Skip to content

Commit 4f8f07b

Browse files
authored
ref(tracing): Don't track transaction sampling method (#5775)
In our initial work on Dynamic Sampling (#3068), we added the ability to track transaction sampling method. https://github.com/getsentry/sentry-javascript/pull/3068/files#diff-337facb22f742f05b3326aed66ca6b0d5eb9c782c7c03c88ef0170fd97dc410dR104-R109 ```ts export enum TransactionSamplingMethod { Explicit = 'explicitly_set', Sampler = 'client_sampler', Rate = 'client_rate', Inheritance = 'inheritance', } ``` To use this info, we set the transaction sampling method and sample rate on the transaction event header: ```ts sample_rates: [{ id: samplingMethod, rate: sampleRate }], ``` In Relay this is used here: https://github.com/getsentry/relay/blob/4b16d279ccf21d3c1d975b652ffca01ebd72a500/relay-general/src/protocol/metrics.rs#L7-L16 This is no longer needed for dynamic sampling context with the introduction of Dynamic Sampling Context, so we can remove this code.
1 parent 5660d9f commit 4f8f07b

File tree

8 files changed

+13
-41
lines changed

8 files changed

+13
-41
lines changed

packages/core/src/envelope.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ export function createEventEnvelope(
7070
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);
7171
const eventType = event.type || 'event';
7272

73-
const { transactionSampling } = event.sdkProcessingMetadata || {};
74-
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
75-
7673
enhanceEventWithSdkInfo(event, metadata && metadata.sdk);
7774

7875
const envelopeHeaders = createEventEnvelopeHeaders(event, sdkInfo, tunnel, dsn);
@@ -83,13 +80,7 @@ export function createEventEnvelope(
8380
// of this `delete`, lest we miss putting it back in the next time the property is in use.)
8481
delete event.sdkProcessingMetadata;
8582

86-
const eventItem: EventItem = [
87-
{
88-
type: eventType,
89-
sample_rates: [{ id: samplingMethod, rate: sampleRate }],
90-
},
91-
event,
92-
];
83+
const eventItem: EventItem = [{ type: eventType }, event];
9384
return createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]);
9485
}
9586

packages/tracing/src/hubextensions.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ function sample<T extends Transaction>(
5555
// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
5656
if (transaction.sampled !== undefined) {
5757
transaction.setMetadata({
58-
transactionSampling: {
59-
method: 'explicitly_set',
60-
rate: Number(transaction.sampled),
61-
},
58+
sampleRate: Number(transaction.sampled),
6259
});
6360
return transaction;
6461
}
@@ -69,25 +66,14 @@ function sample<T extends Transaction>(
6966
if (typeof options.tracesSampler === 'function') {
7067
sampleRate = options.tracesSampler(samplingContext);
7168
transaction.setMetadata({
72-
transactionSampling: {
73-
method: 'client_sampler',
74-
// cast to number in case it's a boolean
75-
rate: Number(sampleRate),
76-
},
69+
sampleRate: Number(sampleRate),
7770
});
7871
} else if (samplingContext.parentSampled !== undefined) {
7972
sampleRate = samplingContext.parentSampled;
80-
transaction.setMetadata({
81-
transactionSampling: { method: 'inheritance' },
82-
});
8373
} else {
8474
sampleRate = options.tracesSampleRate;
8575
transaction.setMetadata({
86-
transactionSampling: {
87-
method: 'client_rate',
88-
// cast to number in case it's a boolean
89-
rate: Number(sampleRate),
90-
},
76+
sampleRate: Number(sampleRate),
9177
});
9278
}
9379

packages/tracing/src/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
244244
const { environment, release } = client.getOptions() || {};
245245
const { publicKey: public_key } = client.getDsn() || {};
246246

247-
const maybeSampleRate = (this.metadata.transactionSampling || {}).rate;
247+
const maybeSampleRate = this.metadata.sampleRate;
248248
const sample_rate = maybeSampleRate !== undefined ? maybeSampleRate.toString() : undefined;
249249

250250
const scope = hub.getScope();

packages/tracing/test/hub.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe('Hub', () => {
243243
hub.startTransaction({ name: 'dogpark', sampled: true });
244244

245245
expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
246-
transactionSampling: { method: 'explicitly_set', rate: 1.0 },
246+
sampleRate: 1.0,
247247
});
248248
});
249249

@@ -255,7 +255,7 @@ describe('Hub', () => {
255255
hub.startTransaction({ name: 'dogpark' });
256256

257257
expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
258-
transactionSampling: { method: 'client_sampler', rate: 0.1121 },
258+
sampleRate: 0.1121,
259259
});
260260
});
261261

@@ -265,9 +265,7 @@ describe('Hub', () => {
265265
makeMain(hub);
266266
hub.startTransaction({ name: 'dogpark', parentSampled: true });
267267

268-
expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
269-
transactionSampling: { method: 'inheritance' },
270-
});
268+
expect(Transaction.prototype.setMetadata).toHaveBeenCalledTimes(0);
271269
});
272270

273271
it('should record sampling method and rate when sampling decision comes from traceSampleRate', () => {
@@ -277,7 +275,7 @@ describe('Hub', () => {
277275
hub.startTransaction({ name: 'dogpark' });
278276

279277
expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
280-
transactionSampling: { method: 'client_rate', rate: 0.1121 },
278+
sampleRate: 0.1121,
281279
});
282280
});
283281
});

packages/tracing/test/span.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ describe('Span', () => {
424424
{
425425
name: 'tx',
426426
metadata: {
427-
transactionSampling: { rate: 0.56, method: 'client_rate' },
427+
sampleRate: 0.56,
428428
},
429429
},
430430
hub,

packages/types/src/envelope.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DsnComponents } from './dsn';
33
import { Event } from './event';
44
import { SdkInfo } from './sdkinfo';
55
import { Session, SessionAggregates } from './session';
6-
import { Transaction, TransactionSamplingMethod } from './transaction';
6+
import { Transaction } from './transaction';
77
import { UserFeedback } from './user';
88

99
// Based on: https://develop.sentry.dev/sdk/envelopes/
@@ -49,7 +49,6 @@ type BaseEnvelope<EH extends BaseEnvelopeHeaders, I extends BaseEnvelopeItem<Bas
4949

5050
type EventItemHeaders = {
5151
type: 'event' | 'transaction';
52-
sample_rates?: [{ id?: TransactionSamplingMethod; rate?: number }];
5352
};
5453
type AttachmentItemHeaders = {
5554
type: 'attachment';

packages/types/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export type {
7070
Transaction,
7171
TransactionContext,
7272
TransactionMetadata,
73-
TransactionSamplingMethod,
7473
TransactionSource,
7574
TransactionNameChange,
7675
} from './transaction';

packages/types/src/transaction.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ export interface SamplingContext extends CustomSamplingContext {
136136
request?: ExtractedNodeRequestData;
137137
}
138138

139-
export type TransactionSamplingMethod = 'explicitly_set' | 'client_sampler' | 'client_rate' | 'inheritance';
140-
141139
export interface TransactionMetadata {
142-
transactionSampling?: { rate?: number; method: TransactionSamplingMethod };
140+
/** The sample rate used when sampling this transaction */
141+
sampleRate?: number;
143142

144143
/**
145144
* The Dynamic Sampling Context of a transaction. If provided during transaction creation, its Dynamic Sampling

0 commit comments

Comments
 (0)