Skip to content

Conversation

@vasantteja
Copy link

@vasantteja vasantteja commented Feb 2, 2026

Summary

  • Added OpenTelemetry tracing + metrics across the SDK with consistent span naming (claude_agent_sdk.<layer>.<operation>), plus new top‑level lifecycle spans for ClaudeSDKClient and one‑shot
    query() usage.
  • Implemented CLI tool-use span interception, richer MCP attributes, and permissions/hook tracing.
  • Centralized telemetry helpers, SpanKind utilities, and metrics initialization; improved cleanup error visibility; fixed async span context manager bug.
  • Added comprehensive telemetry tests and documented span/metric names in README.
  • closes Add OpenTelemetry Tracing Support #452

Spans Added/Updated

  • Client: claude_agent_sdk.client.connect, claude_agent_sdk.client.query, claude_agent_sdk.client.disconnect
  • Query: claude_agent_sdk.query.lifecycle, claude_agent_sdk.query.initialize, claude_agent_sdk.query.read_messages, claude_agent_sdk.query.stream_input, claude_agent_sdk.query.close
  • Transport: claude_agent_sdk.transport.connect, claude_agent_sdk.transport.read_messages, claude_agent_sdk.transport.write, claude_agent_sdk.transport.close
  • Permissions/Hooks: claude_agent_sdk.permission.can_use_tool, claude_agent_sdk.hooks.callback
  • MCP: claude_agent_sdk.mcp.request, claude_agent_sdk.mcp.tool_call
  • CLI Tools: claude_agent_sdk.cli.tool_call

Metrics Added

  • messages, results, errors, invocations
  • tokens.prompt, tokens.completion, tokens.total
  • model.latency_ms, model.errors
  • result.duration_ms, result.cost_usd, cost.total_usd
  • response.size_bytes, throttled
  • Most metrics include session.id for grouping.

- Introduced optional telemetry configuration in `pyproject.toml` for OpenTelemetry dependencies.
- Added `TelemetryOptions` class to manage telemetry settings.
- Integrated telemetry into the `ClaudeSDKClient`, `Query`, and `SubprocessCLITransport` classes for tracing and metrics.
- Updated README with instructions for enabling telemetry and examples of span names and metrics emitted.
- Added tests for telemetry utilities to ensure proper functionality.

This enhancement allows users to monitor and trace SDK operations, improving observability and debugging capabilities.
- Updated Dockerfile and GitHub Actions workflow to install SDK with telemetry dependencies.
- Modified README to clarify installation instructions and added details about telemetry tests.
- Introduced new end-to-end tests for telemetry integration, verifying metrics and tracing functionality.
- Adjusted `conftest.py` to improve test marker documentation.

These changes improve the observability of SDK operations and ensure proper testing of telemetry features.
@vasantteja
Copy link
Author

@ashwin-ant @dicksontsai Can you please take a look at this?

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