@@ -28,18 +28,6 @@ function traceHeaders(this: Hub): { [key: string]: string } {
28
28
return { } ;
29
29
}
30
30
31
- /**
32
- * Implements sampling inheritance and falls back to user-provided static rate if no parent decision is available.
33
- *
34
- * @param parentSampled: The parent transaction's sampling decision, if any.
35
- * @param givenRate: The rate to use if no parental decision is available.
36
- *
37
- * @returns The parent's sampling decision (if one exists), or the provided static rate
38
- */
39
- function _inheritOrUseGivenRate ( parentSampled : boolean | undefined , givenRate : unknown ) : boolean | unknown {
40
- return parentSampled !== undefined ? parentSampled : givenRate ;
41
- }
42
-
43
31
/**
44
32
* Makes a sampling decision for the given transaction and stores it on the transaction.
45
33
*
@@ -64,15 +52,33 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
64
52
65
53
// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
66
54
if ( transaction . sampled !== undefined ) {
55
+ transaction . tags = { ...transaction . tags , __sentry_samplingMethod : 'explicitly_set' } ;
67
56
return transaction ;
68
57
}
69
58
70
59
// we would have bailed already if neither `tracesSampler` nor `tracesSampleRate` were defined, so one of these should
71
60
// work; prefer the hook if so
72
- const sampleRate =
73
- typeof options . tracesSampler === 'function'
74
- ? options . tracesSampler ( samplingContext )
75
- : _inheritOrUseGivenRate ( samplingContext . parentSampled , options . tracesSampleRate ) ;
61
+ let sampleRate ;
62
+ if ( typeof options . tracesSampler === 'function' ) {
63
+ sampleRate = options . tracesSampler ( samplingContext ) ;
64
+ // cast the rate to a number first in case it's a boolean
65
+ transaction . tags = {
66
+ ...transaction . tags ,
67
+ __sentry_samplingMethod : 'client_sampler' ,
68
+ __sentry_sampleRate : String ( Number ( sampleRate ) ) ,
69
+ } ;
70
+ } else if ( samplingContext . parentSampled !== undefined ) {
71
+ sampleRate = samplingContext . parentSampled ;
72
+ transaction . tags = { ...transaction . tags , __sentry_samplingMethod : 'inheritance' } ;
73
+ } else {
74
+ sampleRate = options . tracesSampleRate ;
75
+ // cast the rate to a number first in case it's a boolean
76
+ transaction . tags = {
77
+ ...transaction . tags ,
78
+ __sentry_samplingMethod : 'client_rate' ,
79
+ __sentry_sampleRate : String ( Number ( sampleRate ) ) ,
80
+ } ;
81
+ }
76
82
77
83
// Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
78
84
// only valid values are booleans or numbers between 0 and 1.)
@@ -88,7 +94,7 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
88
94
`[Tracing] Discarding transaction because ${
89
95
typeof options . tracesSampler === 'function'
90
96
? 'tracesSampler returned 0 or false'
91
- : 'tracesSampleRate is set to 0'
97
+ : 'a negative sampling decision was inherited or tracesSampleRate is set to 0'
92
98
} `,
93
99
) ;
94
100
transaction . sampled = false ;
0 commit comments