Skip to content

Conversation

alexmojaki
Copy link
Contributor

@alexmojaki alexmojaki commented Jul 29, 2025

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.

Copy link

github-actions bot commented Jul 29, 2025

Docs Preview

commit: cafba23
Preview URL: https://dc7467b8-pydantic-ai-previews.pydantic.workers.dev

@alexmojaki alexmojaki requested a review from Copilot August 21, 2025 12:00
@alexmojaki alexmojaki marked this pull request as ready for review August 21, 2025 12:00
Copy link

@Copilot Copilot AI left a 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 to InstrumentationSettings 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.

@alexmojaki alexmojaki requested a review from Kludex August 21, 2025 12:02
@@ -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,
Copy link
Member

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 ...?

Copy link
Contributor Author

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.

@alexmojaki alexmojaki enabled auto-merge (squash) August 21, 2025 13:45
@alexmojaki alexmojaki merged commit 38b0273 into main Aug 21, 2025
33 checks passed
@alexmojaki alexmojaki deleted the alex/new-otel-semconv branch August 21, 2025 13:48
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.

2 participants