GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(cloudflare): propagate tracing context through Queue messages by arthurfiorette · Pull Request #22303 · getsentry/sentry-javascript Conversation
|
|
👋 @isaacs, @mydea, @andreiborza — Please review this PR when you get a chance! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
One nit, one minor improvement, and one potentially substantial design choice. Looks good overall, though, and does indeed fix the bug!
Also, since this is a user-facing change (albeit small), we probably want to add a CHANGELOG.md entry like:
- feat(cloudflare): Add `enableQueueTracePropagation` to link Queue producer and consumer traces ([#22303](https://github.com/getsentry/sentry-javascript/pull/22303))
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| traceFlags: producerContext.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE, | ||
| isRemote: true, | ||
| }, | ||
| attributes: { [SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: 'previous_trace' }, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This feels like it might be a weird fit. A previous_trace value here indicates that the link is part of a sequential chain of traces, for example a series of browser interactions that a user might perform. In the UI, it's going to be presented with that kind of sequential semantics.
However, this is more of a "fan out" relationship, not previous/next relationship, so I don't think previous_trace makes the most sense here. It might be better to just leave the type off, and let it be a plain old link.
@andreiborza @mydea Do you think I'm misreading this? What is your opinion on the semantics here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const sentryTrace = body[SENTRY_QUEUE_TRACE_KEY]; | ||
|
|
||
| // Once propagation is enabled this key is reserved transport metadata, even if its value was corrupted in transit. | ||
| delete body.__sentry_queue_trace__; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should use the same const as the rest of the file. Also, delete can throw in strict mode if the object is frozen, so best to try/catch it.
| delete body.__sentry_queue_trace__; | |
| try { | |
| delete body[SENTRY_QUEUE_TRACE_KEY]; | |
| } catch { | |
| // best effort | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return startPublishSpan({ bindingName, bodySize: getBodySize(message) }, span => { | ||
| // Read trace data here so the carrier points to queue.publish, not its parent span. | ||
| const tracedMessage = enableTracePropagation | ||
| ? addQueueTraceContext(message, getTraceData()['sentry-trace']) | ||
| : message; | ||
|
|
||
| if (enableTracePropagation) { | ||
| span.setAttribute('messaging.message.body.size', getBodySize(tracedMessage)); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
So, when trace propagation is enabled, we're calling getBodySize twice, and discarding the original value. It's not a huge cost, but it does incur a JSON.stringify, which can be excessive on large messages.
Consider something like this:
| return startPublishSpan({ bindingName, bodySize: getBodySize(message) }, span => { | |
| // Read trace data here so the carrier points to queue.publish, not its parent span. | |
| const tracedMessage = enableTracePropagation | |
| ? addQueueTraceContext(message, getTraceData()['sentry-trace']) | |
| : message; | |
| if (enableTracePropagation) { | |
| span.setAttribute('messaging.message.body.size', getBodySize(tracedMessage)); | |
| } | |
| return startPublishSpan({ bindingName, bodySize: undefined }, span => { | |
| // Read trace data here so the carrier points to queue.publish, not its parent span. | |
| const tracedMessage = enableTracePropagation | |
| ? addQueueTraceContext(message, getTraceData()['sentry-trace']) | |
| : message; | |
| span.setAttribute('messaging.message.body.size', getBodySize(tracedMessage)); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Cloudflare Queues has no message-header API. Only record-like bodies can carry a named field; binary data and | ||
| // other structured-clone values must pass through untouched. | ||
| const prototype = Object.getPrototypeOf(body); | ||
| return prototype === Object.prototype || prototype === null; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nice. Excludes all "fancy" objects. 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you apply the label |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing due to inactivity after stale warning. Comment or reopen when ready to continue, and use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…25306) This extends #22303, which was auto-closed for inactivity after its review comments slipped through my GitHub inbox. It is now synced with `develop` and addresses that review. --- Adds opt-in trace propagation from Cloudflare Queue producers to consumers. * When a producer binding matches `queueTracePropagationBindings`, plain-object message bodies carry the producer's `sentry-trace` under `__sentry_queue_trace__`. * Arrays, binary payloads and other non-plain values are sent unchanged. * Consumers remove that field before invoking the application handler. * `queue.process` remains a root span and links to every distinct producer in the batch. Span links are used instead of continuing a producer trace because a Queue batch can contain messages from unrelated traces. Picking one producer as the parent would create false causal relationships for the other messages. Propagation is opt-in per binding because Cloudflare Queues has no message-header API. The SDK has to modify the message body, so consumers without Sentry would see the extra field. Changes since #22303: * `enableQueueTracePropagation: boolean` became `queueTracePropagationBindings`, mirroring `rpcTracePropagationBindings` (#23486). Only the producer opts in, since it is the side that changes the payload. Consumers always strip and link, the same way RPC receivers handle `__sentry_rpc_meta__`. * Links no longer set `sentry.link.type: previous_trace`. A batch fans in producers rather than forming a previous/next chain. Fixes #22309 --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Cloudflare Instrumentation for Queues seems broken
There was an error while loading. Please reload this page.