Skip to content

Bug: OTEL "Failed to detach context" warning during orchestrator runs #102

@Abernaughty

Description

@Abernaughty

Description

The Langfuse OTEL SDK (v4) logs Failed to detach context errors during orchestrator runs. This occurs when OpenTelemetry span context tokens are created in one async context and reset in another — a mismatch caused by LangGraph's node execution model.

Log Output

Failed to detach context
Traceback (most recent call last):
  File "...\opentelemetry\context\__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "...\opentelemetry\context\contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token ...> was created in a different Context

Observed on every task run — appears once per run, consistently during the QA or flush_memory phase.

Impact

  • Cosmetic only — traces still record correctly in Langfuse (confirmed via trace JSON export)
  • Clutters FastAPI logs and may mask real errors
  • No data loss or functional impact

Possible Fixes

  1. Suppress the warning — catch ValueError on context detach and log at DEBUG level
  2. Langfuse SDK config — check if there's an OTEL context propagation setting for async frameworks
  3. Upstream fix — may be resolved in a future opentelemetry-sdk or langfuse release

Related

Also see: Unknown observation type: event, falling back to span (filed as separate issue) — both are Langfuse/OTEL integration noise.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions