@@ -14,6 +14,13 @@ import { IdleTransaction } from './idletransaction';
14
14
import { Transaction } from './transaction' ;
15
15
import { hasTracingEnabled } from './utils' ;
16
16
17
+ const SAMPLING_METHODS = {
18
+ explicit : 'explicitly_set' ,
19
+ sampler : 'client_sampler' ,
20
+ rate : 'client_rate' ,
21
+ inheritance : 'inheritance' ,
22
+ } ;
23
+
17
24
/** Returns all trace headers that are currently on the top scope. */
18
25
function traceHeaders ( this : Hub ) : { [ key : string ] : string } {
19
26
const scope = this . getScope ( ) ;
@@ -52,7 +59,7 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
52
59
53
60
// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
54
61
if ( transaction . sampled !== undefined ) {
55
- transaction . tags = { ...transaction . tags , __sentry_samplingMethod : 'explicitly_set' } ;
62
+ transaction . tags = { ...transaction . tags , __sentry_samplingMethod : SAMPLING_METHODS . explicit } ;
56
63
return transaction ;
57
64
}
58
65
@@ -64,18 +71,18 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
64
71
// cast the rate to a number first in case it's a boolean
65
72
transaction . tags = {
66
73
...transaction . tags ,
67
- __sentry_samplingMethod : 'client_sampler' ,
74
+ __sentry_samplingMethod : SAMPLING_METHODS . sampler ,
68
75
__sentry_sampleRate : String ( Number ( sampleRate ) ) ,
69
76
} ;
70
77
} else if ( samplingContext . parentSampled !== undefined ) {
71
78
sampleRate = samplingContext . parentSampled ;
72
- transaction . tags = { ...transaction . tags , __sentry_samplingMethod : ' inheritance' } ;
79
+ transaction . tags = { ...transaction . tags , __sentry_samplingMethod : SAMPLING_METHODS . inheritance } ;
73
80
} else {
74
81
sampleRate = options . tracesSampleRate ;
75
82
// cast the rate to a number first in case it's a boolean
76
83
transaction . tags = {
77
84
...transaction . tags ,
78
- __sentry_samplingMethod : 'client_rate' ,
85
+ __sentry_samplingMethod : SAMPLING_METHODS . rate ,
79
86
__sentry_sampleRate : String ( Number ( sampleRate ) ) ,
80
87
} ;
81
88
}
0 commit comments