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.1b1.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_genai_anthropic-1.1b1.tar.gz
Algorithm Hash digest
SHA256 594d011a4410f89a819eff1df26190167545446ef175fa4d9844621eab9344ae
MD5 d4df0a26f3e63e34a655b841debe910c
BLAKE2b-256 5d7da7cee085186bdde85bc86d697ab72a579d79aff1ee59cab6313378999a66

See more details on using hashes here.

Provenance

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

Publisher: release-package.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.1b1-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_genai_anthropic-1.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 46ca53a6612daefa184ac73fcc379f61fcbadb66ca774c8b848539a33b403c6d
MD5 c0cfd0d2d8940d6de318abdb9ed92019
BLAKE2b-256 8aec4f81d6882c751c992a54ad31d80c7be5dc6ba6f22f4a45b3466cc23eae2a

See more details on using hashes here.

Provenance

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

Publisher: release-package.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.1b1 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