sdk-javascript
sdk-javascript copied to clipboard
Support CloudEvents Traceparent Extension
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.toEventshould parse this documented extension attribute and populate the attribute in the CloudEvent object.- There is a sample for receiving the
traceparentextension
Actual Behavior
- There is no sample for receiving the
traceparentextension HTTP.toEventdoesn't seem to parse this extension
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.
@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 https://github.com/cloudevents/spec/pull/912.
This issue is stale because it has been open 30 days with no activity.
Closing as obsolete