@@ -100,9 +100,14 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, sampleContext:
100
100
*
101
101
* @returns The default sample context
102
102
*/
103
- function getDefaultSampleContext ( ) : SampleContext {
103
+ function getDefaultSampleContext < T extends Transaction > ( transaction : T ) : SampleContext {
104
104
const defaultSampleContext : SampleContext = { } ;
105
105
106
+ // include parent's sampling decision, if there is one
107
+ if ( transaction . parentSpanId && transaction . sampled !== undefined ) {
108
+ defaultSampleContext . parentSampled = transaction . sampled ;
109
+ }
110
+
106
111
if ( isNodeEnv ( ) ) {
107
112
const domain = getActiveDomain ( ) ;
108
113
@@ -177,7 +182,7 @@ function _startTransaction(
177
182
customSampleContext ?: CustomSampleContext ,
178
183
) : Transaction {
179
184
const transaction = new Transaction ( context , this ) ;
180
- return sample ( this , transaction , { ...getDefaultSampleContext ( ) , ...customSampleContext } ) ;
185
+ return sample ( this , transaction , { ...getDefaultSampleContext ( transaction ) , ...customSampleContext } ) ;
181
186
}
182
187
183
188
/**
@@ -190,7 +195,7 @@ export function startIdleTransaction(
190
195
onScope ?: boolean ,
191
196
) : IdleTransaction {
192
197
const transaction = new IdleTransaction ( context , hub , idleTimeout , onScope ) ;
193
- return sample ( hub , transaction , getDefaultSampleContext ( ) ) ;
198
+ return sample ( hub , transaction , getDefaultSampleContext ( transaction ) ) ;
194
199
}
195
200
196
201
/**
0 commit comments