Skip to content

Commit

Permalink
ref(types): deprecate transactionmethod enum
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Dec 16, 2021
1 parent c986b1e commit 8782ffe
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
10 changes: 5 additions & 5 deletions packages/core/test/lib/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebugMeta, Event, SentryRequest, TransactionSamplingMethod } from '@sentry/types';
import { DebugMeta, Event, SentryRequest } from '@sentry/types';

import { initAPIDetails } from '../../src/api';
import { eventToSentryRequest, sessionToSentryRequest } from '../../src/request';
Expand Down Expand Up @@ -44,21 +44,21 @@ describe('eventToSentryRequest', () => {
});

it('adds transaction sampling information to item header', () => {
event.debug_meta = { transactionSampling: { method: TransactionSamplingMethod.Rate, rate: 0.1121 } };
event.debug_meta = { transactionSampling: { method: 'client_rate', rate: 0.1121 } };

const result = eventToSentryRequest(event, api);
const envelope = parseEnvelopeRequest(result);

expect(envelope.itemHeader).toEqual(
expect.objectContaining({
sample_rates: [{ id: TransactionSamplingMethod.Rate, rate: 0.1121 }],
sample_rates: [{ id: 'client_rate', rate: 0.1121 }],
}),
);
});

it('removes transaction sampling information (and only that) from debug_meta', () => {
event.debug_meta = {
transactionSampling: { method: TransactionSamplingMethod.Sampler, rate: 0.1121 },
transactionSampling: { method: 'client_sampler', rate: 0.1121 },
dog: 'Charlie',
} as DebugMeta;

Expand All @@ -71,7 +71,7 @@ describe('eventToSentryRequest', () => {

it('removes debug_meta entirely if it ends up empty', () => {
event.debug_meta = {
transactionSampling: { method: TransactionSamplingMethod.Rate, rate: 0.1121 },
transactionSampling: { method: 'client_rate', rate: 0.1121 },
} as DebugMeta;

const result = eventToSentryRequest(event, api);
Expand Down
9 changes: 4 additions & 5 deletions packages/tracing/src/hubextensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Options,
SamplingContext,
TransactionContext,
TransactionSamplingMethod,
} from '@sentry/types';
import { dynamicRequire, isNodeEnv, loadModule, logger } from '@sentry/utils';

Expand Down Expand Up @@ -51,7 +50,7 @@ function sample<T extends Transaction>(transaction: T, options: Options, samplin
// 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: TransactionSamplingMethod.Explicit },
transactionSampling: { method: 'explicitly_set' },
});
return transaction;
}
Expand All @@ -63,21 +62,21 @@ function sample<T extends Transaction>(transaction: T, options: Options, samplin
sampleRate = options.tracesSampler(samplingContext);
transaction.setMetadata({
transactionSampling: {
method: TransactionSamplingMethod.Sampler,
method: 'client_sampler',
// cast to number in case it's a boolean
rate: Number(sampleRate),
},
});
} else if (samplingContext.parentSampled !== undefined) {
sampleRate = samplingContext.parentSampled;
transaction.setMetadata({
transactionSampling: { method: TransactionSamplingMethod.Inheritance },
transactionSampling: { method: 'inheritance' },
});
} else {
sampleRate = options.tracesSampleRate;
transaction.setMetadata({
transactionSampling: {
method: TransactionSamplingMethod.Rate,
method: 'client_rate',
// cast to number in case it's a boolean
rate: Number(sampleRate),
},
Expand Down
9 changes: 4 additions & 5 deletions packages/tracing/test/hub.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { BrowserClient } from '@sentry/browser';
import { Hub, makeMain } from '@sentry/hub';
import { TransactionSamplingMethod } from '@sentry/types';
import * as utilsModule from '@sentry/utils'; // for mocking
import { logger } from '@sentry/utils';

Expand Down Expand Up @@ -221,7 +220,7 @@ describe('Hub', () => {
hub.startTransaction({ name: 'dogpark', sampled: true });

expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
transactionSampling: { method: TransactionSamplingMethod.Explicit },
transactionSampling: { method: 'explicitly_set' },
});
});

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

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

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

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

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

expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({
transactionSampling: { method: TransactionSamplingMethod.Rate, rate: 0.1121 },
transactionSampling: { method: 'client_rate', rate: 0.1121 },
});
});
});
Expand Down
9 changes: 2 additions & 7 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,10 @@ export interface SamplingContext extends CustomSamplingContext {

export type Measurements = Record<string, { value: number }>;

export enum TransactionSamplingMethod {
Explicit = 'explicitly_set',
Sampler = 'client_sampler',
Rate = 'client_rate',
Inheritance = 'inheritance',
}
export type TransactionSamplingMethod = 'explicitly_set' | 'client_sampler' | 'client_rate' | 'inheritance';

export interface TransactionMetadata {
transactionSampling?: { rate?: number; method?: string };
transactionSampling?: { rate?: number; method?: TransactionSamplingMethod };

/** The two halves (sentry and third-party) of a transaction's tracestate header, used for dynamic sampling */
tracestate?: {
Expand Down
9 changes: 9 additions & 0 deletions packages/types/src/transactionsamplingmethod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** JSDoc
* @deprecated Use string literals - if you require type casting, cast to TransactionSamplingMethod type
*/
export enum TransactionSamplingMethod {
Explicit = 'explicitly_set',
Sampler = 'client_sampler',
Rate = 'client_rate',
Inheritance = 'inheritance',
}

0 comments on commit 8782ffe

Please sign in to comment.