Skip to main content

Tracing with OpenTelemetry — Observability & Monitoring

[ ABORT TO HUD ]
SEQ. 1
SEQ. 2

Tracing with OpenTelemetry

📊 Observability & Monitoring 9 min 80 BASE XP⌨ HANDS-ON LAB

Understanding Agent Behavior

Foundry uses OpenTelemetry standards for distributed tracing, integrated with Azure Monitor Application Insights.

What Tracing Captures

  • LLM calls - Model, tokens, latency, response
  • Tool invocations - Which tools were called, with what arguments
  • Agent reasoning - Decision chains and state transitions
  • Errors - Failed calls, timeouts, content filter triggers

Setup in Code

from azure.monitor.opentelemetry import configure_azure_monitor

# One line to enable full tracing:
configure_azure_monitor(
    connection_string="InstrumentationKey=xxx;..."
)

# Automatically instrument Foundry SDK & OpenAI Responses API (gen_ai.* spans):
from azure.ai.projects.telemetry import AIProjectInstrumentor
AIProjectInstrumentor().instrument()

Viewing Traces

Traces are viewable in two places:

  • Foundry Portal → Tracing - Quick inspection of agent runs
  • Application Insights → Logs - Advanced KQL queries for deep analysis
🎯 Pro Tip: Always enable tracing in production. When an agent fails, traces show you the exact reasoning chain that led to the failure - invaluable for debugging complex multi-step workflows.
⌨ HANDS-ON LABEnable OpenTelemetry Tracing to Azure Monitor
⭐ +200 XP

Configure OpenTelemetry exporter to stream agent run traces, spans, and token counts to Application Insights.

1Run Python script initializing AzureMonitorTraceExporter with connection string.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
FOUNDRY VERIFICATION
QUERY 1 // 1
What standard does Azure AI Foundry use for distributed tracing?
Custom Microsoft protocol
OpenTelemetry
Log4j
Syslog