Skip to content

feat: add opt-in OpenTelemetry tracing support - #1186

Open
SushantTusharJoshi wants to merge 1 commit into
anthropics:mainfrom
SushantTusharJoshi:feat/otel-tracing
Open

feat: add opt-in OpenTelemetry tracing support#1186
SushantTusharJoshi wants to merge 1 commit into
anthropics:mainfrom
SushantTusharJoshi:feat/otel-tracing

Conversation

@SushantTusharJoshi

Copy link
Copy Markdown

Summary

  • New tracing.py module with enable_tracing(), disable_tracing(), start_span() context manager
  • Wraps key lifecycle points: session connect/disconnect, query execution, tool calls, tool permissions
  • opentelemetry-api is a soft dependency — imported with try/except, all ops are best-effort
  • Exports enable_tracing and disable_tracing from top-level __init__.py
  • Includes Jaeger integration example in examples/otel_tracing.py

Test plan

  • 19 tests covering enable/disable, span creation, exception recording, no-ops, error tolerance, query/session span lifecycle
  • All 38 existing tests pass alongside new tests
  • Ruff lint and format clean

Closes #452

Developed with Claude Code as a coding partner

Introduce a tracing module that emits OTel spans for key SDK lifecycle
events when opentelemetry-api is installed and tracing is enabled via
enable_tracing(). Traced events include session connect/disconnect,
one-shot queries, MCP tool calls, and permission callbacks.

All tracing is best-effort -- failures are logged at DEBUG level and
never propagate to caller code. When opentelemetry-api is absent the
helpers are harmless no-ops.

Developed with Claude Code as a coding partner
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.

Add OpenTelemetry Tracing Support

1 participant