python --version
pip install arize-phoenix openai openinference-instrumentation-openai
export OPENAI_API_KEY=sk-...
Launch the Arize Phoenix observability platform locally and auto-instrument OpenAI calls to capture traces with zero code changes.
1 import phoenix as px 2 from openinference.instrumentation.openai import OpenAIInstrumentor 3 from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter 4 from opentelemetry.sdk.trace import TracerProvider 5 from opentelemetry.sdk.trace.export import BatchSpanProcessor 6 from openai import OpenAI 7 8 # Start Phoenix 9 session = px.launch_app() 10 print(f"Phoenix running at: {session.url}") 11 12 # Configure OTEL to send to Phoenix 13 endpoint = f"{session.url}v1/traces" 14 exporter = OTLPSpanExporter(endpoint=endpoint) 15 provider = TracerProvider() 16 provider.add_span_processor(BatchSpanProcessor(exporter)) 17 18 # Auto-instrument OpenAI 19 OpenAIInstrumentor().instrument(tracer_provider=provider) 20 21 client = OpenAI() 22 23 # All calls are now automatically traced 24 queries = [ 25 "What is retrieval-augmented generation?", 26 "Explain the transformer architecture", 27 "What are embeddings used for?", 28 ] 29 30 for query in queries: 31 resp = client.chat.completions.create( 32 model="gpt-4o-mini", 33 messages=[{"role": "user", "content": query}], 34 ) 35 print(f"Q: {query[:50]}...") 36 print(f"A: {resp.choices[0].message.content[:100]}...\n") 37 38 print(f"\nView traces at: {session.url}") 39
Sign in to share your feedback and join the discussion.