AI Agent Observability: Add Logging, Tracing, and Monitoring to Your Python Agents¶

Every article about AI agent observability tells you to buy a platform. Dynatrace. Arize. Galileo. They're great tools — if you have an enterprise budget and a dedicated observability team.
If you're a developer deploying autonomous agents in Python, you need observability that ships with your agent, not a separate SaaS subscription. Here's how to build it.
What "observability" means for an AI agent¶
| Traditional service | AI agent |
|---|---|
| Request latency | Agent run duration |
| Error rate | Tool call failures, LLM refusals |
| Throughput | Runs per day, tokens consumed |
| Log lines | Agent reasoning traces |
The simplest observability: structured logging¶
import json, time, os
from datetime import datetime
def log(event_type: str, **kwargs):
entry = {"timestamp": datetime.utcnow().isoformat(), "event": event_type, **kwargs}
print(json.dumps(entry))
def handler(event, context):
run_id = os.urandom(4).hex()
start = time.time()
log("agent.start", run_id=run_id, goal=event.get("goal", ""))
try:
result = run_agent(event.get("goal", ""))
log("agent.complete", run_id=run_id, duration_sec=round(time.time()-start, 2),
status="success", result=result)
return {"ok": True, "run_id": run_id}
except Exception as e:
log("agent.error", run_id=run_id, error=str(e))
raise
Tool call tracing¶
def traced_tool_call(tool_name, args, run_id):
start = time.time()
log("tool.call", run_id=run_id, tool=tool_name, args=args)
try:
result = execute_tool(tool_name, args)
log("tool.result", run_id=run_id, tool=tool_name,
duration_ms=int((time.time()-start)*1000))
return result
except Exception as e:
log("tool.error", run_id=run_id, tool=tool_name, error=str(e))
raise
Built-in observability with HollowHost¶
| Metric | HollowHost dashboard | DIY logs |
|---|---|---|
| Run history | ✅ Auto-tracked | You build it |
| Duration per run | ✅ Dashboard | You compute it |
| Token usage | ✅ Per-run tracking | You add code |
| Log streaming | ✅ Real-time CLI | You pipe logs |
When to use a platform vs DIY¶
| DIY (this article) | Platform (LangSmith, Arize) | |
|---|---|---|
| Cost | $0 | $50-500+/month |
| Setup time | 30 minutes | 1-2 days |
| Custom metrics | Unlimited | Limited |
| Best for | 1-5 agents, custom needs | 10+ agents, teams |
Start with DIY. Upgrade to a platform when you need shared dashboards.
Deploy agents with built-in observability. Every run is logged automatically. Start on HollowHost — free tier included.