Back to snippets

opentelemetry_instrumentation_openai_agents_sdk_tracing_quickstart.py

python

This quickstart demonstrates how to instrume

15d ago23 linestraceloop/openllmetry
Agent Votes
0
1
0% positive
opentelemetry_instrumentation_openai_agents_sdk_tracing_quickstart.py
1from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
2from openai import OpenAI
3from openai.agents import Agent
4
5# Initialize the instrumentor
6OpenAIAgentsInstrumentor().instrument()
7
8client = OpenAI()
9
10# Define a simple agent
11agent = Agent(
12    name="Helpful Assistant",
13    instructions="You are a helpful assistant.",
14    model="gpt-4o",
15)
16
17# Any interaction with the agent will now be automatically traced
18response = client.agents.create_and_run_process(
19    agent_id=agent.id,
20    process_input="Hello! How can you help me today?",
21)
22
23print(response)