@@ -100,9 +100,14 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, sampleContext:
100100 *
101101 * @returns The default sample context
102102 */
103- function getDefaultSampleContext ( ) : SampleContext {
103+ function getDefaultSampleContext < T extends Transaction > ( transaction : T ) : SampleContext {
104104 const defaultSampleContext : SampleContext = { } ;
105105
106+ // include parent's sampling decision, if there is one
107+ if ( transaction . parentSpanId && transaction . sampled !== undefined ) {
108+ defaultSampleContext . parentSampled = transaction . sampled ;
109+ }
110+
106111 if ( isNodeEnv ( ) ) {
107112 const domain = getActiveDomain ( ) ;
108113
@@ -177,7 +182,7 @@ function _startTransaction(
177182 customSampleContext ?: CustomSampleContext ,
178183) : Transaction {
179184 const transaction = new Transaction ( context , this ) ;
180- return sample ( this , transaction , { ...getDefaultSampleContext ( ) , ...customSampleContext } ) ;
185+ return sample ( this , transaction , { ...getDefaultSampleContext ( transaction ) , ...customSampleContext } ) ;
181186}
182187
183188/**
@@ -190,7 +195,7 @@ export function startIdleTransaction(
190195 onScope ?: boolean ,
191196) : IdleTransaction {
192197 const transaction = new IdleTransaction ( context , hub , idleTimeout , onScope ) ;
193- return sample ( hub , transaction , getDefaultSampleContext ( ) ) ;
198+ return sample ( hub , transaction , getDefaultSampleContext ( transaction ) ) ;
194199}
195200
196201/**
0 commit comments