@@ -29,15 +29,15 @@ function traceHeaders(this: Hub): { [key: string]: string } {
29
29
}
30
30
31
31
/**
32
- * Uses existing sampling decision if available; falls back to user-provided static rate.
32
+ * Implements sampling inheritance and falls back to user-provided static rate if no parent decision is available .
33
33
*
34
- * @param existingDecision : The transaction's existing sampling decision, if any (likely inherited) .
34
+ * @param parentSampled : The parent transaction's sampling decision, if any.
35
35
* @param givenRate: The rate to use if no parental decision is available.
36
36
*
37
- * @returns The existing sampling decision (if one exists), or the provided static rate
37
+ * @returns The parent's sampling decision (if one exists), or the provided static rate
38
38
*/
39
- function _useExistingDecisionOrGivenRate ( existingDecision : boolean | undefined , givenRate : unknown ) : boolean | unknown {
40
- return existingDecision !== undefined ? existingDecision : givenRate ;
39
+ function _inheritOrUseGivenRate ( parentSampled : boolean | undefined , givenRate : unknown ) : boolean | unknown {
40
+ return parentSampled !== undefined ? parentSampled : givenRate ;
41
41
}
42
42
43
43
/**
@@ -67,7 +67,7 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
67
67
const sampleRate =
68
68
typeof options . tracesSampler === 'function'
69
69
? options . tracesSampler ( samplingContext )
70
- : _useExistingDecisionOrGivenRate ( samplingContext . transactionContext . sampled , options . tracesSampleRate ) ;
70
+ : _inheritOrUseGivenRate ( samplingContext . parentSampled , options . tracesSampleRate ) ;
71
71
72
72
// Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
73
73
// only valid values are booleans or numbers between 0 and 1.)
@@ -117,7 +117,9 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
117
117
* @returns The default sample context
118
118
*/
119
119
function getDefaultSamplingContext ( transactionContext : TransactionContext ) : SamplingContext {
120
- const defaultSamplingContext : SamplingContext = { transactionContext } ;
120
+ // promote parent sampling decision (if any) for easy access
121
+ const { parentSampled } = transactionContext ;
122
+ const defaultSamplingContext : SamplingContext = { transactionContext, parentSampled } ;
121
123
122
124
if ( isNodeEnv ( ) ) {
123
125
const domain = getActiveDomain ( ) ;
0 commit comments