fix(azure-ai): fall back to message metadata for gen_ai.response.id - #802
Merged
Facundo Santiago (santiagxf) merged 1 commit intoJul 5, 2026
Conversation
The AzureAIOpenTelemetryTracer only stamped `gen_ai.response.id` from `LLMResult.llm_output["id"]`, which is populated on the Chat Completions path. On the Responses API path the id is only available on `AIMessage.response_metadata["id"]`, so the attribute was missing and traces did not show up in the Foundry portal. Resolve the id with a fallback to the message metadata so it is emitted on both paths. `llm_output["id"]` still takes precedence when present. Fixes langchain-ai#655
Facundo Santiago (santiagxf)
approved these changes
Jul 5, 2026
Facundo Santiago (santiagxf)
merged commit Jul 5, 2026
1afe242
into
langchain-ai:main
8 checks passed
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.
Fixes #655.
Problem
AzureAIOpenTelemetryTracer.on_llm_endonly stampsgen_ai.response.idwhen it findsLLMResult.llm_output["id"]. That field is populated on the Chat Completions path, but on the Responses API pathlangchain-openaiexposes the id only onAIMessage.response_metadata["id"]. As a resultgen_ai.response.idis missing on that path, and the traces do not show up in the Foundry portal.Fix
Resolve the response id with a fallback: use
llm_output["id"]when present, otherwise walk the chat generations and readAIMessage.response_metadata["id"]. The attribute is now emitted on both paths, andllm_output["id"]still takes precedence.Tests
Added two unit tests in
tests/unit_tests/test_inference_tracing.py:test_response_id_falls_back_to_message_response_metadata— id only onAIMessage.response_metadatais now emitted.test_response_id_prefers_llm_output_over_message_metadata—llm_output["id"]wins when both are present.Full
test_inference_tracing.pymodule passes (138 tests); ruff + mypy clean.Fixes #655