Skip to content

Commit 95cc948

Browse files
authored
feat: Propagate and use a sampling random (#14989)
1 parent 5a46a5c commit 95cc948

File tree

70 files changed

+481
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+481
-151
lines changed

dev-packages/browser-integration-tests/suites/public-api/startSpan/parallel-root-spans-with-parentSpanId/subject.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Sentry.getCurrentScope().setPropagationContext({
22
parentSpanId: '1234567890123456',
33
traceId: '12345678901234567890123456789012',
4+
sampleRand: Math.random(),
45
});
56

67
Sentry.startSpan({ name: 'test_span_1' }, () => undefined);

dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone-mixed-transaction/test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ sentryTest(
4747
sampled: 'true',
4848
trace_id: traceId,
4949
transaction: 'outer',
50+
sample_rand: expect.any(String),
5051
},
5152
});
5253

@@ -64,6 +65,7 @@ sentryTest(
6465
sampled: 'true',
6566
trace_id: traceId,
6667
transaction: 'outer',
68+
sample_rand: expect.any(String),
6769
},
6870
});
6971

dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sentryTest('sends a segment span envelope', async ({ getLocalTestUrl, page }) =>
3333
sampled: 'true',
3434
trace_id: traceId,
3535
transaction: 'standalone_segment_span',
36+
sample_rand: expect.any(String),
3637
},
3738
});
3839

dev-packages/browser-integration-tests/suites/replay/dsc/test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ sentryTest(
6262
public_key: 'public',
6363
replay_id: replay.session?.id,
6464
sampled: 'true',
65+
sample_rand: expect.any(String),
6566
});
6667
},
6768
);
@@ -108,6 +109,7 @@ sentryTest(
108109
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
109110
public_key: 'public',
110111
sampled: 'true',
112+
sample_rand: expect.any(String),
111113
});
112114
},
113115
);
@@ -161,6 +163,7 @@ sentryTest(
161163
public_key: 'public',
162164
replay_id: replay.session?.id,
163165
sampled: 'true',
166+
sample_rand: expect.any(String),
164167
});
165168
},
166169
);
@@ -202,6 +205,7 @@ sentryTest(
202205
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
203206
public_key: 'public',
204207
sampled: 'true',
208+
sample_rand: expect.any(String),
205209
});
206210
},
207211
);
@@ -247,6 +251,7 @@ sentryTest('should add replay_id to error DSC while replay is active', async ({
247251
? {
248252
sample_rate: '1',
249253
sampled: 'true',
254+
sample_rand: expect.any(String),
250255
}
251256
: {}),
252257
});
@@ -267,6 +272,7 @@ sentryTest('should add replay_id to error DSC while replay is active', async ({
267272
? {
268273
sample_rate: '1',
269274
sampled: 'true',
275+
sample_rand: expect.any(String),
270276
}
271277
: {}),
272278
});

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/meta/template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-1" />
66
<meta
77
name="baggage"
8-
content="sentry-release=2.1.12,sentry-public_key=public,sentry-trace_id=123,sentry-sample_rate=0.3232"
8+
content="sentry-release=2.1.12,sentry-public_key=public,sentry-trace_id=123,sentry-sample_rate=0.3232,sentry-sample_rand=0.42"
99
/>
1010
</head>
1111
</html>

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/meta/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sentryTest(
4343
sample_rate: '0.3232',
4444
trace_id: '123',
4545
public_key: 'public',
46+
sample_rand: '0.42',
4647
});
4748
},
4849
);

dev-packages/browser-integration-tests/suites/tracing/dsc-txn-name-update/test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
4848
'sentry-environment=production',
4949
'sentry-public_key=public',
5050
'sentry-release=1.1.1',
51+
expect.stringMatching(/sentry-sample_rand=0\.[0-9]+/),
5152
'sentry-sample_rate=1',
5253
'sentry-sampled=true',
5354
`sentry-trace_id=${traceId}`,
@@ -62,6 +63,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
6263
sample_rate: '1',
6364
sampled: 'true',
6465
trace_id: traceId,
66+
sample_rand: expect.any(String),
6567
});
6668

6769
// 4
@@ -73,6 +75,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
7375
'sentry-environment=production',
7476
'sentry-public_key=public',
7577
'sentry-release=1.1.1',
78+
expect.stringMatching(/sentry-sample_rand=0\.[0-9]+/),
7679
'sentry-sample_rate=1',
7780
'sentry-sampled=true',
7881
`sentry-trace_id=${traceId}`,
@@ -89,6 +92,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
8992
sampled: 'true',
9093
trace_id: traceId,
9194
transaction: 'updated-root-span-1',
95+
sample_rand: expect.any(String),
9296
});
9397

9498
// 7
@@ -100,6 +104,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
100104
'sentry-environment=production',
101105
'sentry-public_key=public',
102106
'sentry-release=1.1.1',
107+
expect.stringMatching(/sentry-sample_rand=0\.[0-9]+/),
103108
'sentry-sample_rate=1',
104109
'sentry-sampled=true',
105110
`sentry-trace_id=${traceId}`,
@@ -116,6 +121,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
116121
sampled: 'true',
117122
trace_id: traceId,
118123
transaction: 'updated-root-span-2',
124+
sample_rand: expect.any(String),
119125
});
120126

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

142149
expect(txnEvent.transaction).toEqual('updated-root-span-2');

dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ sentryTest(
2727
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
2828
public_key: 'public',
2929
sampled: 'true',
30+
sample_rand: expect.any(String),
3031
});
3132
},
3233
);

