Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

OpenTelemetry Anthropic Instrumentation

pypi

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!"}
    ]
)

Configuration

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

Release files for opentelemetry-instrumentation-genai-anthropic 1.2b0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opentelemetry-instrumentation-genai-anthropic 1.2b0
File Size Uploaded
opentelemetry_instrumentation_genai_anthropic-1.2b0.tar.gz 84.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opentelemetry-instrumentation-genai-anthropic 1.2b0
File Interpreter ABI Platform
opentelemetry_instrumentation_genai_anthropic-1.2b0-py3-none-any.whl Python 3 none any Details

Total release size: 111.5 kB

Release files / opentelemetry_instrumentation_genai_anthropic-1.2b0.tar.gz

Download URL opentelemetry_instrumentation_genai_anthropic-1.2b0.tar.gz
Size 84.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b031fbda4dff59bd2c234707614d7579833ca7676dd8d65a6f70ba1ef87ad6d1
BLAKE2b-256 checksum
How to use checksums
3cb738c44a555860bbdd15f13ca84a029d30e8d0648946de43db8b125a928c5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 24, 2026.

Transparency log

Release files / opentelemetry_instrumentation_genai_anthropic-1.2b0-py3-none-any.whl

Download URL opentelemetry_instrumentation_genai_anthropic-1.2b0-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
901da681a0041036cde0d06548b756b4add0d441e8412988cb6ad163787cdfa3
BLAKE2b-256 checksum
How to use checksums
b41dfa8b77244443aa689c507f646f39455fb52adb02008602713f46c27dc37e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 24, 2026.

Transparency log
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