Registry / llm-agents / openinference-instrumentation-anthropic

openinference-instrumentation-anthropic

JSON →
library1.0.6pypypiunverified

openinference-instrumentation-anthropic is a Python auto-instrumentation library for the Anthropic package. It captures traces for Anthropic client calls (e.g., Messages, Completions, AsyncMessages, AsyncCompletions, BetaMessagesParse) and aligns them with OpenInference semantic conventions. These traces are fully OpenTelemetry compatible and can be sent to any OpenTelemetry collector, such as Arize Phoenix, for observability and evaluation. The library is currently at version 1.0.0 and is actively maintained with frequent updates to the broader OpenInference project.

pip install openinference-instrumentation-anthropic anthropic opentelemetry-sdk opentelemetry-exporter-otlp
INSTALL
IMPORT
SIG · OPENINFERENCE-INST
O
openinference-instrumentation-anthropic
llm-agentspythonv1.0.6
Install
8.4s avg
Import
633ms
Disk
76MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.6 · 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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.661s · 77.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 8.4s · import 0.604s · 75MB
76MB installed
● package 76MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AnthropicInstrumentor
from openinference.instrumentation.anthropic import AnthropicInstrumentor

This quickstart demonstrates how to instrument Anthropic API calls using `openinference-instrumentation-anthropic` and send the traces to an OpenTelemetry collector. It configures a `TracerProvider` with an OTLP HTTP exporter, instruments the Anthropic library, and then makes a sample API call. You can run a local collector like Arize Phoenix (<code>python -m phoenix.server.main serve</code>) to view the traces.

import os from anthropic import Anthropic from openinference.instrumentation.anthropic import AnthropicInstrumentor from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.sdk import trace as trace_sdk from opentelemetry.sdk.trace.export import SimpleSpanProcessor # Set your Anthropic API key (replace with actual key or use environment variable) os.environ['ANTHROPIC_API_KEY'] = os.environ.get('ANTHROPIC_API_KEY', 'your_anthropic_api_key_here') # Configure OpenTelemetry TracerProvider to send traces to an OTLP endpoint (e.g., Arize Phoenix) # Default Phoenix endpoint: http://localhost:6006/v1/traces endpoint = os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://127.0.0.1:6006/v1/traces') tracer_provider = trace_sdk.TracerProvider() tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) # Instrument the Anthropic client AnthropicInstrumentor().instrument(tracer_provider=tracer_provider) # Create an Anthropic client and make a request client = Anthropic() try: print("Making Anthropic API call...") message = client.messages.create( model="claude-3-5-sonnet-20240620", max_tokens=1000, temperature=0, messages=[ {"role": "user", "content": "Explain the concept of quantum entanglement in simple terms."} ] ) print("Anthropic Response:") print(message.content[0].text) print("Traces should now be visible in your OpenTelemetry collector (e.g., Phoenix).") except Exception as e: print(f"An error occurred: {e}") print("Ensure ANTHROPIC_API_KEY is set and your OpenTelemetry collector is running.")
Debug
Known issues
breakingFuture updates to the underlying `anthropic` SDK (e.g., new API types, changed response structures) may require corresponding updates to `openinference-instrumentation-anthropic` to maintain full compatibility and accurate tracing. Always check release notes for `anthropic` and `openinference` for potential version conflicts or required upgrades.
fix
Upgrade `openinference-instrumentation-anthropic` and `anthropic` to compatible versions as indicated in the release notes.
affects: <1.0.0 (and potentially future versions with new Anthropic SDKs)
gotchaThe `AnthropicInstrumentor().instrument(tracer_provider=tracer_provider)` call must occur *before* any Anthropic client instances are created or API calls are made to ensure proper instrumentation. If instrumentation is initialized too late, calls may not be traced.
fix
Ensure `AnthropicInstrumentor().instrument()` is called early in your application's lifecycle, typically at the start of your main script or entry point.
affects: All
gotchaIncorrectly configured OpenTelemetry exporter endpoint will result in traces not being sent or visible in your observability backend. The default for many local collectors like Phoenix is `http://127.0.0.1:6006/v1/traces`.
fix
Verify that the `endpoint` provided to `OTLPSpanExporter` matches the listening address of your OpenTelemetry collector or observability platform.
affects: All
Upgrade
Version history
1.0.6latest on PyPI · released Jun 2, 2026
Audit
Dependencies
anthropicrequiredRequired for making calls to the Anthropic API that this library instruments.
opentelemetry-sdkrequiredCore OpenTelemetry SDK for creating and managing traces.
opentelemetry-exporter-otlprequiredRequired to export OpenTelemetry traces to an OTLP-compatible collector (e.g., Arize Phoenix).
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
2
Resources
openinference-instrumentation-anthropic — pip install openinference-instrumentation-anthropic · libregistry