Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CloudEvents Traceparent Extension #452

Closed
grant opened this issue Dec 11, 2021 · 4 comments
Closed

Support CloudEvents Traceparent Extension #452

grant opened this issue Dec 11, 2021 · 4 comments

Comments

@grant
Copy link
Member

grant commented Dec 11, 2021

Describe the Bug

Some HTTP requests may follow the CE traceparent extension. Currently, the default way of parsing this extension does not work as expected.

Concretely, this extension / attributes (traceparent, tracestate):

https://github.com/cloudevents/spec/blob/v1.0/extensions/distributed-tracing.md

  • There should be a way to access CloudEvent extensions after converting a HTTP request to a CloudEvent.
  • There should be a sample showing how to receive CloudEvents with documented extensions.

Steps to Reproduce

index.js

const app = require("express")();
const { HTTP } = require("cloudevents");

app.post("/", (req, res) => {
  // body and headers come from an incoming HTTP request, e.g. express.js
  const receivedEvent = HTTP.toEvent({ headers: req.headers, body: req.body });
  console.log(receivedEvent);
  res.send('ok');
});

app.listen(8080);

package.json

{
  "main": "index.js",
  "scripts": {
    "start": "node ."
  },
  "dependencies": {
    "cloudevents": "^5.2.0",
    "express": "^4.17.1"
  }
}

Send HTTP request:

curl localhost:8080 -XPOST \
-H "Ce-Id: abc-123" \
-H "Ce-Source: cloudevents.conformance.tool" \
-H "Ce-Specversion: 1.0" \
-H "Ce-Type: foo.bar" \
-H "traceparent: 123"

Observe no traceparent field:

{"id":"abc-123","time":"2021-12-10T17:34:55.358Z","type":"foo.bar","source":"cloudevents.conformance.tool","specversion":"1.0"}

Note: The traceparent header does not need to have a ce- prefix.

Expected Behavior

  • HTTP.toEvent should parse this documented extension attribute and populate the attribute in the CloudEvent object.
  • There is a sample for receiving the traceparent extension

Actual Behavior

  • There is no sample for receiving the traceparent extension
  • HTTP.toEvent doesn't seem to parse this extension
@lance
Copy link
Member

lance commented Dec 14, 2021

Hey @grant - so to be quite honest, this extension has been a bit confusing to me, and I have had different expectations. To try and clarify, I posted in the #cloudevents slack about it. https://cloud-native.slack.com/archives/C9DB5ABAA/p1639507801025900

My expectation is that all extension attributes are encoded in the same way as other attributes. That is, they appear in the incoming HTTP request headers prefixed with ce-. So in your case, the header should be ce-traceparent. If you try your example with that header, you should see the extension in the CloudEvent object.

Let's see if we get any response from others on that Slack query.

@lance
Copy link
Member

lance commented Dec 15, 2021

@grant I am pretty sure that the SDK is doing the right thing based on discussion in the Slack link above. There is also an open PR to the Distributed Tracing Extension that we should be aware of cloudevents/spec#912.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@lance
Copy link
Member

lance commented Oct 11, 2022

Closing as obsolete

@lance lance closed this as completed Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants