|
11 | 11 | pip install agno opentelemetry-api opentelemetry-sdk openinference-instrumentation-agno |
12 | 12 | """ |
13 | 13 |
|
| 14 | +import time # noqa |
| 15 | + |
14 | 16 | from agno.agent import Agent |
15 | 17 | from agno.db.sqlite import SqliteDb |
16 | 18 | from agno.models.openai import OpenAIChat |
17 | 19 | from agno.tools.hackernews import HackerNewsTools |
18 | 20 | from agno.tracing import setup_tracing |
19 | 21 | from agno.utils.pprint import pprint_run_response |
20 | | -from opentelemetry import trace as trace_api |
21 | 22 |
|
22 | 23 | # Set up database |
23 | 24 | db = SqliteDb(db_file="tmp/traces.db") |
|
40 | 41 | response = agent.run("What is the latest news on AI?") |
41 | 42 | pprint_run_response(response) |
42 | 43 |
|
43 | | -# Force flush traces to database |
44 | | -tracer_provider = trace_api.get_tracer_provider() |
45 | | -if hasattr(tracer_provider, "force_flush"): |
46 | | - tracer_provider.force_flush(timeout_millis=5000) |
47 | | - |
48 | 44 | # Query traces and spans from database |
49 | 45 | print("\n" + "=" * 60) |
50 | 46 | print("Traces and Spans in Database:") |
51 | 47 | print("=" * 60) |
52 | 48 |
|
| 49 | +## If using BatchSpanProcessor, we need to wait for the traces to be flushed to the database before querying |
| 50 | +# time.sleep(5) # Uncomment this if using BatchSpanProcessor |
| 51 | + |
53 | 52 | try: |
54 | 53 | # Get the trace for this run |
55 | 54 | trace = db.get_trace(run_id=response.run_id) |
|
59 | 58 | "\n❌ No trace found. Make sure openinference-instrumentation-agno is installed." |
60 | 59 | ) |
61 | 60 | else: |
62 | | - print("\n📊 Found trace for run") |
| 61 | + print(f"\n📊 Found trace for run") |
63 | 62 |
|
64 | 63 | print(f"\n🔍 Trace ID: {trace.trace_id[:16]}...") |
65 | 64 | print(f" Name: {trace.name}") |
|
0 commit comments