Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): Defer TwP sampling by reading trace state from the scope#21549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ba712f0d1d9d2d6a7c65451b7626e550e1f14cf7738b31869b65741e7965770File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import * as Sentry from '@sentry/cloudflare'; | ||
| interface Env { | ||
| SENTRY_DSN: string; | ||
| } | ||
| // Tracing is enabled (not TwP), but the route is a raw, non-parametrized URL so the | ||
| // http.server span source is `url`. The span name must therefore be omitted from the | ||
| // DSC (raw URLs may contain PII), even though a real transaction is recorded. | ||
| export default Sentry.withSentry( | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m: This test is also passing on the latest MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above | ||
| (env: Env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| tracesSampleRate: 1.0, | ||
| }), | ||
| { | ||
| async fetch(_request, _env, _ctx) { | ||
| throw new Error('Test error from URL-source worker'); | ||
| }, | ||
| }, | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { expect, it } from 'vitest'; | ||
| import { eventEnvelope } from '../../../expect'; | ||
| import { createRunner } from '../../../runner'; | ||
| it('omits the span name from the DSC for url-source spans when tracing is enabled', async ({ signal }) => { | ||
| const runner = createRunner(__dirname) | ||
| // Error event: because tracing is enabled, the DSC carries the sampling fields. But the span | ||
| // source is `url`, so the span name is omitted from the DSC (raw URLs may contain PII). | ||
| .expect( | ||
| eventEnvelope( | ||
| { | ||
| level: 'error', | ||
| exception: { | ||
| values: [ | ||
| { | ||
| type: 'Error', | ||
| value: 'Test error from URL-source worker', | ||
| stacktrace: { | ||
| frames: expect.any(Array), | ||
| }, | ||
| mechanism: { type: 'auto.http.cloudflare', handled: false }, | ||
| }, | ||
| ], | ||
| }, | ||
| request: { | ||
| headers: expect.any(Object), | ||
| method: 'GET', | ||
| url: expect.any(String), | ||
| }, | ||
| }, | ||
| { includeSamplingFields: true, includeSampleRand: true, includeTransaction: false }, | ||
| ), | ||
| ) | ||
| // Transaction event: proves we are NOT in TwP — the span is recorded with a `url` source and | ||
| // carries the name on the event itself, even though it is intentionally absent from the DSC. | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1]; | ||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| type: 'transaction', | ||
| transaction: 'GET /error', | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'http.server', | ||
| data: expect.objectContaining({ 'sentry.source': 'url' }), | ||
| }), | ||
| }), | ||
| }), | ||
| ); | ||
| }) | ||
| .unordered() | ||
| .start(signal); | ||
| await runner.makeRequest('get', '/error', { expectError: true }); | ||
| await runner.completed(); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "worker-name", | ||
| "compatibility_date": "2025-06-17", | ||
| "main": "index.ts", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Was this issue specifically related to Cloudflare? Just wondering why there is specifically a CF test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not CF specific but it tests a core behavior of
getDynamicSamplingContextFromSpanthat we didn't test before.I wanted to make sure that a in a non TwP case the transaction is also scrubbed when the source is url.