Skip to content

Commit 3470ab2

Browse files
committed
feat(core): Add sampling decision to trace envelope header
1 parent 86ffdf4 commit 3470ab2

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

packages/core/src/tracing/transaction.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ export class Transaction extends SpanClass implements TransactionInterface {
264264
dsc.transaction = this.name;
265265
}
266266

267+
if (this.sampled !== undefined) {
268+
dsc.sampled = String(this.sampled);
269+
}
270+
267271
// Uncomment if we want to make DSC immutable
268272
// this._frozenDynamicSamplingContext = dsc;
269273

packages/node/test/integrations/http.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ describe('tracing', () => {
116116
expect(baggageHeader).toEqual(
117117
'sentry-environment=production,sentry-release=1.0.0,' +
118118
'sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' +
119-
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-transaction=dogpark',
119+
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,' +
120+
'sentry-transaction=dogpark,sentry-sampled=true',
120121
);
121122
});
122123

@@ -128,10 +129,10 @@ describe('tracing', () => {
128129
const request = http.get({ host: 'http://dogs.are.great/', headers: { baggage: 'dog=great' } });
129130
const baggageHeader = request.getHeader('baggage') as string;
130131

131-
expect(baggageHeader).toEqual([
132-
'dog=great',
133-
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-transaction=dogpark',
134-
]);
132+
expect(baggageHeader[0]).toEqual('dog=great');
133+
expect(baggageHeader[1]).toEqual(
134+
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-transaction=dogpark,sentry-sampled=true',
135+
);
135136
});
136137

137138
it('adds the transaction name to the the baggage header if a valid transaction source is set', async () => {
@@ -144,7 +145,7 @@ describe('tracing', () => {
144145

145146
expect(baggageHeader).toEqual([
146147
'dog=great',
147-
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-transaction=dogpark',
148+
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-transaction=dogpark,sentry-sampled=true',
148149
]);
149150
});
150151

@@ -158,7 +159,7 @@ describe('tracing', () => {
158159

159160
expect(baggageHeader).toEqual([
160161
'dog=great',
161-
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1',
162+
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-sampled=true',
162163
]);
163164
});
164165

packages/node/test/integrations/undici.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
204204

205205
expect(requestHeaders['sentry-trace']).toEqual(span?.toTraceparent());
206206
expect(requestHeaders['baggage']).toEqual(
207-
`sentry-environment=production,sentry-public_key=0,sentry-trace_id=${transaction.traceId},sentry-sample_rate=1,sentry-transaction=test-transaction`,
207+
`sentry-environment=production,sentry-public_key=0,sentry-trace_id=${transaction.traceId},sentry-sample_rate=1,sentry-transaction=test-transaction,sentry-sampled=true`,
208208
);
209209
});
210210

packages/tracing-internal/test/browser/browsertracing.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ conditionalTest({ min: 10 })('BrowserTracing', () => {
636636
release: '1.0.0',
637637
environment: 'production',
638638
public_key: 'pubKey',
639+
sampled: 'false',
639640
trace_id: expect.not.stringMatching('12312012123120121231201212312012'),
640641
});
641642
});

packages/types/src/envelope.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type DynamicSamplingContext = {
2020
transaction?: string;
2121
user_segment?: string;
2222
replay_id?: string;
23+
sampled?: string;
2324
};
2425

2526
export type EnvelopeItemType =

0 commit comments

Comments
 (0)