Skip to main content

PyPI Version

Provides a lightweight wrapper around OpenTelemetry primitives with Phoenix-aware defaults. Also includes tracing decorators for common GenAI patterns.

Installation#

Note

Starting in 0.16.0, phoenix.otel re-exports the OpenInference context managers and semantic conventions, so manual instrumentation no longer requires separately installing openinference-instrumentation or openinference-semantic-conventions. On older versions, import them from openinference.instrumentation and openinference.semconv.trace instead.

Note

arize-phoenix-otel is versioned independently of the Phoenix server; the two are not coupled. Any recent SDK version works with any Phoenix server version — there is no version pairing to track. See Version compatibility.

Quick Start#

That’s it! By default, register reads the PHOENIX_COLLECTOR_ENDPOINT environment variable, falling back to http://localhost:4317 using gRPC if the variable is not set.

Configuration#

Environment Variables#

The SDK automatically reads these environment variables:

VariableDescription
PHOENIX_COLLECTOR_ENDPOINTPhoenix server URL
PHOENIX_PROJECTProject name for traces (canonical)
PHOENIX_PROJECT_NAMEAlias for PHOENIX_PROJECT; if both are set, PHOENIX_PROJECT wins
PHOENIX_API_KEYAPI key (automatically adds auth header)
PHOENIX_CLIENT_HEADERSCustom headers for requests
PHOENIX_GRPC_PORTOverride default gRPC port
Note

register() also auto-loads PHOENIX_-prefixed settings from a .env.phoenix file discovered by walking up from the current directory (process environment variables take precedence). Set PHOENIX_DISCOVER_CONFIG=false to opt out. See Environments.

Endpoint Configuration#

You can also configure the endpoint directly in code:

Info

When using the endpoint argument, you must specify the fully qualified URL. HTTP uses /v1/traces, while gRPC uses port 4317 by default.

Register Options#

ParameterDescription
project_namePhoenix project name (or the PHOENIX_PROJECT env var, alias PHOENIX_PROJECT_NAME)
endpointCollector endpoint URL
protocolTransport protocol: "grpc" or "http/protobuf"
headersCustom headers for requests
batchProcess spans in batch (default: False)
auto_instrumentAuto-instrument supported libraries

Note

Spans may not be exported if still queued in the processor when your process exits. With batch=True, call tracer_provider.shutdown() to explicitly flush before exit. Alternatively, use batch=False for immediate export or a context manager (with register(...) as tracer_provider).


Manual Instrumentation Helpers#

phoenix.otel re-exports the OpenInference context managers and semantic conventions so you can add session, user, metadata, tag, prompt template, and suppression context — plus set OpenInference span attributes — from a single import:

Info

Requires arize-phoenix-otel>=0.16.0. Lower-level helpers (get_llm_attributes, TraceConfig, Message, Image, …) continue to live in the openinference-instrumentation package.

See Using Tracing Helpers for a full walkthrough of manual instrumentation.


Advanced: OTel Primitives#

For granular control, use Phoenix wrappers as drop-in replacements for OpenTelemetry primitives:

These wrappers accept an endpoint argument to automatically infer the appropriate SpanExporter.

More examples

Using environment variables:

Custom resources:

Batch processing:

Custom gRPC endpoint:


Advanced: TracerProvider Options#

Both register() and TracerProvider accept standard OpenTelemetry TracerProvider kwargs for advanced features like custom ID generators and sampling:


Reference Documentation#

Full API Reference

Complete API documentation for tracing setup, decorators, and OpenTelemetry configuration