Skip to content

feat: Propagate and use a sampling random #14989

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

Merged
merged 21 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Sentry.getCurrentScope().setPropagationContext({
parentSpanId: '1234567890123456',
traceId: '12345678901234567890123456789012',
sampleRand: Math.random(),
});

Sentry.startSpan({ name: 'test_span_1' }, () => undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sentryTest(
sampled: 'true',
trace_id: traceId,
transaction: 'outer',
sample_rand: expect.any(String),
},
});

Expand All @@ -64,6 +65,7 @@ sentryTest(
sampled: 'true',
trace_id: traceId,
transaction: 'outer',
sample_rand: expect.any(String),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sentryTest('sends a segment span envelope', async ({ getLocalTestUrl, page }) =>
sampled: 'true',
trace_id: traceId,
transaction: 'standalone_segment_span',
sample_rand: expect.any(String),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sentryTest(
public_key: 'public',
replay_id: replay.session?.id,
sampled: 'true',
sample_rand: expect.any(String),
});
},
);
Expand Down Expand Up @@ -108,6 +109,7 @@ sentryTest(
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
public_key: 'public',
sampled: 'true',
sample_rand: expect.any(String),
});
},
);
Expand Down Expand Up @@ -161,6 +163,7 @@ sentryTest(
public_key: 'public',
replay_id: replay.session?.id,
sampled: 'true',
sample_rand: expect.any(String),
});
},
);
Expand Down Expand Up @@ -202,6 +205,7 @@ sentryTest(
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
public_key: 'public',
sampled: 'true',
sample_rand: expect.any(String),
});
},
);
Expand Down Expand Up @@ -247,6 +251,7 @@ sentryTest('should add replay_id to error DSC while replay is active', async ({
? {
sample_rate: '1',
sampled: 'true',
sample_rand: expect.any(String),
}
: {}),
});
Expand All @@ -267,6 +272,7 @@ sentryTest('should add replay_id to error DSC while replay is active', async ({
? {
sample_rate: '1',
sampled: 'true',
sample_rand: expect.any(String),
}
: {}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-1" />
<meta
name="baggage"
content="sentry-release=2.1.12,sentry-public_key=public,sentry-trace_id=123,sentry-sample_rate=0.3232"
content="sentry-release=2.1.12,sentry-public_key=public,sentry-trace_id=123,sentry-sample_rate=0.3232,sentry-sample_rand=0.42"
/>
</head>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sentryTest(
sample_rate: '0.3232',
trace_id: '123',
public_key: 'public',
sample_rand: '0.42',
});
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
'sentry-environment=production',
'sentry-public_key=public',
'sentry-release=1.1.1',
expect.stringMatching(/sentry-sample_rand=0\.[0-9]+/),
'sentry-sample_rate=1',
'sentry-sampled=true',
`sentry-trace_id=${traceId}`,
Expand All @@ -62,6 +63,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
sample_rate: '1',
sampled: 'true',
trace_id: traceId,
sample_rand: expect.any(String),
});

// 4
Expand All @@ -73,6 +75,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
'sentry-environment=production',
'sentry-public_key=public',
'sentry-release=1.1.1',
expect.stringMatching(/sentry-sample_rand=0\.[0-9]+/),
'sentry-sample_rate=1',
'sentry-sampled=true',
`sentry-trace_id=${traceId}`,
Expand All @@ -89,6 +92,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
sampled: 'true',
trace_id: traceId,
transaction: 'updated-root-span-1',
sample_rand: expect.any(String),
});

// 7
Expand All @@ -100,6 +104,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
'sentry-environment=production',
'sentry-public_key=public',
'sentry-release=1.1.1',
expect.stringMatching(/sentry-sample_rand=0\.[0-9]+/),
'sentry-sample_rate=1',
'sentry-sampled=true',
`sentry-trace_id=${traceId}`,
Expand All @@ -116,6 +121,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
sampled: 'true',
trace_id: traceId,
transaction: 'updated-root-span-2',
sample_rand: expect.any(String),
});

// 10
Expand All @@ -137,6 +143,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
sampled: 'true',
trace_id: traceId,
transaction: 'updated-root-span-2',
sample_rand: expect.any(String),
});

