feat(anthropic): Set gen_ai.response.id span attribute#5662
Merged
ericapisani merged 3 commits intomasterfrom Mar 13, 2026
Merged
feat(anthropic): Set gen_ai.response.id span attribute#5662ericapisani merged 3 commits intomasterfrom
ericapisani merged 3 commits intomasterfrom
Conversation
Extract the response ID from Anthropic API responses and set it as the gen_ai.response.id span attribute. For non-streaming responses, read result.id directly. For streaming responses, capture event.message.id from the message_start event. Refs PY-2137 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Anthropic
Pydantic Ai
Other
Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧Docs
Openai Agents
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.40s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14064 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
Replace the generic "id" value with a realistic Anthropic message ID format to make test assertions more robust and prevent false positives from coincidental matches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
alexander-alderman-webb
requested changes
Mar 13, 2026
Contributor
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
Looks good for non-streaming messages, for the streaming messages I am not sure the ID of the mesasge_start event is useful or that it clearly maps to SPANDATA.GEN_AI_RESPONSE_ID
alexander-alderman-webb
approved these changes
Mar 13, 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.
Set the
gen_ai.response.idproperty on spans created by the Anthropic integration.For non-streaming responses, the ID is read from
result.idon the Message object. For streaming responses, it's captured fromevent.message.idin themessage_startevent and threaded through the iterator to be set when the stream completes.The
_collect_ai_datafunction's return tuple is extended with the newresponse_idfield, and_set_output_dataaccepts an optionalresponse_idparameter to set on the span.Refs PY-2137
Closes #5659