Populate gen_ai.response.model from responses API when the response body includes the served model header (OpenAI) - #355
Conversation
14bdc52 to
d9e4c67
Compare
Pull request dashboard statusMerged · refreshed 2026-08-06 02:21 UTC Status above doesn't look right?
|
There was a problem hiding this comment.
Pull request overview
This PR improves model-name attribution by preferring the served model reported via the x-ms-served-model HTTP response header (notably for OpenAI Responses API / Azure scenarios), and hardens LangChain’s header handling to avoid overwriting a real model name with an empty/whitespace header value.
Changes:
- Add a
get_served_model()helper and use it across OpenAI response extraction paths to populategen_ai.response.modelfromx-ms-served-modelwhen available. - Add unit tests for
get_served_model()and adjust LangChain callback handling + test coverage to ignore empty/whitespace served-model header values. - Add changelog fragments documenting the user-visible behavior changes.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_chat_completions.py | Adds unit tests covering get_served_model() behavior across header shapes and edge cases. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/utils.py | Introduces SUPPORTED_RAPI_RESPONSE_HEADERS and get_served_model() helper for extracting the served model name. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/response_extractors.py | Prefers served-model header over response.model when setting invocation response attributes. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch.py | Uses served-model header in chat/embeddings response-property extraction. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/_raw_response.py | Captures served-model header early for raw streaming responses to populate invocation model name. |
| instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/355.added | Documents the OpenAI served-model header behavior change for the OpenAI instrumentation package. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py | Updates test expectations to ensure whitespace header values do not overwrite an existing model name. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py | Tightens served-model header value guard (isinstance(value, str) + value.strip()). |
| instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/355.fixed | Notes the fix preventing empty model-name overwrite in LangChain instrumentation. |
eternalcuriouslearner
left a comment
There was a problem hiding this comment.
LGTM!! Just a small doubt, should we add a check to the conformance tests or do we have it there?
…ody includes the served model header (OpenAI)
I am not sure if adding conformance test for this scenario would make sense, we would not be able distinguish if the response model was populated though the served model or the deployment name. WDYT? |
8e0ae3a to
7b713d7
Compare
|
@eternalcuriouslearner The PR is ready for another review. Thanks a lot for the previous feedback. |
Description
Fixes one part of # (348)
Added a guard to the response header value in the langchain implementation to ensure we don't accept empty string values.
Type of change
Please delete options that are not relevant.
How has this been tested?
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. List any relevant details for your test
configuration.
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.