@@ -29,15 +29,15 @@ function traceHeaders(this: Hub): { [key: string]: string } {
2929}
3030
3131/**
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 .
3333 *
34- * @param existingDecision : The transaction's existing sampling decision, if any (likely inherited) .
34+ * @param parentSampled : The parent transaction's sampling decision, if any.
3535 * @param givenRate: The rate to use if no parental decision is available.
3636 *
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
3838 */
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 ;
4141}
4242
4343/**
@@ -67,7 +67,7 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
6767 const sampleRate =
6868 typeof options . tracesSampler === 'function'
6969 ? options . tracesSampler ( samplingContext )
70- : _useExistingDecisionOrGivenRate ( samplingContext . transactionContext . sampled , options . tracesSampleRate ) ;
70+ : _inheritOrUseGivenRate ( samplingContext . parentSampled , options . tracesSampleRate ) ;
7171
7272 // Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
7373 // 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
117117 * @returns The default sample context
118118 */
119119function 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 } ;
121123
122124 if ( isNodeEnv ( ) ) {
123125 const domain = getActiveDomain ( ) ;
0 commit comments