opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

Add OpenTelemetry Instrumentation for the Claude Agent SDK

Open vasantteja opened this issue 1 month ago • 7 comments

What problem do you want to solve?

Add OpenTelemetry instrumentation for the Anthropic Claude Agent SDK (claude-agent-sdk package) to support tracing of agent operations, tool executions, and MCP server interactions, following the GenAI Agent Semantic Conventions.

Describe the solution you'd like

Create a new instrumentation package opentelemetry-instrumentation-anthrophic-agents (or similar naming) that:

Core Instrumentation

  • Instruments agent query operations (query() and ClaudeSDKClient.query())
  • Creates invoke_agent spans for agent invocations following GenAI agent span conventions.
  • Creates execute_tool spans for each tool execution (Read, Write, Bash, Edit, etc.)
  • Instruments custom MCP server tool calls created via @tool decorator and create_sdk_mcp_server()
  • Captures hook executions (PreToolUse, PostToolUse, etc.) as span events or child spans.

Edit 1: I am working with agent-sdk maintainers to see if they can support trace and span creation. I will update the plan accordingly once I hear back from them.

Describe alternatives you've considered

No response

Additional Context

  • Follow the structure of opentelemetry-instrumentation-openai-v2
  • Use gen_ai.provider.name = "anthropic" (already in OTel well-known values)
  • Map ClaudeAgentOptions fields to appropriate gen_ai.* attributes
  • Handle AssistantMessage, UserMessage, ResultMessage, SystemMessage types
  • Extract ToolUseBlock and ToolResultBlock for tool span creation

Would you like to implement a fix?

Yes

References

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

vasantteja avatar Dec 30 '25 15:12 vasantteja