Arize Phoenix OpenTelemetry Wrapper
arize-phoenix-otel is a Python library that provides a lightweight wrapper around OpenTelemetry primitives, offering Phoenix-aware defaults and tracing decorators for common Generative AI patterns. It simplifies the setup of OpenTelemetry for sending traces to Arize Phoenix, an open-source AI observability platform. The library is actively maintained, with frequent updates released as part of the larger `arize-phoenix` monorepo, currently at version 0.15.0.
Warnings
- gotcha Critical: There are two distinct Arize products with separate Python packages: `arize-phoenix-otel` (for open-source Phoenix) and `arize-otel` (for Arize AX, a cloud product). Ensure you are using `from phoenix.otel import register` for Arize Phoenix. Using `arize.otel` will configure tracing for the wrong product.
- breaking Version 14.0.0 of the broader `arize-phoenix` ecosystem (which `arize-phoenix-otel` is part of) introduced several breaking changes. These include the removal of the `/v1/evaluations` endpoint, deprecation and removal of Evals 1.0 modules, and significant changes to the CLI and the `arize-phoenix-client` package (e.g., `px.Client()` removed, `endpoint` parameter renamed to `base_url`). While `arize-phoenix-otel` focuses on tracing, these changes can affect how users interact with the Phoenix backend.
- gotcha When configuring the OpenTelemetry collector endpoint directly, you must provide a fully qualified URL including the path. For HTTP/protobuf, this is typically `http://localhost:6006/v1/traces`, and for gRPC, it's `http://localhost:4317`. Simply providing `http://localhost:6006` or `http://localhost` may lead to incorrect endpoint resolution.
- gotcha If batch processing of spans is enabled (`batch=True` in `register()`), it's crucial to call `tracer_provider.shutdown()` before your application process exits. Failing to do so may result in queued spans not being exported to the Phoenix collector, leading to incomplete traces.
Install
-
pip install arize-phoenix-otel
Imports
- register
from phoenix.otel import register
- TracerProvider
from phoenix.otel import TracerProvider
- HTTPSpanExporter
from phoenix.otel import HTTPSpanExporter
Quickstart
import os
from phoenix.otel import register
from opentelemetry import trace
# Configure Phoenix collector endpoint and API key via environment variables
# PHOENIX_COLLECTOR_ENDPOINT defaults to http://localhost:4317 (gRPC) or http://localhost:6006/v1/traces (HTTP)
# PHOENIX_API_KEY for authentication if required by your Phoenix instance
# Example usage with explicit project name and auto-instrumentation
# For production, set PHOENIX_COLLECTOR_ENDPOINT and PHOENIX_API_KEY environment variables.
# If running locally without env vars, it defaults to localhost.
tracer_provider = register(
project_name=os.environ.get('PHOENIX_PROJECT_NAME', 'my-llm-app'),
auto_instrument=True, # Automatically instruments supported AI/ML libraries like OpenAI, LangChain
batch=True # Enable batch processing for better performance, requires shutdown call
)
# Get a tracer
tracer = trace.get_tracer(__name__)
# Example of creating a span manually (if auto_instrument=False or for custom logic)
with tracer.start_as_current_span("my-manual-operation") as span:
span.set_attribute("input", "test data")
print("Performing a traced operation...")
span.set_attribute("output", "result data")
# Important: If batch=True, ensure all spans are flushed before the process exits
tracer_provider.shutdown()