Skip to main content
Pre-release

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

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

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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file opentelemetry_instrumentation_genai_anthropic-1.1b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_genai_anthropic-1.1b0.tar.gz
Algorithm Hash digest
SHA256 193caed02a8243fca359545e388fd46768fafbcc89878f6151de8b13f0e6317c
MD5 92c5a0a97aa0a1c75f6b5af0874d1402
BLAKE2b-256 e9d63e3bd0e9728c7b73dbdb810085526528455df565fb4bcd16762224fdcc4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_genai_anthropic-1.1b0.tar.gz:

Publisher: release-all.yml on open-telemetry/opentelemetry-python-genai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opentelemetry_instrumentation_genai_anthropic-1.1b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_genai_anthropic-1.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0e5f3bac164b37658dac60582e8c0f9ea9729097415f4bf6aed8e517b6a901
MD5 54e3580ed92aecbd43dd72651d3b87ab
BLAKE2b-256 d5ea5663495a6d4bcfb4e02f319f28548dddad1d7ea350594b9c277310b7ec07

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_genai_anthropic-1.1b0-py3-none-any.whl:

Publisher: release-all.yml on open-telemetry/opentelemetry-python-genai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.1b0 This release

2 files

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