Registry /
observability / opentelemetry-instrumentation-anthropic
Install & Compatibility
Where this runs
tested against v0.62.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 2.922s · 82.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 8.8s · import 2.602s · 79MB
80MB installed
● package 80MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AnthropicInstrumentor
✓ from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
This quickstart demonstrates how to set up OpenTelemetry with the Anthropic instrumentation, configure an OTLP HTTP exporter, and make a traced Anthropic API call. Ensure `ANTHROPIC_API_KEY` is set in your environment. An OpenTelemetry Collector or compatible backend should be running to receive traces.
import os
from anthropic import Anthropic
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
# --- OpenTelemetry Setup ---
# 1. Configure the OpenTelemetry TracerProvider
resource = Resource.create({"service.name": "anthropic-llm-app"})
provider = TracerProvider(resource=resource)
trace.set_tracer_provider(provider)
# 2. Configure an OTLP exporter to send traces (e.g., to an OTLP collector or a service like SigNoz/Arize)
# Default OTLP HTTP endpoint is http://localhost:4318/v1/traces
otlp_exporter = OTLPSpanExporter()
span_processor = BatchSpanProcessor(otlp_exporter)
provider.add_span_processor(span_processor)
# 3. Instrument the Anthropic library
AnthropicInstrumentor().instrument()
# --- Anthropic API Call ---
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY", "YOUR_ANTHROPIC_API_KEY")
if ANTHROPIC_API_KEY == "YOUR_ANTHROPIC_API_KEY":
print("WARNING: ANTHROPIC_API_KEY not set or placeholder. API calls will fail without a valid key.")
else:
try:
client = Anthropic(api_key=ANTHROPIC_API_KEY)
print("Making an Anthropic API call...")
response = client.messages.create(
model="claude-3-opus-20240229", # Or another suitable model
max_tokens=100,
messages=[
{"role": "user", "content": "Explain the concept of quantum entanglement in a sentence."}
],
)
print("Anthropic API call successful.")
print(f"Response: {response.content[0].text[:50]}...")
except Exception as e:
print(f"Error during Anthropic API call: {e}")
# Ensure all spans are exported before the application exits
provider.force_flush()
opentelemetry-instrument --version
Debug
Known issues
breakingBreaking changes were introduced in version 0.54.0 to conform to the OpenTelemetry Generative AI Semantic Conventions (GenAI SemConv). This may alter span attribute names and structure.fixReview the OpenTelemetry GenAI Semantic Conventions documentation for the updated attribute naming and structure. Your observability backend might require updates to dashboards or alerts.
affects: >=0.54.0
gotchaBy default, this instrumentation logs the full content of prompts, completions, and embeddings to span attributes. This data may contain sensitive information.fixTo disable logging of sensitive content, set the environment variable `TRACELOOP_TRACE_CONTENT` to `false`.
affects: All versions
gotchaWhen using `client.messages.stream()` with base64 encoded images, particularly with Langfuse, input token counts might be inflated in traces.fixThis is a known upstream issue (traceloop/openllmetry#3949). Monitor the project's GitHub for a fix. Consider alternative methods for calculating token usage or use non-streaming calls if accurate token counts are critical for images.
affects: Reported in 0.57.0 (likely affects similar versions)
gotchaInstrumentation itself only creates spans. An OpenTelemetry SDK (TracerProvider, SpanProcessor, Exporter) must be explicitly configured to process and send telemetry data to a backend.fixAlways initialize a `TracerProvider`, add at least one `SpanProcessor` (e.g., `BatchSpanProcessor`), and configure an appropriate `SpanExporter` (e.g., `OTLPSpanExporter`) before calling `instrument()` on the Anthropic instrumentor.
affects: All versions
Upgrade
Version history
0.62.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
anthropicrequiredRequired for interacting with the Anthropic API.
opentelemetry-apirequiredCore OpenTelemetry API for defining telemetry.
opentelemetry-sdkrequiredOpenTelemetry SDK for trace provider and span processors.
opentelemetry-semantic-conventions-airequiredProvides Generative AI semantic conventions for LLM tracing.