Skip to content

Python: Add Microsoft OpenTelemetry Distro sample#5632

Draft
TaoChenOSU wants to merge 1 commit intomicrosoft:mainfrom
TaoChenOSU:feature/python-microsoft-opentelemetry-distro
Draft

Python: Add Microsoft OpenTelemetry Distro sample#5632
TaoChenOSU wants to merge 1 commit intomicrosoft:mainfrom
TaoChenOSU:feature/python-microsoft-opentelemetry-distro

Conversation

@TaoChenOSU
Copy link
Copy Markdown
Contributor

Motivation and Context

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@TaoChenOSU TaoChenOSU self-assigned this May 4, 2026
Copilot AI review requested due to automatic review settings May 4, 2026 22:26
@TaoChenOSU TaoChenOSU added python observability Issues related to observability or telemetry labels May 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FoundryChatClient and AzureCliCredential.

Comment on lines +7 to +12
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)
Comment on lines +32 to +36
# 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)
@github-actions github-actions Bot changed the title Add Microsoft OpenTelemetry Distro sample Python: Add Microsoft OpenTelemetry Distro sample May 4, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 78%

✓ Correctness

The new sample follows the same structural pattern as the existing agent_observability.py sample (calling the setup function inside main() 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 to use_microsoft_opentelemetry is 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_opentelemetry to 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-314 both 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

Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs the script dependency install header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

observability Issues related to observability or telemetry python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants