Skip to content

Populate gen_ai.response.model from responses API when the response body includes the served model header - #305

Merged
lmolkova merged 6 commits into
open-telemetry:mainfrom
rads-1996:respect-rapi-headers
Aug 3, 2026
Merged

Populate gen_ai.response.model from responses API when the response body includes the served model header#305
lmolkova merged 6 commits into
open-telemetry:mainfrom
rads-1996:respect-rapi-headers

Conversation

@rads-1996

@rads-1996 rads-1996 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes # (267)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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.

  • uv run tox -e py312-test-instrumentation-genai-langchain -- -q
  • uv run tox -e py312-test-instrumentation-genai-langchain-conformance -- -q
  • uv run --python 3.12 tox -e lint-instrumentation-genai-langchain

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 23, 2026

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-08-03 14:55 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@rads-1996
rads-1996 force-pushed the respect-rapi-headers branch from e986ddb to cc0cf57 Compare July 23, 2026 21:41
@rads-1996

Copy link
Copy Markdown
Contributor Author
image image image

@rads-1996
rads-1996 force-pushed the respect-rapi-headers branch 3 times, most recently from dd53ba4 to 29f323a Compare July 30, 2026 16:51
@rads-1996
rads-1996 marked this pull request as ready for review July 30, 2026 16:52
@rads-1996
rads-1996 requested a review from a team as a code owner July 30, 2026 16:52
Copilot AI review requested due to automatic review settings July 30, 2026 16:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the LangChain GenAI instrumentation to prefer a concrete “served model” value exposed via Responses API response headers when available, improving the accuracy of gen_ai.response.model for deployments where the response body only echoes the requested deployment name.

Changes:

  • Add header-based resolution for response_model_name (e.g. x-ms-served-model) with fallback to existing llm_output["model_name" | "model"].
  • Add unit tests covering header precedence, case-insensitivity, and fallbacks.
  • Add a towncrier changelog fragment for the new capability.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py Prefer served-model response header when present to populate response_model_name
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py Add tests validating header extraction and precedence over llm_output
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/305.added Record the user-visible behavior change in release notes

@eternalcuriouslearner eternalcuriouslearner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!! Thanks for the quick turnaround.

@rads-1996
rads-1996 force-pushed the respect-rapi-headers branch from f82c3d5 to d45a49d Compare July 31, 2026 16:51
@rads-1996
rads-1996 force-pushed the respect-rapi-headers branch from d45a49d to 93212c0 Compare August 3, 2026 14:19
@lmolkova
lmolkova added this pull request to the merge queue Aug 3, 2026
Merged via the queue into open-telemetry:main with commit 79fb78b Aug 3, 2026
81 checks passed
@rads-1996
rads-1996 deleted the respect-rapi-headers branch August 3, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants