Skip to main content

telemetry-dev-anthropic

Anthropic Claude SDK instrumentation for telemetry.dev. It wraps the official anthropic Python SDK and emits telemetry.dev generation spans through telemetry-dev.

Install

pip install telemetry-dev-anthropic

Initialize the core SDK first:

import telemetry_dev

telemetry_dev.init(
    api_key="td_live_...",
    service_name="my-service",
)

Per-client wrapping

from anthropic import Anthropic
from telemetry_dev_anthropic import wrap_anthropic

client = wrap_anthropic(Anthropic())
message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Tell me a joke about OpenTelemetry"}],
)

wrap_anthropic also supports AsyncAnthropic and the provider clients AnthropicBedrock, AnthropicBedrockMantle, AnthropicVertex, AnthropicAWS, and AnthropicFoundry, with their Async variants.

Global instrumentation

from anthropic import Anthropic
from telemetry_dev_anthropic import instrument_anthropic, uninstrument_anthropic

instrument_anthropic()
try:
    client = Anthropic()
    client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello"}],
    )
finally:
    uninstrument_anthropic()

Instrumented surfaces

  • client.messages.create(...)
  • client.messages.create(..., stream=True)
  • client.messages.stream(...) context managers, sync and async
  • client.messages.parse(...), sync and async
  • client.beta.messages.create(...), stream(...), and parse(...), sync and async
  • client.beta.messages.tool_runner(...): each model request in the tool loop records its own generation span

The integration maps native Anthropic request and response shapes directly into telemetry.dev fields. It does not normalize messages into another schema.

Streaming

Native Anthropic stream events pass through unmodified. The span records time to first chunk on the first received event, merges usage from message_start and message_delta, aggregates text, tool-use JSON, and thinking blocks, and ends on stream exhaustion, close, context-manager exit, or error.

messages.stream() starts the span when the context manager is entered, because that is when the Anthropic SDK opens the HTTP stream.

Provider clients

Class instrumentation covers the provider clients. Their messages resources reuse the stable Messages and AsyncMessages classes. The Bedrock and Vertex beta.messages resources are separate provider classes, which are patched too: Bedrock exposes create() and Vertex exposes create() and stream(). Provider attribution comes from the client class, including subclasses: aws.bedrock for AnthropicBedrock and AnthropicBedrockMantle, and gcp.vertex_ai for AnthropicVertex. AnthropicAWS (Claude Platform on AWS) and AnthropicFoundry (Microsoft Foundry) serve the Anthropic API, so they are recorded as anthropic.

Limitations

  • messages.count_tokens(), beta.messages.count_tokens(), and batches are not instrumented.
  • with_raw_response snapshots bound methods; wrap or instrument clients before creating raw-response wrappers.
  • Unconsumed streams end spans only on exhaustion, close, context-manager exit, or error.

Metadata

Release files for telemetry-dev-anthropic 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telemetry-dev-anthropic 0.1.3
File Size Uploaded
telemetry_dev_anthropic-0.1.3.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telemetry-dev-anthropic 0.1.3
File Interpreter ABI Platform
telemetry_dev_anthropic-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.8 kB

Release files / telemetry_dev_anthropic-0.1.3.tar.gz

Download URL telemetry_dev_anthropic-0.1.3.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2037228c7f5a8cea90cdb8e5d6c98e80a756f8a4b1e92f5d775aa077589a6971
BLAKE2b-256 checksum
How to use checksums
680f6a89d663d617bc5762a103e4859d13970ff33940c558e26b44917f9c0ea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / telemetry_dev_anthropic-0.1.3-py3-none-any.whl

Download URL telemetry_dev_anthropic-0.1.3-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e76f7339cab2308fd6cbcca8c3e3b0ba08f6776007c9bf104f25048e58c9894
BLAKE2b-256 checksum
How to use checksums
edfd93a52f3f8a990d8e743a2792abb6cb520503311c89256d5645d04a348fa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.4

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page