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.

Docs: https://telemetry.dev/docs/integrations/anthropic

Install

pip install telemetry-dev-anthropic

Requires Python 3.10 or later and anthropic 0.116 or later, below 2.

Initialize the core SDK first. init() reads your project API key from the TELEMETRY_DEV_API_KEY environment variable, so set it before you start the app:

import telemetry_dev

telemetry_dev.init(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.

Reconstructed output is bounded to 48 KiB and 1,000 items. The configured max_attribute_length does not shrink these retention bounds; the core applies it to the exported attribute after the mask runs, with its ...[truncated] marker, without setting telemetry.dev.capture.truncated. A stream that ends without message_stop, encounters a mapping failure, or exceeds a capture bound sets telemetry.dev.capture.truncated. With a mask configured, incomplete output is omitted because the mask cannot inspect the complete value. When output capture is disabled, response IDs and models, finish reasons, usage, timing, and errors may still be recorded. Capture flags do not gate stop sequences, caller-supplied metadata or raw attributes, or exception messages and stack traces; redact those separately when needed. Request tools and tool_choice are part of the captured input, so capture_input=False removes them.

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.

Native Claude SDK spans

The anthropic SDK 1.14.0 and later emits OpenTelemetry spans natively when the application registers a global tracer provider. Use this package or the native spans, not the two. If you use the two, each request has two spans.

To keep this package, turn off the native spans on each client:

client = wrap_anthropic(Anthropic(open_telemetry=False))

With global instrumentation, set ANTHROPIC_OPEN_TELEMETRY=false before you make the clients. The Claude SDK reads this variable only for a client that has no open_telemetry option. For a client with this option, set open_telemetry=False.

To use the native spans instead of this package, refer to Claude SDK. The Claude API can also send server-side spans to telemetry.dev. Refer to Claude Platform.

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.

License

MIT. See LICENSE.

Metadata

Release files for telemetry-dev-anthropic 0.1.6

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.6
File Size Uploaded Provenance Actions
telemetry_dev_anthropic-0.1.6.tar.gz 16.6 kB Without provenance Details for telemetry_dev_anthropic-0.1.6.tar.gz

Built distribution (wheel)

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

Total release size: 34.1 kB

Release files / telemetry_dev_anthropic-0.1.6.tar.gz

Download URL telemetry_dev_anthropic-0.1.6.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6dfe37e0c1e20b63abcb13f9bcf7b87d75ba24179c73f3a885a5a9fdd7f1bbd1
BLAKE2b-256 checksum
How to use checksums
07e4ea802c7d88b748925d4ef224b7deb933d872a97ae8a7bb9d497616a1247c
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.6-py3-none-any.whl

Download URL telemetry_dev_anthropic-0.1.6-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
004f28cd1b73764d849d0854d3f1b849c97954e749cbfb20186a9a33c80edc98
BLAKE2b-256 checksum
How to use checksums
34b2f6d528b15e0a4a6f82ceb41efcc8ab14439ba8ebfcac9e47df4ed8191868
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}

Security for telemetry-dev-anthropic 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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