Skip to content

ref: Replace forceTransaction with continueTrace at internal call sites - #23761

Closed
andreiborza wants to merge 2 commits into
ab/investigate-remove-force-transactionfrom
ab/force-transaction-via-continue-trace
Closed

andreiborza wants to merge 2 commits into
ab/investigate-remove-force-transactionfrom
ab/force-transaction-via-continue-trace

Conversation

@andreiborza

Copy link
Copy Markdown
Member

Stacked on #23756.

What

Adds withSegment, a wrapper that 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 of that trace. That is what forceTransaction: true does 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.

… 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>
Comment thread packages/core/src/tracing/trace.ts
Comment thread packages/core/src/tracing/trace.ts
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.56 kB added added
@sentry/browser - with treeshaking flags 26.92 kB added added
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB added added
@sentry/browser (incl. Tracing) 48.75 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48.76 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.68 kB added added
@sentry/browser (incl. Tracing, Replay) 88.23 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.63 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 92.93 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 105.85 kB added added
@sentry/browser (incl. Feedback) 46.05 kB added added
@sentry/browser (incl. sendFeedback) 33.62 kB added added
@sentry/browser (incl. FeedbackAsync) 38.73 kB added added
@sentry/browser (incl. Metrics) 29.51 kB added added
@sentry/browser (incl. Logs) 29.8 kB added added
@sentry/browser (incl. Metrics & Logs) 30.43 kB added added
@sentry/react 30.3 kB added added
@sentry/react (incl. Tracing) 50.94 kB added added
@sentry/vue 35.73 kB added added
@sentry/vue (incl. Tracing) 51.02 kB added added
@sentry/svelte 28.59 kB added added
CDN Bundle 30.35 kB added added
CDN Bundle (incl. Tracing) 49.38 kB added added
CDN Bundle (incl. Logs, Metrics) 32.58 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 51.25 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 73.17 kB added added
CDN Bundle (incl. Tracing, Replay) 86.86 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.73 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 92.8 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.64 kB added added
CDN Bundle - uncompressed 89.95 kB added added
CDN Bundle (incl. Tracing) - uncompressed 147.2 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.89 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.41 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.69 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.37 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.4 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.06 kB added added
@sentry/nextjs (client) 53.51 kB added added
@sentry/sveltekit (client) 49.19 kB added added
@sentry/core/server 65.55 kB added added
@sentry/core/browser 51.93 kB added added
@sentry/node 123.47 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.23 kB added added
@sentry/node - without tracing 87.76 kB added added
@sentry/node - without channel injection 103.13 kB added added
@sentry/aws-serverless 96.07 kB added added
@sentry/cloudflare (withSentry) - minified 200.72 kB added added
@sentry/cloudflare (withSentry) 499.25 kB added added

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.
@andreiborza

Copy link
Copy Markdown
Member Author

Won't do, maybe in v12.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4d8bd97. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant