File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -229,16 +229,18 @@ def __call__(
229229 run_manager = kwargs .get ("run_manager" )
230230 if run_manager :
231231 run_id = run_manager .run_id
232- span_holder = self ._callback_manager .spans [run_id ]
233-
234- extra_headers = kwargs .get ("extra_headers" , {})
235-
236- # Inject tracing context into the extra headers
237- ctx = set_span_in_context (span_holder .span )
238- TraceContextTextMapPropagator ().inject (extra_headers , context = ctx )
239-
240- # Update kwargs to include the modified headers
241- kwargs ["extra_headers" ] = extra_headers
232+ span_holder = self ._callback_manager .spans .get (run_id )
233+
234+ if span_holder :
235+ extra_headers = kwargs .get ("extra_headers" , {})
236+ ctx = set_span_in_context (span_holder .span )
237+ TraceContextTextMapPropagator ().inject (extra_headers , context = ctx )
238+ kwargs ["extra_headers" ] = extra_headers
239+ else :
240+ logger .debug (
241+ "No span found for run_id %s, skipping header injection" ,
242+ run_id
243+ )
242244
243245 # In legacy chains like LLMChain, suppressing model instrumentations
244246 # within create_llm_span doesn't work, so this should helps as a fallback
You can’t perform that action at this time.
0 commit comments