Title: Add global `Sentry.getDynamicSamplingContext` function · Issue #10119 · getsentry/sentry-javascript · GitHub
Open Graph Title: Add global `Sentry.getDynamicSamplingContext` function · Issue #10119 · getsentry/sentry-javascript
X Title: Add global `Sentry.getDynamicSamplingContext` function · Issue #10119 · getsentry/sentry-javascript
Description: Problem Statement Our current state of obtaining the correct DSC is messy and it's easy to get the logic, when to use the DSC from a span vs. from client data vs. the one on the propagation context wrong. With #10094 we started moving aw...
Open Graph Description: Problem Statement Our current state of obtaining the correct DSC is messy and it's easy to get the logic, when to use the DSC from a span vs. from client data vs. the one on the propagation context...
X Description: Problem Statement Our current state of obtaining the correct DSC is messy and it's easy to get the logic, when to use the DSC from a span vs. from client data vs. the one on the propagation con...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/10119
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add global `Sentry.getDynamicSamplingContext` function","articleBody":"### Problem Statement\r\n\r\nOur current state of obtaining the correct DSC is messy and it's easy to get the logic, when to use the DSC from a span vs. from client data vs. the one on the propagation context wrong. \r\n\r\nWith #10094 we started moving away from creating a DSC from the transaction but this can only be temporary because the frozen DSC is still on the txn. \r\n\r\n### But what about `Scope.getPropagationContext`?\r\n\r\nAfter discussing this extensively, our previous solution to consolidate DSC whenever `scope.getPropagationContext` is called (as described in #10095) has one fundamental flaw: In Otel/Node, the \"active span\" is not always the span that's on the current scope from which `scope.getPropagationContext` would be called. Now, we could, theoretically, just call `getActiveSpan()` within `scope.getPropagationContext` but arguably, this destroys the semantics and doesn't make much sense in Node. \r\n\r\n\r\n### Solution Brainstorm\r\n\r\nThe solution is to decouple DynamicSamplingContext and PropagationContext. To obtain all the necessary tracing data, we'll need to call:\r\n\r\n* `getCurrentScope().getPropagationContext()` for traceparent data\r\n* `getDynamicSamplingContext()` for DSC\r\n\r\nWhile it's not one unified call, it's still way easier than conditionally selecting DSC from wherever and it'll allow us to preserve semantics better. \r\n\r\nThis also has the implication, that we'll remove the `dsc` field from `PropagationContext` as it'll no longer be necessary.\r\n\r\n### Pseudo Code Implementation\r\n\r\ncredits @mydea \r\n\r\n```js\r\n// called from start(inactive)?Span(Manual)?\r\nfunction afterStartSpan(ctx: TransactionContext): void {\r\n if (ctx.metadata?.dynamicSamplingContext) {\r\n const scope = getCurrentScope();\r\n if (!scope.getFrozenDsc()) {\r\n scope.setFrozenDsc(ctx.metadata.dynamicSamplingContext);\r\n }\r\n }\r\n}\r\n\r\nfunction getDynamicSamplingContext(): DynamicSamplingContext {\r\n const scope = getCurrentScope();\r\n if (scope.getFrozenDsc()) {\r\n return scope.getFrozenDsc();\r\n }\r\n\r\n if (getActiveSpan()) {\r\n // set the frozen one if we want to re-introduce freezing:\r\n // getCurrentScope().setFrozenDsc(...);\r\n return getDscFromSpan();\r\n }\r\n\r\n return getDscFromClient(scope.getPropagationContext().traceId, getClient(), scope);\r\n} \r\n```","author":{"url":"https://github.com/Lms24","@type":"Person","name":"Lms24"},"datePublished":"2024-01-09T13:49:22Z","url":"https://github.com/getsentry/sentry-javascript/issues/10119"}
| 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:2a4b0aff-fe19-34a6-8a77-df1cf1948ba6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB26:21F6E2:68D196:938A74:6B044C60 |
| html-safe-nonce | cae561bce341892df1b001387cdcce0597f9deebe79c48de283e713ab981787c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjI2OjIxRjZFMjo2OEQxOTY6OTM4QTc0OjZCMDQ0QzYwIiwidmlzaXRvcl9pZCI6IjQ2NDE5NDE4MDU2NzAzNTQwMTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fe5107d924c313277ca75e2a5f40ffba1c581d4457f384c8d5435bd0bdc51256 |
| hovercard-subject-tag | issue:2072406836 |
| 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/10119/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8ee02a464358931dfeaf18393d4ce2995483a0be8170ebb60da4f1081045f3e/getsentry/sentry-javascript/issues/10119 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8ee02a464358931dfeaf18393d4ce2995483a0be8170ebb60da4f1081045f3e/getsentry/sentry-javascript/issues/10119 |
| og:image:alt | Problem Statement Our current state of obtaining the correct DSC is messy and it's easy to get the logic, when to use the DSC from a span vs. from client data vs. the one on the propagation context... |
| 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 | 002aa6b95ffa730b0aec436a5c383f536ad677284e60056037fb120afe37b730 |
| 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 | 059f24c781e3a0d7df3f27a97da0e93fab06ae39 |
| 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