Skip to content

Commit ddb6cbb

Browse files
JPeer264claude
andauthored
docs(span-links): Add message_origin link type for queues (#20023)
<!-- Keep the urgency section so automation can prioritize this PR. You may delete other sections you don't need. --> ## DESCRIBE YOUR PR This adds the `message_origin` link type to the span links page. A queue consumer span uses it to link to the producer span that published the message, like `cache_origin` does for cached values. The BullMQ integration of the JavaScript SDK sets it first (getsentry/sentry-javascript#21777), and the conventions added it in getsentry/sentry-conventions#724. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the due date. You can update this information later by editing the PR description. - [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD - [ ] Other deadline: YYYY-MM-DD - [x] No deadline: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've supplied a deadline. Thanks in advance for your help! ## PRE-MERGE CHECKLIST _Make sure you've checked the following before merging your changes:_ - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 24fdeaa commit ddb6cbb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎develop-docs/sdk/telemetry/traces/span-links.mdx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Any string can be used, but these types have predefined meanings:
147147
|--------------------|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
148148
| "previous_trace" | Linking e.g. a navigation span to the previous page load span. | Used to query linked traces. Shows a button to go to linked previous trace in the trace explorer. |
149149
| "cache_origin" | Linking a span that reads a cached value to the trace that produced that value (e.g. server-side rendering). | Used to navigate from a cache-hit span to the origin trace. |
150+
| "message_origin" | Linking a span that processes a queue message to the span that published the message (e.g. a queue job). | Used to navigate from a consumer span to the producer trace. |
150151

151152
### `previous_trace`
152153

@@ -209,6 +210,35 @@ The origin trace may be negatively sampled. The link is still added, with `sampl
209210

210211
A background revalidation (for example, stale-while-revalidate) starts its own trace rather than continuing the serving trace, and becomes the origin for future cache hits.
211212

213+
### `message_origin`
214+
215+
When a consumer processes a message, the work often runs long after the producer published it, in another process, and with a different sampling decision.
216+
A parent/child relationship does not fit well: a delayed or retried job keeps the producer trace open for a long time, one publish span can fan out to many consumers, and a batch can contain messages from unrelated traces, so it has no single correct parent.
217+
If the consumer starts its own trace, then without a link, the consumer trace has no way to find the code that published the message.
218+
219+
The [Queues module](/sdk/telemetry/traces/modules/queues/#distributed-tracing) continues the producer trace in the consumer where it can.
220+
For the cases above, start a new trace in the consumer and add a `message_origin` link instead.
221+
If the consumer continues the producer trace, do not add the link, because it would point into the same trace.
222+
223+
A `message_origin` link connects the span that processes a message (for example, a `queue.process` span) to the span that published it (for example, a `queue.publish` span). "Origin" here means the producer span, not the consumer.
224+
225+
Add the link to the span that processes the message:
226+
227+
```ts
228+
span.addLink({
229+
context: producerSpanContext, // propagated with the message
230+
attributes: {
231+
'sentry.link.type': 'message_origin'
232+
}
233+
})
234+
```
235+
236+
- On publish, store the context of the publish span (for example, the `queue.publish` span: `trace_id`, `span_id`, sampling decision) with the message, for example in message metadata or headers.
237+
- On process, read the stored context and add the link. A span that processes a batch adds one link for each distinct producer span in the batch.
238+
- If the message has no stored context, emit the consumer span **without** a link.
239+
240+
The producer trace may be negatively sampled. The link is still added, with `sampled: false` from the stored span context (same behavior as `previous_trace`).
241+
212242
## Usage Example
213243

214244
Adding span links should be possible at span start time, as well as when holding a reference to the span.

0 commit comments

Comments
 (0)