Title: Setting `beforeSendSpan` drops the root span's `links` from transactions (loses the `previous_trace` link) · Issue #25545 · getsentry/sentry-javascript · GitHub
Open Graph Title: Setting `beforeSendSpan` drops the root span's `links` from transactions (loses the `previous_trace` link) · Issue #25545 · getsentry/sentry-javascript
X Title: Setting `beforeSendSpan` drops the root span's `links` from transactions (loses the `previous_trace` link) · Issue #25545 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I searched for "beforeSendSpan links" and "previous_trace beforeSendSpan" and found none. How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using? @sentry/nextjs (browser client), 10.76...
Open Graph Description: Is there an existing issue for this? I searched for "beforeSendSpan links" and "previous_trace beforeSendSpan" and found none. How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using...
X Description: Is there an existing issue for this? I searched for "beforeSendSpan links" and "previous_trace beforeSendSpan" and found none. How do you use Sentry? Sentry SaaS (sentry.io) Whi...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/25545
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Setting `beforeSendSpan` drops the root span's `links` from transactions (loses the `previous_trace` link)","articleBody":"### Is there an existing issue for this?\n\nI searched for \"beforeSendSpan links\" and \"previous_trace beforeSendSpan\" and found none.\n\n### How do you use Sentry?\n\nSentry SaaS (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nextjs (browser client), 10.76.2. The same code is in @sentry/core 11.8.0.\n\n### SDK Version\n\n10.76.2\n\n### Framework Version\n\nNext.js 16.4\n\n### Steps to Reproduce\n\n1. Initialize the browser SDK with tracing and the default `browserTracingIntegration` (`linkPreviousTrace: 'in-memory'`), and any `beforeSendSpan`, even an identity function:\n\n ```js\n Sentry.init({\n dsn,\n tracesSampleRate: 1.0,\n beforeSendSpan: (span) => span,\n });\n ```\n2. Load a page, then trigger a second page-load or navigation transaction.\n3. Look at the second transaction's `contexts.trace.links`.\n\n### Expected Result\n\n`contexts.trace.links` holds the `previous_trace` link, as it does without `beforeSendSpan`. In general, a `beforeSendSpan` that returns the span unchanged leaves the transaction unchanged.\n\n### Actual Result\n\n`contexts.trace.links` is missing. The `sentry.previous_trace` attribute survives in `contexts.trace.data`, but the trace view no longer links to the previous trace.\n\nWe see this in our own data. A navigation transaction that followed a page load in the same tab carries the `sentry.previous_trace` attribute, but its stored span has `links: null`.\n\nWhat we traced in `@sentry/core` 10.76.2 (`build/esm`):\n\n- **`client.js`, in `processBeforeSend`:** when `beforeSendSpan` is set, the root span goes through `beforeSendSpan(convertTransactionEventToSpanJson(event))`, and the result is merged back with `merge(event, convertSpanJsonToTransactionEvent(result))`.\n- **`utils/transactionEvent.js`:** `convertTransactionEventToSpanJson` doesn't copy `contexts.trace.links`, and `convertSpanJsonToTransactionEvent` doesn't write them back.\n- **`utils/merge.js`:** with its default depth of 2, `merge` replaces `contexts.trace` whole. The links set by `spanToTransactionTraceContext` (`utils/spanUtils.js`) are lost.\n\nCarrying `links` through both conversions would fix it. The other `SpanJSON` fields the round trip doesn't carry may be worth checking too.\n\n### Why it matters\n\n`beforeSendSpan` is the only hook that sees standalone spans, such as INP, so apps that scrub data from every span have to set it. Setting it currently costs the previous-trace link on every transaction, app-wide.\n","author":{"url":"https://github.com/arobison","@type":"Person","name":"arobison"},"datePublished":"2026-10-19T23:18:46Z","url":"https://github.com/getsentry/sentry-javascript/issues/25545"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9142fd25-6720-52b1-373b-4983a6dbad21 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8BBA:347215:126948:192CF0:6B0446B1 |
| html-safe-nonce | 9b62a6f7b141b644b2a715c593117e9b1c516a1f6adf3e22338cc741762d602b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkJBOjM0NzIxNToxMjY5NDg6MTkyQ0YwOjZCMDQ0NkIxIiwidmlzaXRvcl9pZCI6IjE3MjMwMDIxNTc4MDE5NDg4NDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 16338417102e05d7012f4d4f8965445126f2c6164fd1a465c522f10461c4ca8f |
| hovercard-subject-tag | issue:5933098944 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/25545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/67d0e0dbe34433cd263bb32c6cc04b4a0a15be313dab26c2b7de140f049db6eb/getsentry/sentry-javascript/issues/25545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/67d0e0dbe34433cd263bb32c6cc04b4a0a15be313dab26c2b7de140f049db6eb/getsentry/sentry-javascript/issues/25545 |
| og:image:alt | Is there an existing issue for this? I searched for "beforeSendSpan links" and "previous_trace beforeSendSpan" and found none. How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | arobison |
| hostname | github.com |
| expected-hostname | github.com |
| None | d4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width