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 3.

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")

Versions of telemetry-dev before 0.3.0 sent data to https://ingest.telemetry.dev by default. That hostname reaches the same service and stays supported: if a firewall allows only it, set TELEMETRY_DEV_BASE_URL to it.

Per-client wrapping

from anthropic import Anthropic
from telemetry_dev_anthropic import wrap_anthropic

client = wrap_anthropic(Anthropic())
message = client.messages.create(
    model="claude-haiku-5-5",
    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-haiku-5-5",
        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. With anthropic 2.2 or later, the loop runs over a thread that the server keeps by default, so from the second request on, the span's input has only the new messages and no tool definitions. Pass thread=False to tool_runner(...) to send, and record, the full history on each request.

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 kept up to 16 MiB, and all streams in flight share the max_stream_bytes bound of the core (64 MiB by default). These bounds need a telemetry-dev core with max_stream_bytes; with an older core, each stream keeps up to 64 KiB and 1,024 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 or caller-supplied metadata or raw attributes; redact those separately when needed. Exception messages and stack traces are recorded only when both capture_input and capture_output are on, and pass through mask. Request tools and tool_choice are part of the captured input, so capture_input=False removes them. Each tool's type and name are still recorded in gen_ai.tool.definitions, and mask does not apply to them; descriptions and input schemas are not.

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.2.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.2.6
File Size Uploaded Provenance Actions
telemetry_dev_anthropic-0.2.6.tar.gz 20.6 kB Without provenance Details for telemetry_dev_anthropic-0.2.6.tar.gz

Built distribution (wheel)

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

Total release size: 42.1 kB

Release files / telemetry_dev_anthropic-0.2.6.tar.gz

Download URL telemetry_dev_anthropic-0.2.6.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
61be001c20b25d71572c79ac2a8d78eadeb1a3de500c47b54d656ba46aa67c53
BLAKE2b-256 checksum
How to use checksums
eb76262aa6656c75ea92d5757c7162727f7096a5c60e855dfd694f023c625632
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.2.6-py3-none-any.whl

Download URL telemetry_dev_anthropic-0.2.6-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6169efb9fef7cf978d75ca243323877d81f9db7828f854abeca5a83d43db340c
BLAKE2b-256 checksum
How to use checksums
be2432139e8f5111a731f69047ff9eb84ac79ec60b8986fa203b319c4e0ac9fa
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.2.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