-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use new OpenTelemetry GenAI chat span attribute conventions #2349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Docs Preview
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements support for the new OpenTelemetry GenAI chat span attribute conventions as the first part of addressing issue #2348. The changes introduce a version 2 format that stores chat messages in standardized gen_ai.input.messages
and gen_ai.output.messages
attributes instead of the legacy event-based format.
Key changes:
- Added a new
version
parameter toInstrumentationSettings
with options 1 (legacy) and 2 (new format) - Implemented new OpenTelemetry message format conversion methods that structure messages as standardized chat objects
- Updated tests to validate both version formats and ensure backward compatibility
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pydantic_ai_slim/pydantic_ai/_otel_messages.py |
New module defining TypedDict structures for OpenTelemetry chat message format |
pydantic_ai_slim/pydantic_ai/models/instrumented.py |
Core implementation of version 2 message handling and format conversion |
pydantic_ai_slim/pydantic_ai/messages.py |
Added otel_message_parts methods to all message part classes |
tests/test_logfire.py |
Updated tests to validate both instrumentation versions |
tests/models/test_instrumented.py |
Comprehensive test coverage for new message format conversion |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -90,6 +99,7 @@ def __init__( | |||
event_logger_provider: EventLoggerProvider | None = None, | |||
include_binary_content: bool = True, | |||
include_content: bool = True, | |||
version: Literal[1, 2] = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a better option than this? "legacy"
vs ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this, I suggest bringing it up on slack or something if you'd like to change it, which can still be done after this merges.
First part of #2348
This PR is not meant to finish off this change, just to get moving and make the new format available. Followup PRs will look at the
all_messages_events
attribute of agent run spans, and maybe tool call spans.