Python: Add Microsoft OpenTelemetry Distro sample#5632
Python: Add Microsoft OpenTelemetry Distro sample#5632TaoChenOSU wants to merge 1 commit intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new Python sample demonstrating how to enable telemetry for an Agent Framework agent using the Microsoft OpenTelemetry Distro and Azure Monitor.
Changes:
- Adds a new observability sample that configures the Microsoft OpenTelemetry Distro.
- Demonstrates tracing a simple weather agent conversation and printing the active trace ID.
- Shows a tool-backed streaming agent workflow using
FoundryChatClientandAzureCliCredential.
| from agent_framework import Agent, tool | ||
| from agent_framework.foundry import FoundryChatClient | ||
| from agent_framework.observability import get_tracer | ||
| from azure.identity import AzureCliCredential | ||
| from dotenv import load_dotenv | ||
| from microsoft.opentelemetry import use_microsoft_opentelemetry |
| # This will automatically enable instrumentation for Agent Framework | ||
| # Install the Microsoft OpenTelemetry Distro package to enable this functionality: | ||
| # pip install microsoft-opentelemetry | ||
| use_microsoft_opentelemetry(enable_azure_monitor=True) |
| # Set up Azure monitor exporters for telemetry | ||
| # This will automatically enable instrumentation for Agent Framework | ||
| # Install the Microsoft OpenTelemetry Distro package to enable this functionality: | ||
| # pip install microsoft-opentelemetry | ||
| use_microsoft_opentelemetry(enable_azure_monitor=True) |
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 78%
✓ Correctness
The new sample follows the same structural pattern as the existing
agent_observability.pysample (calling the setup function insidemain()after imports). The Agent Framework's observability uses the standard OpenTelemetry API proxy pattern (get_tracer()delegates to whatever TracerProvider is currently set), so import ordering relative touse_microsoft_opentelemetryis not a correctness issue for framework-generated spans. The existing unresolved comments about Azure Monitor configuration documentation remain relevant. No new correctness bugs found beyond those already flagged.
✓ Security Reliability
This new sample demonstrates using the Microsoft OpenTelemetry Distro for observability. The existing review comments already cover the primary reliability concerns (import ordering for auto-instrumentation and missing Azure Monitor configuration documentation). After investigating the Agent Framework's observability internals (observability.py:1256 gates telemetry behind OBSERVABILITY_SETTINGS.ENABLED, which defaults to False at line 680), I noted that the sample relies on
use_microsoft_opentelemetryto automatically enable framework instrumentation per its inline comment. No additional security vulnerabilities (no secrets, no injection risks, no unsafe deserialization, no resource leaks) were identified beyond what existing comments address.
✓ Test Coverage
This PR adds a new observability sample using Microsoft OpenTelemetry Distro. No tests accompany it, which is consistent with the existing pattern for 02-agents samples (only getting_started samples have tests). However, there are no integration or unit tests anywhere in the project validating the observability module's behavior (get_tracer, tracing instrumentation), meaning this new integration path with the Microsoft distro is completely untested. The sample itself is straightforward and follows the structure of the existing agent_observability.py sample.
✗ Design Approach
The new sample picks the wrong observability layer for the behavior it is trying to demonstrate. It configures the Microsoft OpenTelemetry distro, but never enables Agent Framework's own instrumentation switch, so the Agent/Foundry spans this sample is supposed to showcase will be skipped. The repo also already has a Foundry-specific
configure_azure_monitor()helper that retrieves the Application Insights connection string and enables instrumentation in one place, which is a better fit for this scenario than a lower-level distro call.
Suggestions
- For a Foundry-based sample, prefer
await client.configure_azure_monitor(...)instead of wiring Azure Monitor through the distro directly. The implementation in_chat_client.py:261-314both retrieves the project connection string and enables Agent Framework instrumentation in one call, which is the documented Foundry path in the README.
Automated review by TaoChenOSU's agents
eavanvalkenburg
left a comment
There was a problem hiding this comment.
looks nice! Just the header that tells the user/uv which package to install and README update, and probably good to note how to setup sensitive data as well (if desired) (through env)
| @@ -0,0 +1,60 @@ | |||
| # Copyright (c) Microsoft. All rights reserved. | |||
There was a problem hiding this comment.
needs the script dependency install header
Motivation and Context
Description
Contribution Checklist