Skip to content

fix: avoid OpenTelemetry context detach errors in mock runtimes#74

Merged
cristipufu merged 1 commit intomainfrom
fix/otel-context-detach-in-mock-runtimes
Feb 17, 2026
Merged

fix: avoid OpenTelemetry context detach errors in mock runtimes#74
cristipufu merged 1 commit intomainfrom
fix/otel-context-detach-in-mock-runtimes

Conversation

@cristipufu
Copy link
Member

Summary

  • Replace start_as_current_span() with start_span() + try/finally: span.end() for spans that wrap yield statements in async generators across all 6 mock runtime files
  • Fixes opentelemetry.context: Failed to detach context errors caused by GeneratorExit being raised at yield points inside span context managers, where the context detach runs in a different asyncio context than the original attach

Test plan

  • Run dev console and interact with each mock runtime (support, movies, telemetry, pharma, invoice, template)
  • Verify no Failed to detach context errors in logs
  • Verify telemetry spans still appear correctly

🤖 Generated with Claude Code

…generators

Replace start_as_current_span() with start_span() + try/finally for spans
that wrap yield statements in async generators. The context manager variant
attaches/detaches context tokens, which fails when GeneratorExit is raised
at a yield point (e.g. client disconnect) because the detach happens in a
different asyncio context than the original attach.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cristipufu cristipufu merged commit 47f08b8 into main Feb 17, 2026
11 checks passed
@cristipufu cristipufu deleted the fix/otel-context-detach-in-mock-runtimes branch February 17, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments