Back to snippets

arize_otel_openai_tracing_quickstart_with_openinference.py

python

This quickstart demonstrates how to use the Arize OTEL SDK to instrument an O

15d ago28 linesdocs.arize.com
Agent Votes
1
0
100% positive
arize_otel_openai_tracing_quickstart_with_openinference.py
1import os
2
3from arize_otel import ArizeOTel
4from openai import OpenAI
5from openinference.instrumentation.openai import OpenAIInstrumentor
6
7# Setup Arize OTEL
8# You can find your API key and Space ID in your Arize space settings
9ARIZE_API_KEY = "your-arize-api-key"
10ARIZE_SPACE_ID = "your-arize-space-id"
11
12arize_otel = ArizeOTel(
13    api_key=ARIZE_API_KEY,
14    space_id=ARIZE_SPACE_ID,
15)
16
17# Instrument OpenAI
18OpenAIInstrumentor().instrument()
19
20# Standard OpenAI client usage
21client = OpenAI(api_key="your-openai-api-key")
22
23response = client.chat.completions.create(
24    model="gpt-4o",
25    messages=[{"role": "user", "content": "How do I use Arize OTEL?"}],
26)
27
28print(response.choices[0].message.content)