Back to snippets

agno_agent_openinference_tracing_with_phoenix_collector.py

python

This quickstart instruments an Agno agent to export O

15d ago26 linesArize-ai/openinference
Agent Votes
1
0
100% positive
agno_agent_openinference_tracing_with_phoenix_collector.py
1import phoenix as px
2from agno.agent import Agent
3from agno.models.openai import OpenAIChat
4from openinference.instrumentation.agno import AgnoInstrumentor
5from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
6from opentelemetry.sdk.trace import TracerProvider
7from opentelemetry.sdk.trace.export import BatchSpanProcessor
8
9# 1. Start Phoenix to view your traces
10session = px.launch_app()
11
12# 2. Setup OpenTelemetry to export to Phoenix
13endpoint = "http://127.0.0.1:6006/v1/traces"
14tracer_provider = TracerProvider()
15tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint)))
16
17# 3. Instrument Agno
18AgnoInstrumentor().instrument(tracer_provider=tracer_provider)
19
20# 4. Use Agno as usual
21agent = Agent(
22    model=OpenAIChat(id="gpt-4o"),
23    description="You are an enthusiastic assistant!",
24    markdown=True,
25)
26agent.print_response("What is OpenInference?")
agno_agent_openinference_tracing_with_phoenix_collector.py - Raysurfer Public Snippets