Skip to content

Add async support to Anthropic instrumentation #4518

@JMGalvao

Description

@JMGalvao

What problem do you want to solve?

The Anthropic instrumentation package currently focuses on synchronous flows, while many production Python services call Anthropic using async patterns. This creates an observability gap in latency, error, and streaming telemetry for async workloads.
Without async instrumentation support:

  • teams do not get consistent tracing across sync and async code paths
  • async streaming lifecycle visibility is incomplete
  • users must build custom wrappers, which leads to fragmented telemetry quality

Describe the solution you'd like

Add first-class async instrumentation support in opentelemetry-instrumentation-anthropic, with behavior parity to the existing sync implementation.
Expected behavior:

  • instrument AsyncAnthropic message creation paths
  • support async streaming lifecycle with correct span start/finalization
  • preserve semantic attributes and token/usage metadata extraction where available
  • capture errors and set span status correctly in async paths
  • keep uninstrument idempotent and safe for async patches
  • keep application behavior unchanged apart from telemetry side effects

Describe alternatives you've considered

  • custom app-level wrappers around AsyncAnthropic calls: works but duplicates effort and is inconsistent
  • HTTP-only instrumentation: captures transport metrics but misses GenAI semantic context
  • maintaining private internal instrumentation: reduces reuse and increases maintenance burden

Additional Context

Scope proposal:

  • implement async wrappers and stream managers for Anthropic messages APIs
  • align attribute extraction with existing sync implementation to avoid telemetry divergence
  • include compatibility handling for SDK version differences where needed
  • follow existing contrib instrumentation conventions for patch lifecycle and configuration

This work will be co-implemented by @davidgss04 .

Would you like to implement a fix?

Yes

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.

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