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")
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-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 asyncclient.messages.parse(...), sync and asyncclient.beta.messages.create(...),stream(...), andparse(...), sync and asyncclient.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 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. Older telemetry-dev
versions record them regardless of capture flags. 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_responsesnapshots 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| telemetry_dev_anthropic-0.2.1.tar.gz | 17.2 kB | Without provenance | Details for telemetry_dev_anthropic-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| telemetry_dev_anthropic-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for telemetry_dev_anthropic-0.2.1-py3-none-any.whl |
Total release size: 35.3 kB
Release files / telemetry_dev_anthropic-0.2.1.tar.gz
| Download URL | telemetry_dev_anthropic-0.2.1.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d8c55236c7c35cfba4228c55eeb90d1eb4911750a98759ad9d22e04840aa02a
|
|
BLAKE2b-256 checksum How to use checksums |
880f7df3d45c281ff3c6787914738340db9af8eed2857bf27ce48f2f7d8590ca
|
| 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.1-py3-none-any.whl
| Download URL | telemetry_dev_anthropic-0.2.1-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3726e87f0cedf188388f164c7f49422cfa9c67d9212049d4adf02ad7e990a9a8
|
|
BLAKE2b-256 checksum How to use checksums |
77a193171b1b459182b06cb88a07ec418464ecf596bfce121ae62c1c2f506a6e
|
| 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.1
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.