@@ -29,15 +29,15 @@ function traceHeaders(this: Hub): { [key: string]: string } {
2929}
3030
3131/**
32- * Implements sampling inheritance and falls back to user-provided static rate if no parent decision is available .
32+ * Uses existing sampling decision if available; falls back to user-provided static rate.
3333 *
34- * @param parentSampled : The parent transaction's sampling decision, if any.
34+ * @param existingDecision : The transaction's existing sampling decision, if any (likely inherited) .
3535 * @param givenRate: The rate to use if no parental decision is available.
3636 *
37- * @returns The parent's sampling decision (if one exists), or the provided static rate
37+ * @returns The existing sampling decision (if one exists), or the provided static rate
3838 */
39- function _inheritOrUseGivenRate ( parentSampled : boolean | undefined , givenRate : unknown ) : boolean | unknown {
40- return parentSampled !== undefined ? parentSampled : givenRate ;
39+ function _useExistingDecisionOrGivenRate ( existingDecision : boolean | undefined , givenRate : unknown ) : boolean | unknown {
40+ return existingDecision !== undefined ? existingDecision : givenRate ;
4141}
4242
4343/**
@@ -52,7 +52,7 @@ function _inheritOrUseGivenRate(parentSampled: boolean | undefined, givenRate: u
5252 *
5353 * @returns The given transaction with its `sampled` value set
5454 */
55- function sample < T extends Transaction > ( hub : Hub , transaction : T , samplingContext : SamplingContext = { } ) : T {
55+ function sample < T extends Transaction > ( hub : Hub , transaction : T , samplingContext : SamplingContext ) : T {
5656 const client = hub . getClient ( ) ;
5757 const options = ( client && client . getOptions ( ) ) || { } ;
5858
@@ -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- : _inheritOrUseGivenRate ( samplingContext . parentSampled , options . tracesSampleRate ) ;
70+ : _useExistingDecisionOrGivenRate ( samplingContext . transactionContext . sampled , 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.)
@@ -116,13 +116,8 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
116116 *
117117 * @returns The default sample context
118118 */
119- function getDefaultSamplingContext < T extends Transaction > ( transaction : T ) : SamplingContext {
120- const defaultSamplingContext : SamplingContext = { } ;
121-
122- // include parent's sampling decision, if there is one
123- if ( transaction . parentSpanId && transaction . sampled !== undefined ) {
124- defaultSamplingContext . parentSampled = transaction . sampled ;
125- }
119+ function getDefaultSamplingContext ( transactionContext : TransactionContext ) : SamplingContext {
120+ const defaultSamplingContext : SamplingContext = { transactionContext } ;
126121
127122 if ( isNodeEnv ( ) ) {
128123 const domain = getActiveDomain ( ) ;
@@ -196,24 +191,27 @@ function isValidSampleRate(rate: unknown): boolean {
196191 */
197192function _startTransaction (
198193 this : Hub ,
199- context : TransactionContext ,
194+ transactionContext : TransactionContext ,
200195 customSamplingContext ?: CustomSamplingContext ,
201196) : Transaction {
202- const transaction = new Transaction ( context , this ) ;
203- return sample ( this , transaction , { ...getDefaultSamplingContext ( transaction ) , ...customSamplingContext } ) ;
197+ const transaction = new Transaction ( transactionContext , this ) ;
198+ return sample ( this , transaction , {
199+ ...getDefaultSamplingContext ( transactionContext ) ,
200+ ...customSamplingContext ,
201+ } ) ;
204202}
205203
206204/**
207205 * Create new idle transaction.
208206 */
209207export function startIdleTransaction (
210208 hub : Hub ,
211- context : TransactionContext ,
209+ transactionContext : TransactionContext ,
212210 idleTimeout ?: number ,
213211 onScope ?: boolean ,
214212) : IdleTransaction {
215- const transaction = new IdleTransaction ( context , hub , idleTimeout , onScope ) ;
216- return sample ( hub , transaction , getDefaultSamplingContext ( transaction ) ) ;
213+ const transaction = new IdleTransaction ( transactionContext , hub , idleTimeout , onScope ) ;
214+ return sample ( hub , transaction , getDefaultSamplingContext ( transactionContext ) ) ;
217215}
218216
219217/**
0 commit comments