Python: Show FoundryAgent client spans in Foundry traces - #7981
Python: Show FoundryAgent client spans in Foundry traces#7981Jose Alvarez (jpalvarezl) wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Foundry client-span attribution by exposing provider-specific OpenTelemetry agent identity hooks.
Changes:
- Adds overridable agent ID/name telemetry hooks.
- Maps Foundry’s deployed agent name to trace identity.
- Adds identity tests and ignores JetBrains metadata.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
observability.py |
Adds telemetry identity hooks. |
_agent.py |
Implements Foundry-specific identity mapping. |
test_foundry_agent.py |
Tests resolved and explicit identities. |
.gitignore |
Ignores .idea/. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Code Coverage OverviewLanguages: Python Python / code-coverage/pythonThe overall line coverage in commit 4f3b8b1 in the Show a line coverage summary of the most covered files.
Updated |
|
Please use the required pull request template. When ready, re-open the PR. |
|
Re-opening PR to request feedback. Made the PR compliant to guidelines to the best of my ability. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5641780c-318a-4def-8692-710b2b061c60
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (8 commit(s)): c133e29bf466, 2ac21147e0b5, c46ff52fccb4, 7180c5893298, 79db80942428, 7695b7ffd6d9, a3eeaee0c3b8, 807a12a7d750
Model: gpt-5.6-sol
Overview
The PR adds provider hooks for Foundry-specific root-span attributes and response-ID retention, with safe defaults for other providers and symmetric context-variable cleanup in streaming and non-streaming paths. The new tests cover both response-ID modes and successful project-ID derivation. One setup-ordering regression remains: failure of the additional ARM-ID lookup prevents Azure Monitor from being configured even after a valid Application Insights connection string was obtained.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 high) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/foundry/agent_framework_foundry/_agent.py
| "Install it with: pip install azure-monitor-opentelemetry" | ||
| ) from exc | ||
|
|
||
| self._foundry_project_arm_id = await self._get_foundry_project_arm_id() |
There was a problem hiding this comment.
Could this lookup degrade gracefully instead of aborting setup? The connection string has already been retrieved successfully, but the separate connections API can return no APPLICATION_INSIGHTS entry, an unexpected ID shape, or its own service error. Any of those now prevents configure_azure_monitor() and enable_instrumentation() from running, so deployments that previously exported telemetry lose it entirely just because the optional Foundry project attribute cannot be derived. Please warn and continue configuring Azure Monitor without the project attribute when this lookup fails.
| "Install it with: pip install azure-monitor-opentelemetry" | ||
| ) from exc | ||
|
|
||
| self._foundry_project_arm_id = await self._get_foundry_project_arm_id() |
There was a problem hiding this comment.
so does calling this here, mean that only if you setup using this helper method this get's applied and things work? that's either something we need to document extra well, including the in the current samples, or something we need to rethink... (to be clear, I'm not opposed perse)
Motivation & Context
FoundryAgentclient-side spans are exported to Application Insights but do not appear in the agent's Foundry trace view. Foundry requires the client root span to include the Foundry project ARM ID and the response ID used for trace discovery.This change makes client-side
invoke_agentand childchatspans discoverable in Foundry for both streaming and non-streaming runs without changing the agent's public identity or adding agent-version metadata.Description & Review Guide
Related Issue
Fixes #7492
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically