Skip to main content
Observability in Microsoft Agent Framework is built on OpenTelemetry, the industry-standard framework for collecting telemetry data (traces, metrics, and logs). This enables you to monitor agent behavior, debug issues, and optimize performance in production.

What is Observability?

Observability provides insight into:
  • Agent invocations - Track each agent run with traces
  • Function calls - Monitor tool execution and performance
  • Token usage - Measure costs and quota consumption
  • Errors and failures - Debug issues with detailed stack traces
  • Performance metrics - Identify bottlenecks and slow operations
  • Conversation flows - Visualize multi-turn interactions
The framework automatically emits OpenTelemetry traces, metrics, and logs that can be exported to various backends (Azure Monitor, Aspire Dashboard, Jaeger, Prometheus, etc.).

Quick Start

Zero-Code Observability

Enable observability with a single function call:

Configuration via Environment Variables

Configure exporters through environment variables:
Then simply call configure_otel_providers() without arguments:

Traces

Traces provide a hierarchical view of agent execution:

Automatic Tracing

The framework automatically creates spans for:
  • Agent runs - Each agent.run() call
  • Chat requests - LLM API calls
  • Function invocations - Tool executions
  • HTTP requests - External API calls

Custom Spans

Add custom spans for application-specific operations:

Span Attributes

Agent framework automatically adds rich attributes:

Metrics

Metrics provide quantitative measurements over time:

Built-in Metrics

The framework automatically emits:

Custom Metrics

Add application-specific metrics:

Logs

Automatic Logging

The framework uses Python’s logging module:

Custom Logging

Visualization & Analysis

Aspire Dashboard

The .NET Aspire Dashboard provides a local development UI for viewing telemetry:

Azure Monitor (Application Insights)

Jaeger (Distributed Tracing)

Sensitive Data

Security WarningEnabling sensitive data logging includes:
  • User messages and prompts
  • Agent responses
  • Function arguments and results
  • API keys (if logged)
Only enable in secure development environments. Never in production.

Complete Example

Best Practices

Observability Tips
  1. Always Enable in Production: Observability is essential for debugging
  2. Use Sampling: Sample high-volume traces to reduce costs
  3. Add Custom Spans: Instrument critical business operations
  4. Set Alerts: Monitor error rates and latency thresholds
  5. Correlate Logs: Use trace IDs to correlate logs with traces
  6. Tag Resources: Add service name and version to all telemetry
  7. Monitor Costs: Track token usage metrics for cost optimization
Production Considerations
  • Disable Sensitive Data: Never log sensitive data in production
  • Sampling Strategy: Use tail-based sampling for cost control
  • Data Retention: Configure appropriate retention policies
  • PII Compliance: Ensure telemetry complies with privacy regulations
  • Performance: Observability should add less than 1% overhead
  • Alerting: Set up alerts for errors, latency, and quota limits

Troubleshooting

No Telemetry Appearing

High Overhead

  • Reduce sampling rate
  • Disable sensitive data logging
  • Use batch exporters
  • Filter out low-value spans

Missing Attributes

  • Enable sensitive data (development only)
  • Check span attribute limits in exporter
  • Verify OpenTelemetry SDK version

Next Steps

Agents

Learn about agent telemetry

Middleware

Add custom telemetry with middleware

Tools

Monitor tool execution

Sessions

Track session lifecycle