Skip to content

Conversation

bitnahian
Copy link
Contributor

@bitnahian bitnahian commented Sep 29, 2025

Fixes #2964

Key Changes:

  • New InstrumentationNames class - Centralizes span naming and attribute configuration for different instrumentation versions (v2 vs v3+)
  • This was necessary because it didn't feel quite right to include this functionality in InstrumentationSettings. These could potentially be staticmethods in InstrumentationSettings. Feel free to suggest changing to this if it feels more appropriate.
  • Versioned span naming - v3+ uses semantic naming like invoke_agent {name} and execute_tool {name} vs v2's generic names
  • Updated attribute schemas - v3+ uses standardized gen_ai.* attributes (e.g., gen_ai.agent.name, gen_ai.tool.call.arguments)
  • Output tool instrumentation - Added proper span configuration for output function execution

@bitnahian bitnahian changed the title feat: InstrumentationSettings version 3 feat: Otel instrumentaiton version 3 Sep 29, 2025
@bitnahian bitnahian changed the title feat: Otel instrumentaiton version 3 feat: Otel instrumentation version 3 Sep 29, 2025
@alexmojaki alexmojaki requested a review from Copilot September 30, 2025 16:05
Copy link
Contributor

@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 adds support for OpenTelemetry instrumentation version 3, implementing a new configuration system for span naming and attribute schemas. The main purpose is to provide semantic span names (e.g., invoke_agent {name}, execute_tool {name}) and standardized gen_ai.* attributes for better observability.

  • Added InstrumentationConfig class to centralize span naming and attribute configuration across versions
  • Updated span naming patterns for v3+ with semantic naming conventions
  • Migrated attribute schemas to use standardized gen_ai.* format for v3+

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pydantic_ai_slim/pydantic_ai/_instrumentation.py New file implementing InstrumentationConfig class for version-specific span naming and attributes
pydantic_ai_slim/pydantic_ai/models/instrumented.py Updated version type annotation to include version 3 and changed default to use constant
pydantic_ai_slim/pydantic_ai/agent/init.py Updated agent run span creation to use versioned configuration
pydantic_ai_slim/pydantic_ai/_tool_manager.py Modified tool execution spans to use versioned naming and attributes
pydantic_ai_slim/pydantic_ai/_output.py Updated output function spans to use versioned configuration
pydantic_ai_slim/pydantic_ai/_run_context.py Added instrumentation version field to RunContext
pydantic_ai_slim/pydantic_ai/_agent_graph.py Updated to pass instrumentation version to run context
tests/test_logfire.py Comprehensive test updates with version 3 test cases and expected span names/attributes
tests/models/test_fallback.py Added gen_ai.agent.name attribute to test expectations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bitnahian bitnahian requested a review from alexmojaki October 1, 2025 01:34
@alexmojaki alexmojaki requested a review from Copilot October 1, 2025 09:42
Copy link
Contributor

@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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@alexmojaki alexmojaki assigned Copilot and unassigned Copilot Oct 1, 2025
Copy link
Contributor

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

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

Thanks!

@bitnahian
Copy link
Contributor Author

Thanks @alexmojaki legend.

@alexmojaki alexmojaki merged commit df333bd into pydantic:main Oct 1, 2025
31 checks passed
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.

Update OpenTelemetry span and attribute names
3 participants