Arize-OTel

0.12.0 · active · verified Thu Apr 16

Arize-OTel is a helper package designed to streamline OpenTelemetry (OTel) setup for sending traces to Arize AI and Arize Phoenix. It simplifies instrumenting Python applications by providing pre-configured exporters and an instrumentor for common libraries, enabling quick observability integration. The current version is 0.12.0, and the project maintains a regular release cadence for new features, bug fixes, and dependency updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes OpenTelemetry with Arize and Phoenix exporters, then demonstrates both manual and automatic instrumentation. Ensure `ARIZE_API_KEY` and `ARIZE_SPACE_KEY` environment variables are set for Arize and Phoenix is running locally if using the default host. For automatic instrumentation, relevant `opentelemetry-instrumentation-*` packages must be installed separately (e.g., `pip install opentelemetry-instrumentation-requests`).

import os
from opentelemetry import trace
from arize_otel.tracing.config import configure_opentelemetry_for_arize_phoenix
from arize_otel.tracing.instrumentation import ArizeInstrumentor

# Configure OpenTelemetry to send traces to Arize and Phoenix
# Ensure ARIZE_API_KEY and ARIZE_SPACE_KEY environment variables are set.
configure_opentelemetry_for_arize_phoenix(
    arize_api_key=os.environ.get("ARIZE_API_KEY", ""),
    arize_space_key=os.environ.get("ARIZE_SPACE_KEY", ""),
    phoenix_host="http://localhost:6006" # Optional: defaults to "http://localhost:6006"
)

# Manually instrument an application using OpenTelemetry Tracer
tracer = trace.get_tracer("my-arize-app")

with tracer.start_as_current_span("my-manual-span"):
    print("Performing some traced operation...")

# Automatically instrument common libraries (e.g., requests, flask, django)
# Ensure you have installed the respective opentelemetry-instrumentation- packages.
ArizeInstrumentor().instrument()

# Example using a common library (e.g., requests) which will be automatically traced
try:
    import requests
    response = requests.get("https://www.example.com")
    print(f"Requests response status: {response.status_code}")
except ImportError:
    print("Install 'opentelemetry-instrumentation-requests' to trace requests.")

print("Tracing configured and example operation completed.")

view raw JSON →