@@ -1132,13 +1132,14 @@ def _get_sampled_injection_context(
11321132 If sampling_priority is already set, returns immediately. Otherwise, finds the
11331133 appropriate span and triggers sampling before returning the injection context.
11341134 """
1135+ core_tracer = core .root .get_item ("tracer" )
11351136 # Extract context for header injection (non_active_span takes precedence)
11361137 injection_context = trace_info .context if isinstance (trace_info , Span ) else trace_info
11371138
11381139 # Find root span for sampling decisions
11391140 if injection_context .sampling_priority is not None :
11401141 return injection_context
1141- elif core . tracer is None :
1142+ elif core_tracer is None :
11421143 # This should never happen, tracer should be initialized before headers can be injected.
11431144 log .error (
11441145 "No tracer found and injection context %s has no sampling priority, skipping sampling" ,
@@ -1153,13 +1154,13 @@ def _get_sampled_injection_context(
11531154 elif isinstance (trace_info , Span ):
11541155 # Use span's root for sampling
11551156 sampling_span = trace_info ._local_root
1156- elif (current_root := core . tracer .current_root_span ()) and current_root .trace_id == trace_info .trace_id :
1157+ elif (current_root := core_tracer .current_root_span ()) and current_root .trace_id == trace_info .trace_id :
11571158 # Get the local root span for the current trace (if it is active, otherwise we can't sample)
11581159 sampling_span = current_root
11591160
11601161 # Sample the local root span before injecting headers.
11611162 if sampling_span :
1162- core . tracer .sample (sampling_span )
1163+ core_tracer .sample (sampling_span )
11631164 log .debug ("%s sampled before propagating trace: span_context=%s" , sampling_span , injection_context )
11641165
11651166 return injection_context
0 commit comments