Python: Backfill chat span request model if it's unknown and response model is avaliable#6160
Merged
TaoChenOSU merged 1 commit intoMay 28, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves Python OpenTelemetry chat span telemetry by backfilling gen_ai.request.model (and the span name) when the request model is initially unknown but the response includes a resolved model, addressing issue #5088’s “unknown request model” gap.
Changes:
- Add
ChatTelemetryLayer._backfill_request_model(...)to updateREQUEST_MODELand span name fromRESPONSE_MODELwhen the request model is"unknown". - Invoke the backfill step for both streaming and non-streaming chat responses before capturing response attributes.
- Add unit tests covering the helper behavior and end-to-end chat client telemetry updates (streaming + non-streaming).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/observability.py | Adds request-model backfill helper and wires it into chat response capture paths. |
| python/packages/core/tests/core/test_observability.py | Adds coverage for backfill helper and chat-client telemetry behavior. |
| python/packages/foundry/agent_framework_foundry/_agent.py | Updates a Foundry-related doc example import/usage (documentation-only change). |
Comments suppressed due to low confidence (1)
python/packages/foundry/agent_framework_foundry/_agent.py:520
- The example in this docstring instantiates
FoundryAgentand then passes it asclientintoAgent(...).FoundryAgentis itself an agent (it already hasrun(...)and owns an internal chat client), so this example is misleading/incorrect. Update the example to either (a) useFoundryAgentdirectly (agent = FoundryAgent(...); await agent.run(...)) or (b) show how to create a chat client (RawFoundryAgentChatClient/_FoundryAgentChatClient) and wrap it withAgent(client=...).
from agent_framework import Agent
from agent_framework.foundry import FoundryAgent
from azure.identity import AzureCliCredential
client = FoundryAgent(
project_endpoint="https://your-project.services.ai.azure.com",
agent_name="my-prompt-agent",
agent_version="1",
credential=AzureCliCredential(),
)
agent = Agent(client=client, tools=[my_function_tool])
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
4 tasks
eavanvalkenburg
approved these changes
May 28, 2026
semenshi
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Addresses #5088
Description
Backfill the request model in the chat span if it's not set while the response contains the model.

Contribution Checklist