Skip to content

Commit 43aff8d

Browse files
committed
use enum for method options
1 parent cec14a5 commit 43aff8d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

packages/tracing/src/hubextensions.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getActiveDomain, getMainCarrier, Hub } from '@sentry/hub';
2-
import { CustomSamplingContext, SamplingContext, TransactionContext } from '@sentry/types';
2+
import { CustomSamplingContext, SamplingContext, TransactionContext, TransactionSamplingMethod } from '@sentry/types';
33
import {
44
dynamicRequire,
55
extractNodeRequestData,
@@ -52,7 +52,7 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
5252

5353
// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
5454
if (transaction.sampled !== undefined) {
55-
transaction.tags = { ...transaction.tags, __sentry_samplingMethod: 'explicitly_set' };
55+
transaction.tags = { ...transaction.tags, __sentry_samplingMethod: TransactionSamplingMethod.Explicit };
5656
return transaction;
5757
}
5858

@@ -64,18 +64,20 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
6464
// cast the rate to a number first in case it's a boolean
6565
transaction.tags = {
6666
...transaction.tags,
67-
__sentry_samplingMethod: 'client_sampler',
67+
__sentry_samplingMethod: TransactionSamplingMethod.Sampler,
68+
// TODO kmclb - once tag types are loosened, don't need to cast to string here
6869
__sentry_sampleRate: String(Number(sampleRate)),
6970
};
7071
} else if (samplingContext.parentSampled !== undefined) {
7172
sampleRate = samplingContext.parentSampled;
72-
transaction.tags = { ...transaction.tags, __sentry_samplingMethod: 'inheritance' };
73+
transaction.tags = { ...transaction.tags, __sentry_samplingMethod: TransactionSamplingMethod.Inheritance };
7374
} else {
7475
sampleRate = options.tracesSampleRate;
7576
// cast the rate to a number first in case it's a boolean
7677
transaction.tags = {
7778
...transaction.tags,
78-
__sentry_samplingMethod: 'client_rate',
79+
__sentry_samplingMethod: TransactionSamplingMethod.Rate,
80+
// TODO kmclb - once tag types are loosened, don't need to cast to string here
7981
__sentry_sampleRate: String(Number(sampleRate)),
8082
};
8183
}

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export {
3232
TraceparentData,
3333
Transaction,
3434
TransactionContext,
35+
TransactionSamplingMethod,
3536
} from './transaction';
3637
export { Thread } from './thread';
3738
export { Transport, TransportOptions, TransportClass } from './transport';

packages/types/src/transaction.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,10 @@ export interface SamplingContext extends CustomSamplingContext {
100100
}
101101

102102
export type Measurements = Record<string, { value: number }>;
103+
104+
export enum TransactionSamplingMethod {
105+
Explicit = 'explicitly_set',
106+
Sampler = 'client_sampler',
107+
Rate = 'client_rate',
108+
Inheritance = 'inheritance',
109+
}

0 commit comments

Comments
 (0)