Title: Add option to sample linked traces consistently · Issue #15754 · getsentry/sentry-javascript · GitHub
Open Graph Title: Add option to sample linked traces consistently · Issue #15754 · getsentry/sentry-javascript
X Title: Add option to sample linked traces consistently · Issue #15754 · getsentry/sentry-javascript
Description: We should provide a way for users to sample consistently positively or negatively based on the previous/initial trace (i.e. the one we link since #14992). Concretely, we propose to add an option to browserTracingIntegration: Sentry.init(...
Open Graph Description: We should provide a way for users to sample consistently positively or negatively based on the previous/initial trace (i.e. the one we link since #14992). Concretely, we propose to add an option to...
X Description: We should provide a way for users to sample consistently positively or negatively based on the previous/initial trace (i.e. the one we link since #14992). Concretely, we propose to add an option to...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/15754
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add option to sample linked traces consistently","articleBody":"We should provide a way for users to sample consistently positively or negatively based on the previous/initial trace (i.e. the one we link since #14992). Concretely, we propose to add an option to `browserTracingIntegration`:\n\n```js\nSentry.init({\n integrations: [\n browserTracingIntegration({\n linkPreviousTrace: 'in-memory', // other values 'session-storage' | 'off'\n sampleLikePreviousTrace: true, // does nothing if linkPreviousTrace === 'off'\n })\n ]\n})\n```\n\nThis option is opt-in, meaning by default, the SDK continues to sample independently between traces. \n\nSpecifically, if `sampleLikePreviousTrace` is `true`\n- force a positive sampling decision if previous trace was sampled positively\n - ensure that sample rand and rate from initial trace is applied and propagated in new trace\n- force negative sampling decision if previous trace was sampled negatively\n- fall back to user-defined sampling mechanism (`tracesSampleRate` or `tracesSampler`) if no previous trace available (e.g. because first trace in chain or `linkPreviousTrace === 'off'`)\n- injected meta tags on pageload have precedence over previous trace sampling decision (if session-storage is opted into)\n\nOtherwise, fall back to fall back to user-defined sampling mechanism (`tracesSampleRate` or `tracesSampler`) => independent sampling.\n\nAs for implementation: We probably can reuse the `beforeSampling` client hook to keep the logic in `browserTracingIntegration`. But we need to make sure that the hook emits in `sampleSpan` (or prior to calling it) within the Core SDK. Also we need to update or set the propagation context accordingly.\n\nIn other words, the only way how consistent sampling across traces can work is by pretending it is continuing a sampling decision within a distributed trace. Which is a fundamental limitation of the tracing and metrics model we're building at Sentry. This really shows that `tracesSampler` still permits a lot of possibilities for users to influence extrapolation in unexpected ways.\n\n### Naming\n\nNaming is hard and I don't have a great name yet for this option. Some suggestions:\n\n- `sampleLikePreviousTrace` \n- `sampleLinkedTraces(Consistently|Uniformly)`\n- `forwardSamplingToLinkedTraces`\n- `forwardSamplingToNextTrace`\n- `sampleTracesConsistently` \n- `consistentTraceSampling` \u003c-- this is what we went with in #16037 \n\n---\n\nThe initial proposal was reworked b/c it would have significantly skewed span metric extrapolation. I'm leaving this here for some context as to what we could have had. \n\n### Initial Proposal (for context)\n\n#### Description\n\nWe should provide a way for users to make a sampling decision for a trace based on the sampling decision of the previous trace (i.e. the one we link since #14992). Concretely, we propose to add an option to `tracesSampler`:\n\n```js\nSentry.init({\n dsn: '...',\n tracesSampler(({previousTraceSampled}) => {\n if (previousTraceSampled) {\n return 1.0; // could also just increase the rate, e.g. to 0.5\n } else if (previousTraceSampled === false) {\n return 0;\n }\n return 0.05;\n })\n})\n```\n\nwhere `previousTraceSampled` is typed as `boolean | undefined`. The semantics for all values:\n\n- `true` - previous trace was positively sampled and sent to Sentry (this makes no guarantees that this trace in fact was stored; it can still be dropped by Relay)\n- `false` - previous trace was negatively sampled and not Sent to Sentry\n- `undefined` - multiple implications\n - the current trace is the first one\n - previous trace collection is disabled by users\n - previous trace collection is not available (e.g. server SDK) \n\nThis allows users to ensure that a trace chain is longer or in general more complete. \n\nImportant notes:\n- By default the SDK will not continue a positive sampling decision based on the previous trace. This must be a concious user decision to opt into. \n- The potential quota increase must be mentioned in JSDoc and docs","author":{"url":"https://github.com/Lms24","@type":"Person","name":"Lms24"},"datePublished":"2025-03-20T12:02:53Z","url":"https://github.com/getsentry/sentry-javascript/issues/15754"}
| 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:456a40fd-90cf-f02c-aa2b-28716716aeae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD70:18D8CC:1F4A2AF:28B11BC:6B040A63 |
| html-safe-nonce | 07340bb1067b196f1949f639b50674416614f1851be9ab82a3d1b23da35c0d10 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDcwOjE4RDhDQzoxRjRBMkFGOjI4QjExQkM6NkIwNDBBNjMiLCJ2aXNpdG9yX2lkIjoiNzU3MjUxODMyMzgyOTg2OTE1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0e14730129877c0e05f59a5e28a2599232520d47cc223828a755cb481689c3af |
| hovercard-subject-tag | issue:2935229383 |
| 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/15754/issue_layout |
| twitter:image | https://opengraph.githubassets.com/743e5a22d8256ea01c8a2019046263f9f6e2851a8651506eebf929281a00d8e8/getsentry/sentry-javascript/issues/15754 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/743e5a22d8256ea01c8a2019046263f9f6e2851a8651506eebf929281a00d8e8/getsentry/sentry-javascript/issues/15754 |
| og:image:alt | We should provide a way for users to sample consistently positively or negatively based on the previous/initial trace (i.e. the one we link since #14992). Concretely, we propose to add an option to... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Lms24 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| 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