dev-packages/browser-integration-tests/suites/tracing/envelope-header/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sentryTest(
3030
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
3131
public_key: 'public',
3232
sampled: 'true',
33+
sample_rand: expect.any(String),
3334
});
3435
},
3536
);

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans/test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ sentryTest('captures a "GOOD" CLS vital with its source as a standalone span', a
100100
sample_rate: '1',
101101
sampled: 'true',
102102
trace_id: spanEnvelopeItem.trace_id,
103+
sample_rand: expect.any(String),
103104
// no transaction, because span source is URL
104105
},
105106
});
@@ -167,6 +168,7 @@ sentryTest('captures a "MEH" CLS vital with its source as a standalone span', as
167168
sample_rate: '1',
168169
sampled: 'true',
169170
trace_id: spanEnvelopeItem.trace_id,
171+
sample_rand: expect.any(String),
170172
// no transaction, because span source is URL
171173
},
172174
});
@@ -232,6 +234,7 @@ sentryTest('captures a "POOR" CLS vital with its source as a standalone span.',
232234
sample_rate: '1',
233235
sampled: 'true',
234236
trace_id: spanEnvelopeItem.trace_id,
237+
sample_rand: expect.any(String),
235238
// no transaction, because span source is URL
236239
},
237240
});
@@ -294,6 +297,7 @@ sentryTest(
294297
sample_rate: '1',
295298
sampled: 'true',
296299
trace_id: spanEnvelopeItem.trace_id,
300+
sample_rand: expect.any(String),
297301
// no transaction, because span source is URL
298302
},
299303
});

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-late/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ sentryTest('should capture an INP click event span after pageload', async ({ bro
5555
sample_rate: '1',
5656
sampled: 'true',
5757
trace_id: traceId,
58+
sample_rand: expect.any(String),
5859
},
5960
});
6061

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-parametrized-late/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sentryTest(
5858
sampled: 'true',
5959
trace_id: traceId,
6060
transaction: 'test-route',
61+
sample_rand: expect.any(String),
6162
},
6263
});
6364

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-parametrized/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ sentryTest(
5656
sampled: 'true',
5757
trace_id: traceId,
5858
transaction: 'test-route',
59+
sample_rand: expect.any(String),
5960
},
6061
});
6162

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sentryTest('should capture an INP click event span during pageload', async ({ br
5454
sample_rate: '1',
5555
sampled: 'true',
5656
trace_id: traceId,
57+
sample_rand: expect.any(String),
5758
// no transaction, because span source is URL
5859
},
5960
});

dev-packages/browser-integration-tests/suites/tracing/trace-lifetime/navigation/test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
shouldSkipTracingTest,
1111
} from '../../../../utils/helpers';
1212

13-
sentryTest('creates a new trace on each navigation', async ({ getLocalTestUrl, page }) => {
13+
sentryTest('creates a new trace and sample_rand on each navigation', async ({ getLocalTestUrl, page }) => {
1414
if (shouldSkipTracingTest()) {
1515
sentryTest.skip();
1616
}
@@ -49,6 +49,7 @@ sentryTest('creates a new trace on each navigation', async ({ getLocalTestUrl, p
4949
sample_rate: '1',
5050
sampled: 'true',
5151
trace_id: navigation1TraceContext?.trace_id,
52+
sample_rand: expect.any(String),
5253
});
5354

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

6971
expect(navigation1TraceContext?.trace_id).not.toEqual(navigation2TraceContext?.trace_id);
72+
expect(navigation1TraceHeader?.sample_rand).not.toEqual(navigation2TraceHeader?.sample_rand);
7073
});
7174

7275
sentryTest('error after navigation has navigation traceId', async ({ getLocalTestUrl, page }) => {
@@ -101,6 +104,7 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
101104
sample_rate: '1',
102105
sampled: 'true',
103106
trace_id: navigationTraceContext?.trace_id,
107+
sample_rand: expect.any(String),
104108
});
105109

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

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

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

@@ -234,6 +241,7 @@ sentryTest(
234241
sample_rate: '1',
235242
sampled: 'true',
236243
trace_id: navigationTraceContext?.trace_id,
244+
sample_rand: expect.any(String),
237245
});
238246

239247
const headers = request.headers();
@@ -242,7 +250,7 @@ sentryTest(
242250
const navigationTraceId = navigationTraceContext?.trace_id;
243251
expect(headers['sentry-trace']).toMatch(new RegExp(`^${navigationTraceId}-[0-9a-f]{16}-1$`));
244252
expect(headers['baggage']).toEqual(
245-
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true`,
253+
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true,sentry-sample_rand=${navigationTraceHeader?.sample_rand}`,
246254
);
247255
},
248256
);
@@ -296,6 +304,7 @@ sentryTest(
296304
sample_rate: '1',
297305
sampled: 'true',
298306
trace_id: navigationTraceContext?.trace_id,
307+
sample_rand: expect.any(String),
299308
});
300309

301310
const headers = request.headers();
@@ -304,7 +313,7 @@ sentryTest(
304313
const navigationTraceId = navigationTraceContext?.trace_id;
305314
expect(headers['sentry-trace']).toMatch(new RegExp(`^${navigationTraceId}-[0-9a-f]{16}-1$`));
306315
expect(headers['baggage']).toEqual(
307-
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true`,
316+
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sample_rate=1,sentry-sampled=true,sentry-sample_rand=${navigationTraceHeader?.sample_rand}`,
308317
);
309318
},
310319
);

dev-packages/browser-integration-tests/suites/tracing/trace-lifetime/pageload-meta/template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="sentry-trace" content="12345678901234567890123456789012-1234567890123456-1" />
66
<meta name="baggage"
7-
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"/>
7+
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"/>
88
</head>
99
<body>
1010
<button id="errorBtn">Throw Error</button>

0 commit comments

Comments
 (0)