Skip to content

fix(core): preserve span links through beforeSendSpan - #25566

Merged
nicohrubec merged 4 commits into
getsentry:developfrom
chiliec:fix/beforesendspan-drops-span-links
Nov 3, 2026
Merged

nicohrubec merged 4 commits into
getsentry:developfrom
chiliec:fix/beforesendspan-drops-span-links

Conversation

@chiliec

@chiliec chiliec commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25545

Problem

Setting beforeSendSpan — even an identity callback (span) => span — drops the root span's contexts.trace.links from every transaction, so the previous_trace link is lost and the trace view no longer links to the previous trace.

In processBeforeSend, the root span goes through beforeSendSpan(convertTransactionEventToSpanJson(event)) and the result is merged back with merge(event, convertSpanJsonToTransactionEvent(result)). The two converters in packages/core/src/utils/transactionEvent.ts never copied links, and merge (default depth 2) replaces contexts.trace whole, so the links set by spanToTransactionTraceContext are discarded. Thanks to @arobison for the detailed root-cause trace in the issue.

Fix

Carry links through both conversions. TraceContext.links and SpanJSON.links are both SpanLinkJSON[], so this is a direct pass-through.

Tests

Extended the existing transactionEvent.test.ts round-trip cases (convertTransactionEventToSpanJson and convertSpanJsonToTransactionEvent) to assert links (including a previous_trace link) survive.

@github-actions github-actions Bot added the external PR from an external contributor label Oct 20, 2026

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

Stale Bugbot comment from a previous run.

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks! Just a minor change, we need to assert the result. Happy to approve once that's done.

[SENTRY_EXCLUSIVE_TIME]: 123.45,
other: 'value',
},
links: [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These assertions cover the converters, but the links actually got lost in the merge(event, ...) step in processBeforeSend.

Could you also assert contexts.trace.links on the sent transaction in client.test.ts?

@chiliec

chiliec commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Added the assertion on the sent transaction in client.test.ts: it sends a transaction through an identity beforeSendSpan and checks contexts.trace.links survives on the captured event. Reverting the converter fix makes it fail. Thanks for the review.

The transaction-event/span-JSON round trip in processBeforeSend did not
carry contexts.trace.links, so setting beforeSendSpan (even an identity
callback) dropped the root span's links, including the previous_trace
link, from every transaction.

Carry links through convertTransactionEventToSpanJson and
convertSpanJsonToTransactionEvent.

Fixes getsentry#25545
@logaretm
logaretm force-pushed the fix/beforesendspan-drops-span-links branch from b54dd70 to 2ef36f4 Compare November 2, 2026 20:55
@logaretm
logaretm requested review from a team as code owners November 2, 2026 20:55
@logaretm
logaretm requested review from andreiborza, isaacs, logaretm, msonnb, nicohrubec and s1gr1d and removed request for a team November 2, 2026 20:55

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2ef36f4. Configure here.

Comment thread packages/core/test/lib/client.test.ts Resolved
@nicohrubec
nicohrubec merged commit b61bd60 into getsentry:develop Nov 3, 2026
344 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting beforeSendSpan drops the root span's links from transactions (loses the previous_trace link)

3 participants