Skip to content

Add OpenTelemetry instrumentation for the Anthropic Claude Python SDK #3949

@vasantteja

Description

@vasantteja

What problem do you want to solve?

Add OpenTelemetry instrumentation for the Anthropic Claude Python SDK (anthropic package) to support tracing of Messages API calls, following the same pattern as the existing OpenAI instrumentation.

Describe the solution you'd like

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

  1. Instruments the Anthropic Messages API (anthropic.messages.create())
  2. Captures request/response attributes following GenAI semantic conventions
  3. Emits log events for messages (with opt-in content capture)
  4. Records metrics for operation duration and token usage
  5. Supports both sync and async operations
  6. Handles streaming responses

Describe alternatives you've considered

No response

Additional Context

  1. Follow the same structure as opentelemetry-instrumentation-openai-v2
  2. Use gen_ai.system = "anthropic"
  3. Map Anthropic's stop_reason (single value) to gen_ai.response.finish_reasons (array format)
  4. Handle Anthropic's content block structure (array of content blocks vs OpenAI's string/array)
  5. Support opt-in content capture via OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT

Would you like to implement a fix?

Yes

Tip

References

  1. https://docs.claude.com/en/api/messages

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions