You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(langchain): _create_llm_span() overwrites SpanHolder causing potential context token loss #3956
In packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py, the _create_llm_span() method overwrites an existing SpanHolder entry in the span registry without first detaching the context tokens stored in the previous holder. This is pre-existing behavior that predates PR #3807.
Problem
When _create_llm_span() is called for a run ID that already has a SpanHolder in the registry, it replaces that entry directly. The old holder's token (and now association_properties_token introduced in #3807) are lost without being detached, which could silently corrupt the OpenTelemetry context stack in certain execution flows.
Before overwriting a SpanHolder entry in _create_llm_span(), check if an existing holder is present and detach its context tokens (token and association_properties_token) before replacing it.
Fixed in main via #3958 (commit 976eef3) — _create_llm_span() now detaches the context token before overwriting the SpanHolder. Closing. Thanks for the report!
Activity
dvirski commentedon May 19, 2026
Fixed in main via #3958 (commit 976eef3) — _create_llm_span() now detaches the context token before overwriting the SpanHolder. Closing. Thanks for the report!