This release is a pre-release and may not be stable for production use.
OpenTelemetry Anthropic Instrumentation
This library allows tracing LLM requests made by the Anthropic Python SDK.
Installation
pip install opentelemetry-instrumentation-genai-anthropic
If you don’t have an Anthropic application yet, try our examples which only need a valid Anthropic API key.
Check out the zero-code example for a quick start.
Usage
This section describes how to set up Anthropic instrumentation if you’re setting OpenTelemetry up manually. Check out the manual example for more details.
from opentelemetry.instrumentation.genai.anthropic import AnthropicInstrumentor
import anthropic
# Instrument Anthropic
AnthropicInstrumentor().instrument()
# Use Anthropic client as normal
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
Supported Operations
The instrumentation supports synchronous and asynchronous calls for:
messages.create, messages.stream, and messages.parse
beta.messages.create, beta.messages.stream, and beta.messages.parse
Raw and streaming response helpers (with_raw_response and with_streaming_response)
Configuration
Anthropic SDK built-in tracing
anthropic 2.x and newer ships its own OpenTelemetry tracing, enabled by default. Using it together with this instrumentation produces duplicate spans for each call.
On anthropic 2.x, prefer the SDK’s built-in tracing and uninstall this package:
pip uninstall opentelemetry-instrumentation-genai-anthropic
If the package is installed as a dependency of something else, disable it with OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=anthropic instead.
The built-in tracing doesn’t emit metrics, log events and doesn’t support upload hooks. To keep this instrumentation instead, disable the Anthropic SDK tracing by setting ANTHROPIC_OPEN_TELEMETRY=false or passing open_telemetry=False to the client:
client = Anthropic(open_telemetry=False)
Capture Message Content
By default, prompts and completions are not captured. To capture message content, set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to one of NO_CONTENT, SPAN_ONLY, EVENT_ONLY, or SPAN_AND_EVENT:
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT
Uploading prompts and completions
Instead of recording message content inline, prompts and completions can be uploaded to external storage via a completion hook. To enable the built-in upload hook, set:
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK=upload
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH to an fsspec-compatible URI/path (e.g. /path/to/prompts or gs://my_bucket), and install the upload extra (pip install opentelemetry-util-genai[upload]).
A custom CompletionHook can also be passed programmatically, taking precedence over the environment variable:
AnthropicInstrumentor().instrument(completion_hook=my_hook)
References
Metadata
Release files for opentelemetry-instrumentation-genai-anthropic 1.3b0
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 |
|---|---|---|---|---|
| opentelemetry_instrumentation_genai_anthropic-1.3b0.tar.gz | 100.9 kB | With provenance | Details for opentelemetry_instrumentation_genai_anthropic-1.3b0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opentelemetry_instrumentation_genai_anthropic-1.3b0-py3-none-any.whl | Python 3 | none | any | Details for opentelemetry_instrumentation_genai_anthropic-1.3b0-py3-none-any.whl |
Total release size: 131.0 kB
Release files / opentelemetry_instrumentation_genai_anthropic-1.3b0.tar.gz
| Download URL | opentelemetry_instrumentation_genai_anthropic-1.3b0.tar.gz |
|---|---|
| Size | 100.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0581962ba8c79aa317a7d8d23d899de31888465c14e391ab2c5923c512df348e
|
|
BLAKE2b-256 checksum How to use checksums |
ca55982325b67d2b5d4bf064137987d6dee5fd7a719a7e3130be7b9881a1a945
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logRelease files / opentelemetry_instrumentation_genai_anthropic-1.3b0-py3-none-any.whl
| Download URL | opentelemetry_instrumentation_genai_anthropic-1.3b0-py3-none-any.whl |
|---|---|
| Size | 30.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6764d772f2c38015f69f5643e3a57e452a3bebae5088977baf402501f7c89f02
|
|
BLAKE2b-256 checksum How to use checksums |
7c0c702a6f05d3472bcae65916f2bfa4f5871120a45ecb375eff2b8e6c5db0f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logSecurity for opentelemetry-instrumentation-genai-anthropic 1.3b0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for opentelemetry_instrumentation_genai_anthropic-1.3b0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logA 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.