Skip to content

Commit e156f23

Browse files
committed
update
1 parent 4bb2ab6 commit e156f23

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

cookbook/integrations/observability/trace_to_database.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
pip install agno opentelemetry-api opentelemetry-sdk openinference-instrumentation-agno
1212
"""
1313

14+
import time # noqa
15+
1416
from agno.agent import Agent
1517
from agno.db.sqlite import SqliteDb
1618
from agno.models.openai import OpenAIChat
1719
from agno.tools.hackernews import HackerNewsTools
1820
from agno.tracing import setup_tracing
1921
from agno.utils.pprint import pprint_run_response
20-
from opentelemetry import trace as trace_api
2122

2223
# Set up database
2324
db = SqliteDb(db_file="tmp/traces.db")
@@ -40,16 +41,14 @@
4041
response = agent.run("What is the latest news on AI?")
4142
pprint_run_response(response)
4243

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-
4844
# Query traces and spans from database
4945
print("\n" + "=" * 60)
5046
print("Traces and Spans in Database:")
5147
print("=" * 60)
5248

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+
5352
try:
5453
# Get the trace for this run
5554
trace = db.get_trace(run_id=response.run_id)
@@ -59,7 +58,7 @@
5958
"\n❌ No trace found. Make sure openinference-instrumentation-agno is installed."
6059
)
6160
else:
62-
print("\n📊 Found trace for run")
61+
print(f"\n📊 Found trace for run")
6362

6463
print(f"\n🔍 Trace ID: {trace.trace_id[:16]}...")
6564
print(f" Name: {trace.name}")

libs/agno/agno/tracing/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
def setup_tracing(
2727
db: Union[BaseDb, AsyncBaseDb],
28-
use_batch_processor: bool = True,
28+
use_batch_processor: bool = False,
2929
max_queue_size: int = 2048,
3030
max_export_batch_size: int = 512,
3131
schedule_delay_millis: int = 5000,
@@ -93,7 +93,7 @@ def setup_tracing(
9393
)
9494
else:
9595
processor = SimpleSpanProcessor(exporter)
96-
logger.info("Tracing configured with SimpleSpanProcessor (immediate export)")
96+
logger.info("Tracing configured with SimpleSpanProcessor")
9797

9898
tracer_provider.add_span_processor(processor)
9999

0 commit comments

Comments
 (0)