ref: Replace forceTransaction with continueTrace at internal call sites - #23761
andreiborza wants to merge 2 commits into
Conversation
… sites Adds `withSegment`, which reads the trace data of the active span through `getTraceData()` and feeds it back in through `continueTrace()`. A span started inside continues the same trace but has no parent span, so it becomes the segment (root span) of that trace. That is what `forceTransaction: true` does. Applies it to the three sites that need the flag: the MCP server request and notification spans, the Next.js server action span, and the nestjs event span. Experiment. Opened to see whether the composed form behaves the same in CI. Co-Authored-By: Opus 5 <noreply@anthropic.com>
size-limit report 📦
|
continueTrace applies the trace continuation policy. With strictTraceContinuation and a frozen DSC that carries no org id, shouldContinueTrace rejects the self-generated baggage and startNewTrace moves the segment onto a new trace, which detaches it from the request it belongs to. withSegment now writes the propagation context from the active span, the way registerPrepareSpanScope does for a remote parent. Adds tests for the segment topology, for equivalence with forceTransaction, and for the strict continuation case.
|
Won't do, maybe in v12. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4d8bd97. Configure here.
| scope.setPropagationContext({ | ||
| traceId, | ||
| parentSpanId: spanId, | ||
| sampled: spanIsSampled(parentSpan), |
There was a problem hiding this comment.
Segment inherits false sampling decision
Medium Severity
withSegment always writes sampled: spanIsSampled(parentSpan) onto the forked propagation context. spanIsSampled is only true when trace flags are sampled, so a TwP placeholder or any parent with no sampling decision becomes false. That decision then rides on outgoing sentry-trace headers as -0, so downstream services inherit a negative sample and drop the trace. forceTransaction never mutated scope sampled, and registerPrepareSpanScope uses a three-state decision that can stay unset.
Reviewed by Cursor Bugbot for commit 4d8bd97. Configure here.


Stacked on #23756.
What
Adds
withSegment, a wrapper that reads the trace data of the active span throughgetTraceData()and feeds it back in throughcontinueTrace(). A span started inside continues the same trace but has no parent span, so it becomes the segment of that trace. That is whatforceTransaction: truedoes today.Applies it to the three sites that CI proved still need the flag: the MCP server request and notification spans, the Next.js server action span, and the nestjs event span.
Why
Experiment, to see whether the flag can be expressed with the primitives the SDK already exposes instead of a start-span option. The same conversion already exists inside the SDK for remote parents, in
registerPrepareSpanScope, which forks the scope, sets the propagation context from the parent and clears the active span.