Skip to content

Commit 5021a58

Browse files
authored
feat: Pass parentSampleRate to tracesSampler (#15024)
1 parent bde8318 commit 5021a58

File tree

42 files changed

+469
-102
lines changed

Some content is hidden

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

42 files changed

+469
-102
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ sentryTest('should capture an INP click event span after pageload', async ({ bro
6767
'sentry.exclusive_time': inpValue,
6868
'sentry.op': 'ui.interaction.click',
6969
'sentry.origin': 'auto.http.browser.inp',
70-
'sentry.sample_rate': 1,
7170
'sentry.source': 'custom',
7271
transaction: 'test-url',
7372
'user_agent.original': expect.stringContaining('Chrome'),

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ sentryTest(
7070
'sentry.exclusive_time': inpValue,
7171
'sentry.op': 'ui.interaction.click',
7272
'sentry.origin': 'auto.http.browser.inp',
73-
'sentry.sample_rate': 1,
7473
'sentry.source': 'custom',
7574
transaction: 'test-route',
7675
'user_agent.original': expect.stringContaining('Chrome'),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ sentryTest(
250250
const navigationTraceId = navigationTraceContext?.trace_id;
251251
expect(headers['sentry-trace']).toMatch(new RegExp(`^${navigationTraceId}-[0-9a-f]{16}-1$`));
252252
expect(headers['baggage']).toEqual(
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}`,
253+
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sampled=true,sentry-sample_rand=${navigationTraceHeader?.sample_rand},sentry-sample_rate=1`,
254254
);
255255
},
256256
);
@@ -313,7 +313,7 @@ sentryTest(
313313
const navigationTraceId = navigationTraceContext?.trace_id;
314314
expect(headers['sentry-trace']).toMatch(new RegExp(`^${navigationTraceId}-[0-9a-f]{16}-1$`));
315315
expect(headers['baggage']).toEqual(
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}`,
316+
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${navigationTraceId},sentry-sampled=true,sentry-sample_rand=${navigationTraceHeader?.sample_rand},sentry-sample_rate=1`,
317317
);
318318
},
319319
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ sentryTest(
240240
// sampling decision is propagated from active span sampling decision
241241
expect(headers['sentry-trace']).toMatch(new RegExp(`^${pageloadTraceId}-[0-9a-f]{16}-1$`));
242242
expect(headers['baggage']).toBe(
243-
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${pageloadTraceId},sentry-sample_rate=1,sentry-sampled=true,sentry-sample_rand=${pageloadTraceHeader?.sample_rand}`,
243+
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${pageloadTraceId},sentry-sampled=true,sentry-sample_rand=${pageloadTraceHeader?.sample_rand},sentry-sample_rate=1`,
244244
);
245245
},
246246
);
@@ -297,7 +297,7 @@ sentryTest(
297297
// sampling decision is propagated from active span sampling decision
298298
expect(headers['sentry-trace']).toMatch(new RegExp(`^${pageloadTraceId}-[0-9a-f]{16}-1$`));
299299
expect(headers['baggage']).toBe(
300-
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${pageloadTraceId},sentry-sample_rate=1,sentry-sampled=true,sentry-sample_rand=${pageloadTraceHeader?.sample_rand}`,
300+
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${pageloadTraceId},sentry-sampled=true,sentry-sample_rand=${pageloadTraceHeader?.sample_rand},sentry-sample_rate=1`,
301301
);
302302
},
303303
);

dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.dynamic.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => {
3131
data: expect.objectContaining({
3232
'sentry.op': 'pageload',
3333
'sentry.origin': 'auto.pageload.browser',
34-
'sentry.sample_rate': 1,
3534
'sentry.source': 'url',
3635
}),
3736
op: 'pageload',

dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.static.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ test.describe('tracing in static/pre-rendered routes', () => {
3636
data: expect.objectContaining({
3737
'sentry.op': 'pageload',
3838
'sentry.origin': 'auto.pageload.browser',
39-
'sentry.sample_rate': 1,
4039
'sentry.source': 'url',
4140
}),
4241
op: 'pageload',

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => {
3131
data: expect.objectContaining({
3232
'sentry.op': 'pageload',
3333
'sentry.origin': 'auto.pageload.browser',
34-
'sentry.sample_rate': 1,
3534
'sentry.source': 'url',
3635
}),
3736
op: 'pageload',

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.serverIslands.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ test.describe('tracing in static routes with server islands', () => {
3333
data: expect.objectContaining({
3434
'sentry.op': 'pageload',
3535
'sentry.origin': 'auto.pageload.browser',
36-
'sentry.sample_rate': 1,
3736
'sentry.source': 'url',
3837
}),
3938
op: 'pageload',
@@ -75,7 +74,6 @@ test.describe('tracing in static routes with server islands', () => {
7574
data: expect.objectContaining({
7675
'sentry.op': 'http.server',
7776
'sentry.origin': 'auto.http.astro',
78-
'sentry.sample_rate': 1,
7977
'sentry.source': 'route',
8078
}),
8179
op: 'http.server',

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.static.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ test.describe('tracing in static/pre-rendered routes', () => {
3636
data: expect.objectContaining({
3737
'sentry.op': 'pageload',
3838
'sentry.origin': 'auto.pageload.browser',
39-
'sentry.sample_rate': 1,
4039
'sentry.source': 'url',
4140
}),
4241
op: 'pageload',

dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/tests/events.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ test('Event emitter', async () => {
3232
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
3333
data: {
3434
'sentry.source': 'custom',
35-
'sentry.sample_rate': 1,
3635
'sentry.op': 'event.nestjs',
3736
'sentry.origin': 'auto.event.nestjs',
3837
},

dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/tests/propagation.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
8989
'sentry.source': 'route',
9090
'sentry.origin': 'auto.http.otel.http',
9191
'sentry.op': 'http.server',
92-
'sentry.sample_rate': 1,
9392
url: `http://localhost:3030/test-inbound-headers/${id}`,
9493
'otel.kind': 'SERVER',
9594
'http.response.status_code': 200,
@@ -204,7 +203,6 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
204203
'sentry.source': 'route',
205204
'sentry.origin': 'auto.http.otel.http',
206205
'sentry.op': 'http.server',
207-
'sentry.sample_rate': 1,
208206
url: `http://localhost:3030/test-inbound-headers/${id}`,
209207
'otel.kind': 'SERVER',
210208
'http.response.status_code': 200,

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/transactions.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ test('Sends a pageload transaction', async ({ page }) => {
3636
data: expect.objectContaining({
3737
'sentry.op': 'pageload',
3838
'sentry.origin': 'auto.pageload.nextjs.app_router_instrumentation',
39-
'sentry.sample_rate': 1,
4039
'sentry.source': 'url',
4140
}),
4241
},

dev-packages/e2e-tests/test-applications/node-fastify-5/tests/propagation.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
8989
'sentry.source': 'route',
9090
'sentry.origin': 'auto.http.otel.http',
9191
'sentry.op': 'http.server',
92-
'sentry.sample_rate': 1,
9392
url: `http://localhost:3030/test-inbound-headers/${id}`,
9493
'otel.kind': 'SERVER',
9594
'http.response.status_code': 200,
@@ -204,7 +203,6 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
204203
'sentry.source': 'route',
205204
'sentry.origin': 'auto.http.otel.http',
206205
'sentry.op': 'http.server',
207-
'sentry.sample_rate': 1,
208206
url: `http://localhost:3030/test-inbound-headers/${id}`,
209207
'otel.kind': 'SERVER',
210208
'http.response.status_code': 200,

dev-packages/e2e-tests/test-applications/node-fastify/tests/propagation.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
8989
'sentry.source': 'route',
9090
'sentry.origin': 'auto.http.otel.http',
9191
'sentry.op': 'http.server',
92-
'sentry.sample_rate': 1,
9392
url: `http://localhost:3030/test-inbound-headers/${id}`,
9493
'otel.kind': 'SERVER',
9594
'http.response.status_code': 200,
@@ -204,7 +203,6 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
204203
'sentry.source': 'route',
205204
'sentry.origin': 'auto.http.otel.http',
206205
'sentry.op': 'http.server',
207-
'sentry.sample_rate': 1,
208206
url: `http://localhost:3030/test-inbound-headers/${id}`,
209207
'otel.kind': 'SERVER',
210208
'http.response.status_code': 200,

dev-packages/e2e-tests/test-applications/node-koa/tests/propagation.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
8989
'sentry.source': 'route',
9090
'sentry.origin': 'auto.http.otel.http',
9191
'sentry.op': 'http.server',
92-
'sentry.sample_rate': 1,
9392
url: `http://localhost:3030/test-inbound-headers/${id}`,
9493
'otel.kind': 'SERVER',
9594
'http.response.status_code': 200,
@@ -204,7 +203,6 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
204203
'sentry.source': 'route',
205204
'sentry.origin': 'auto.http.otel.http',
206205
'sentry.op': 'http.server',
207-
'sentry.sample_rate': 1,
208206
url: `http://localhost:3030/test-inbound-headers/${id}`,
209207
'otel.kind': 'SERVER',
210208
'http.response.status_code': 200,

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-assign/test.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { parseBaggageHeader } from '@sentry/core';
12
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
23
import type { TestAPIResponse } from '../server';
34

@@ -102,14 +103,20 @@ test('Should populate and propagate sentry baggage if sentry-trace header does n
102103
const response = await runner.makeRequest<TestAPIResponse>('get', '/test/express');
103104

104105
expect(response).toBeDefined();
105-
expect(response).toMatchObject({
106-
test_data: {
107-
host: 'somewhere.not.sentry',
108-
// TraceId changes, hence we only expect that the string contains the traceid key
109-
baggage: expect.stringMatching(
110-
/sentry-environment=prod,sentry-release=1.0,sentry-public_key=public,sentry-trace_id=[\S]*,sentry-sample_rate=1,sentry-transaction=GET%20%2Ftest%2Fexpress/,
111-
),
112-
},
106+
107+
const parsedBaggage = parseBaggageHeader(response?.test_data.baggage);
108+
109+
expect(response?.test_data.host).toBe('somewhere.not.sentry');
110+
expect(parsedBaggage).toStrictEqual({
111+
'sentry-environment': 'prod',
112+
'sentry-release': '1.0',
113+
'sentry-public_key': 'public',
114+
// TraceId changes, hence we only expect that the string contains the traceid key
115+
'sentry-trace_id': expect.stringMatching(/[\S]*/),
116+
'sentry-sample_rand': expect.stringMatching(/[\S]*/),
117+
'sentry-sample_rate': '1',
118+
'sentry-sampled': 'true',
119+
'sentry-transaction': 'GET /test/express',
113120
});
114121
});
115122

@@ -123,13 +130,18 @@ test('Should populate Sentry and ignore 3rd party content if sentry-trace header
123130
});
124131

125132
expect(response).toBeDefined();
126-
expect(response).toMatchObject({
127-
test_data: {
128-
host: 'somewhere.not.sentry',
129-
// TraceId changes, hence we only expect that the string contains the traceid key
130-
baggage: expect.stringMatching(
131-
/sentry-environment=prod,sentry-release=1.0,sentry-public_key=public,sentry-trace_id=[\S]*,sentry-sample_rate=1,sentry-transaction=GET%20%2Ftest%2Fexpress/,
132-
),
133-
},
133+
expect(response?.test_data.host).toBe('somewhere.not.sentry');
134+
135+
const parsedBaggage = parseBaggageHeader(response?.test_data.baggage);
136+
expect(parsedBaggage).toStrictEqual({
137+
'sentry-environment': 'prod',
138+
'sentry-release': '1.0',
139+
'sentry-public_key': 'public',
140+
// TraceId changes, hence we only expect that the string contains the traceid key
141+
'sentry-trace_id': expect.stringMatching(/[\S]*/),
142+
'sentry-sample_rand': expect.stringMatching(/[\S]*/),
143+
'sentry-sample_rate': '1',
144+
'sentry-sampled': 'true',
145+
'sentry-transaction': 'GET /test/express',
134146
});
135147
});

dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span-unsampled/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test('envelope header for error event during active unsampled span is correct',
1010
public_key: 'public',
1111
environment: 'production',
1212
release: '1.0',
13+
sample_rate: '0',
1314
sampled: 'false',
1415
sample_rand: expect.any(String),
1516
},

dev-packages/node-integration-tests/suites/sample-rand-propagation/test.ts renamed to dev-packages/node-integration-tests/suites/tracing/sample-rand-propagation/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cleanupChildProcesses, createRunner } from '../../utils/runner';
1+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
22

33
describe('sample_rand propagation', () => {
44
afterAll(() => {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2+
const Sentry = require('@sentry/node');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
transport: loggingTransport,
7+
});
8+
9+
// express must be required after Sentry is initialized
10+
const express = require('express');
11+
const cors = require('cors');
12+
const {
13+
startExpressServerAndSendPortToRunner,
14+
getPortAppIsRunningOn,
15+
} = require('@sentry-internal/node-integration-tests');
16+
17+
const app = express();
18+
19+
app.use(cors());
20+
21+
app.get('/check', (req, res) => {
22+
const appPort = getPortAppIsRunningOn(app);
23+
// eslint-disable-next-line no-undef
24+
fetch(`http://localhost:${appPort}/bounce`)
25+
.then(r => r.json())
26+
.then(bounceRes => {
27+
res.json({ propagatedData: bounceRes });
28+
});
29+
});
30+
31+
app.get('/bounce', (req, res) => {
32+
res.json({
33+
baggage: req.headers['baggage'],
34+
});
35+
});
36+
37+
Sentry.setupExpressErrorHandler(app);
38+
39+
startExpressServerAndSendPortToRunner(app);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
2+
3+
describe('parentSampleRate propagation with no tracing enabled', () => {
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
test('should propagate an incoming sample rate', async () => {
9+
const runner = createRunner(__dirname, 'server.js').start();
10+
const response = await runner.makeRequest('get', '/check', {
11+
headers: {
12+
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-1',
13+
baggage: 'sentry-sample_rate=0.1337',
14+
},
15+
});
16+
17+
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.1337/);
18+
});
19+
20+
test('should not propagate a sample rate for root traces', async () => {
21+
const runner = createRunner(__dirname, 'server.js').start();
22+
const response = await runner.makeRequest('get', '/check');
23+
expect((response as any).propagatedData.baggage).not.toMatch(/sentry-sample_rate/);
24+
});
25+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2+
const Sentry = require('@sentry/node');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
transport: loggingTransport,
7+
tracesSampleRate: 0,
8+
});
9+
10+
// express must be required after Sentry is initialized
11+
const express = require('express');
12+
const cors = require('cors');
13+
const {
14+
startExpressServerAndSendPortToRunner,
15+
getPortAppIsRunningOn,
16+
} = require('@sentry-internal/node-integration-tests');
17+
18+
const app = express();
19+
20+
app.use(cors());
21+
22+
app.get('/check', (req, res) => {
23+
const appPort = getPortAppIsRunningOn(app);
24+
// eslint-disable-next-line no-undef
25+
fetch(`http://localhost:${appPort}/bounce`)
26+
.then(r => r.json())
27+
.then(bounceRes => {
28+
res.json({ propagatedData: bounceRes });
29+
});
30+
});
31+
32+
app.get('/bounce', (req, res) => {
33+
res.json({
34+
baggage: req.headers['baggage'],
35+
});
36+
});
37+
38+
Sentry.setupExpressErrorHandler(app);
39+
40+
startExpressServerAndSendPortToRunner(app);

0 commit comments

Comments
 (0)