@@ -29,15 +29,15 @@ function traceHeaders(this: Hub): { [key: string]: string } {
29
29
}
30
30
31
31
/**
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.
33
33
*
34
- * @param parentSampled : The parent transaction's sampling decision, if any.
34
+ * @param existingDecision : The transaction's existing sampling decision, if any (likely inherited) .
35
35
* @param givenRate: The rate to use if no parental decision is available.
36
36
*
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
38
38
*/
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 ;
41
41
}
42
42
43
43
/**
@@ -52,7 +52,7 @@ function _inheritOrUseGivenRate(parentSampled: boolean | undefined, givenRate: u
52
52
*
53
53
* @returns The given transaction with its `sampled` value set
54
54
*/
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 {
56
56
const client = hub . getClient ( ) ;
57
57
const options = ( client && client . getOptions ( ) ) || { } ;
58
58
@@ -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
- : _inheritOrUseGivenRate ( samplingContext . parentSampled , options . tracesSampleRate ) ;
70
+ : _useExistingDecisionOrGivenRate ( samplingContext . transactionContext . sampled , 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.)
@@ -116,13 +116,8 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
116
116
*
117
117
* @returns The default sample context
118
118
*/
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 } ;
126
121
127
122
if ( isNodeEnv ( ) ) {
128
123
const domain = getActiveDomain ( ) ;
@@ -196,24 +191,27 @@ function isValidSampleRate(rate: unknown): boolean {
196
191
*/
197
192
function _startTransaction (
198
193
this : Hub ,
199
- context : TransactionContext ,
194
+ transactionContext : TransactionContext ,
200
195
customSamplingContext ?: CustomSamplingContext ,
201
196
) : 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
+ } ) ;
204
202
}
205
203
206
204
/**
207
205
* Create new idle transaction.
208
206
*/
209
207
export function startIdleTransaction (
210
208
hub : Hub ,
211
- context : TransactionContext ,
209
+ transactionContext : TransactionContext ,
212
210
idleTimeout ?: number ,
213
211
onScope ?: boolean ,
214
212
) : 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 ) ) ;
217
215
}
218
216
219
217
/**
0 commit comments