expect(txnEvent.transaction).toEqual('updated-root-span-2');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sentryTest(
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
public_key: 'public',
sampled: 'true',
sample_rand: expect.any(String),
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sentryTest(
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
public_key: 'public',
sampled: 'true',
sample_rand: expect.any(String),
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ sentryTest('captures a "GOOD" CLS vital with its source as a standalone span', a
sample_rate: '1',
sampled: 'true',
trace_id: spanEnvelopeItem.trace_id,
sample_rand: expect.any(String),
// no transaction, because span source is URL
},
});
Expand Down Expand Up @@ -167,6 +168,7 @@ sentryTest('captures a "MEH" CLS vital with its source as a standalone span', as
sample_rate: '1',
sampled: 'true',
trace_id: spanEnvelopeItem.trace_id,
sample_rand: expect.any(String),
// no transaction, because span source is URL
},
});
Expand Down Expand Up @@ -232,6 +234,7 @@ sentryTest('captures a "POOR" CLS vital with its source as a standalone span.',
sample_rate: '1',
sampled: 'true',
trace_id: spanEnvelopeItem.trace_id,
sample_rand: expect.any(String),
// no transaction, because span source is URL
},
});
Expand Down Expand Up @@ -294,6 +297,7 @@ sentryTest(
sample_rate: '1',
sampled: 'true',
trace_id: spanEnvelopeItem.trace_id,
sample_rand: expect.any(String),
// no transaction, because span source is URL
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sentryTest('should capture an INP click event span after pageload', async ({ bro
sample_rate: '1',
sampled: 'true',
trace_id: traceId,
sample_rand: expect.any(String),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ sentryTest(
sampled: 'true',
trace_id: traceId,
transaction: 'test-route',
sample_rand: expect.any(String),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ sentryTest(
sampled: 'true',
trace_id: traceId,
transaction: 'test-route',
sample_rand: expect.any(String),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sentryTest('should capture an INP click event span during pageload', async ({ br
sample_rate: '1',
sampled: 'true',
trace_id: traceId,
sample_rand: expect.any(String),
// no transaction, because span source is URL
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
shouldSkipTracingTest,
} from '../../../../utils/helpers';

sentryTest('creates a new trace on each navigation', async ({ getLocalTestUrl, page }) => {
sentryTest('creates a new trace and sample_rand on each navigation', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
Expand Down Expand Up @@ -49,6 +49,7 @@ sentryTest('creates a new trace on each navigation', async ({ getLocalTestUrl, p
sample_rate: '1',
sampled: 'true',
trace_id: navigation1TraceContext?.trace_id,
sample_rand: expect.any(String),
});

expect(navigation2TraceContext).toMatchObject({
Expand All @@ -64,9 +65,11 @@ sentryTest('creates a new trace on each navigation', async ({ getLocalTestUrl, p
sample_rate: '1',
sampled: 'true',
trace_id: navigation2TraceContext?.trace_id,
sample_rand: expect.any(String),
});

expect(navigation1TraceContext?.trace_id).not.toEqual(navigation2TraceContext?.trace_id);
expect(navigation1TraceHeader?.sample_rand).not.toEqual(navigation2TraceHeader?.sample_rand);
});

sentryTest('error after navigation has navigation traceId', async ({ getLocalTestUrl, page }) => {
Expand Down Expand Up @@ -101,6 +104,7 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
sample_rate: '1',
sampled: 'true',
trace_id: navigationTraceContext?.trace_id,
sample_rand: expect.any(String),
});

const errorEventPromise = getFirstSentryEnvelopeRequest<EventAndTraceHeader>(
Expand All @@ -124,6 +128,7 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
sample_rate: '1',
sampled: 'true',
trace_id: navigationTraceContext?.trace_id,
sample_rand: expect.any(String),
});
});

Expand Down Expand Up @@ -168,6 +173,7 @@ sentryTest('error during navigation has new navigation traceId', async ({ getLoc
sample_rate: '1',
sampled: 'true',
trace_id: navigationTraceContext?.trace_id,
sample_rand: expect.any(String),
});

const errorTraceContext = errorEvent?.contexts?.trace;
Expand All @@ -182,6 +188,7 @@ sentryTest('error during navigation has new navigation traceId', async ({ getLoc
sample_rate: '1',
sampled: 'true',
trace_id: navigationTraceContext?.trace_id,
sample_rand: expect.any(String),
});
});

Expand Down Expand Up @@ -234,6 +241,7 @@ sentryTest(
sample_rate: '1',
sampled: 'true',
trace_id: navigationTraceContext?.trace_id,
sample_rand: expect.any(String),
});

const headers = request.headers();
Expand All @@ -242,7 +250,7 @@ sentryTest(
const navigationTraceId = navigationTraceContext?.trace_id;
expect(headers['sentry-trace']).toMatch(new RegExp(`^${navigationTraceId}-[0-9a-f]{16}-1$`));
expect(headers['baggage']).toEqual(
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true`,
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true,sentry-sample_rand=${navigationTraceHeader?.sample_rand}`,
);
},
);
Expand Down Expand Up @@ -296,6 +304,7 @@ sentryTest(
sample_rate: '1',
sampled: 'true',
trace_id: navigationTraceContext?.trace_id,
sample_rand: expect.any(String),
});

const headers = request.headers();
Expand All @@ -304,7 +313,7 @@ sentryTest(
const navigationTraceId = navigationTraceContext?.trace_id;
expect(headers['sentry-trace']).toMatch(new RegExp(`^${navigationTraceId}-[0-9a-f]{16}-1$`));
expect(headers['baggage']).toEqual(
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true`,
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true,sentry-sample_rand=${navigationTraceHeader?.sample_rand}`,
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="sentry-trace" content="12345678901234567890123456789012-1234567890123456-1" />
<meta name="baggage"
content="sentry-trace_id=12345678901234567890123456789012,sentry-sample_rate=0.2,sentry-sampled=true,sentry-transaction=my-transaction,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod"/>
content="sentry-trace_id=12345678901234567890123456789012,sentry-sample_rate=0.2,sentry-sampled=true,sentry-transaction=my-transaction,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod,sentry-sample_rand=0.42"/>
</head>
<body>
<button id="errorBtn">Throw Error</button>
Expand Down
Loading
Loading