Skip to content

Commit 5778f9f

Browse files
committed
feat(core): Add sampling decision to trace envelope header
1 parent db9523e commit 5778f9f

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
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
@@ -131,7 +131,8 @@ describe('tracing', () => {
131131
expect(baggageHeader).toEqual(
132132
'sentry-environment=production,sentry-release=1.0.0,' +
133133
'sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' +
134-
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-transaction=dogpark',
134+
'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,' +
135+
'sentry-transaction=dogpark,sentry-sampled=true',
135136
);
136137
});
137138

@@ -143,10 +144,10 @@ describe('tracing', () => {
143144
const request = http.get({ host: 'http://dogs.are.great/', headers: { baggage: 'dog=great' } });
144145
const baggageHeader = request.getHeader('baggage') as string;
145146

146-
expect(baggageHeader).toEqual([
147-
'dog=great',
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',
149-
]);
147+
expect(baggageHeader[0]).toEqual('dog=great');
148+
expect(baggageHeader[1]).toEqual(
149+
'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',
150+
);
150151
});
151152

152153
it('adds the transaction name to the the baggage header if a valid transaction source is set', async () => {
@@ -159,7 +160,7 @@ describe('tracing', () => {
159160

160161
expect(baggageHeader).toEqual([
161162
'dog=great',
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-transaction=dogpark',
163+
'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',
163164
]);
164165
});
165166

@@ -173,7 +174,7 @@ describe('tracing', () => {
173174

174175
expect(baggageHeader).toEqual([
175176
'dog=great',
176-
'sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1',
177+
'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',
177178
]);
178179
});
179180

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)