Anthropic integration for telemetry.dev Python SDK
Project description
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, AnthropicBedrock, AsyncAnthropicBedrock, AnthropicVertex, and AsyncAnthropicVertex clients.
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
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.
Bedrock and Vertex
Class instrumentation covers Bedrock and Vertex clients because the Anthropic SDK reuses the same Messages and AsyncMessages resource classes. Provider attribution is recorded as aws.bedrock or gcp.vertex_ai when the client class identifies those runtimes.
Limitations
client.beta.messagesis not instrumented.messages.parse()andmessages.count_tokens()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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telemetry_dev_anthropic-0.1.0.tar.gz.
File metadata
- Download URL: telemetry_dev_anthropic-0.1.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80e2c3c48ae640fc7381af23a01877b7efa2fb7e354be2e6d6892fb3d047a3d1
|
|
| MD5 |
2e4df6b06eae5ab6ad43283bc38ffe68
|
|
| BLAKE2b-256 |
c97d5b570c10e419297a2613ca1b83d5564527c545deaf41d4ededed6440d361
|
File details
Details for the file telemetry_dev_anthropic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: telemetry_dev_anthropic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f2afb2d1547bfc78b0f19beaff86a08ae9cc5ec0f044b299a2fa27c920c35a4
|
|
| MD5 |
42db8648859f39baae00d6444f45ccd7
|
|
| BLAKE2b-256 |
427f7b5876bd63031adfabd6a4b4afbfaf61cd18af94cb2a3cba7693aee8c628
|