Skip to content

ref(tracing): Don't track transaction sampling method #5775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions packages/core/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export function createEventEnvelope(
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);
const eventType = event.type || 'event';

const { transactionSampling } = event.sdkProcessingMetadata || {};
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};

enhanceEventWithSdkInfo(event, metadata && metadata.sdk);

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

const eventItem: EventItem = [
{
type: eventType,
sample_rates: [{ id: samplingMethod, rate: sampleRate }],
},
event,
];
const eventItem: EventItem = [{ type: eventType }, event];
return createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]);
}

Expand Down
20 changes: 3 additions & 17 deletions packages/tracing/src/hubextensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ function sample<T extends Transaction>(
// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
if (transaction.sampled !== undefined) {
transaction.setMetadata({
transactionSampling: {
method: 'explicitly_set',
rate: Number(transaction.sampled),
},
sampleRate: Number(transaction.sampled),
});
return transaction;
}
Expand All @@ -69,25 +66,14 @@ function sample<T extends Transaction>(
if (typeof options.tracesSampler === 'function') {
sampleRate = options.tracesSampler(samplingContext);
transaction.setMetadata({
transactionSampling: {
method: 'client_sampler',
// cast to number in case it's a boolean
rate: Number(sampleRate),
},
sampleRate: Number(sampleRate),
});
} else if (samplingContext.parentSampled !== undefined) {
sampleRate = samplingContext.parentSampled;
transaction.setMetadata({
transactionSampling: { method: 'inheritance' },
});
} else {
sampleRate = options.tracesSampleRate;
transaction.setMetadata({
transactionSampling: {
method: 'client_rate',
// cast to number in case it's a boolean
rate: Number(sampleRate),
},
sampleRate: Number(sampleRate),
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
const { environment, release } = client.getOptions() || {};
const { publicKey: public_key } = client.getDsn() || {};

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

const scope = hub.getScope();
Expand Down
10 changes: 4 additions & 6 deletions packages/tracing/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('Hub', () => {
hub.startTransaction({ name: 'dogpark', sampled: true });

expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
transactionSampling: { method: 'explicitly_set', rate: 1.0 },
sampleRate: 1.0,
});
});

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

expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
transactionSampling: { method: 'client_sampler', rate: 0.1121 },
sampleRate: 0.1121,
});
});

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

expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
transactionSampling: { method: 'inheritance' },
});
expect(Transaction.prototype.setMetadata).toHaveBeenCalledTimes(0);
});

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

expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
transactionSampling: { method: 'client_rate', rate: 0.1121 },
sampleRate: 0.1121,
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ describe('Span', () => {
{
name: 'tx',
metadata: {
transactionSampling: { rate: 0.56, method: 'client_rate' },
sampleRate: 0.56,
},
},
hub,
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DsnComponents } from './dsn';
import { Event } from './event';
import { SdkInfo } from './sdkinfo';
import { Session, SessionAggregates } from './session';
import { Transaction, TransactionSamplingMethod } from './transaction';
import { Transaction } from './transaction';
import { UserFeedback } from './user';

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

type EventItemHeaders = {
type: 'event' | 'transaction';
sample_rates?: [{ id?: TransactionSamplingMethod; rate?: number }];
};
type AttachmentItemHeaders = {
type: 'attachment';
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export type {
Transaction,
TransactionContext,
TransactionMetadata,
TransactionSamplingMethod,
TransactionSource,
TransactionNameChange,
} from './transaction';
Expand Down
5 changes: 2 additions & 3 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ export interface SamplingContext extends CustomSamplingContext {
request?: ExtractedNodeRequestData;
}

export type TransactionSamplingMethod = 'explicitly_set' | 'client_sampler' | 'client_rate' | 'inheritance';

export interface TransactionMetadata {
transactionSampling?: { rate?: number; method: TransactionSamplingMethod };
/** The sample rate used when sampling this transaction */
sampleRate?: number;

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