-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Otel instrumentation version 3 #3021
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
Merged
alexmojaki
merged 27 commits into
pydantic:main
from
bitnahian:bitnahian-update-otel-attrs-and-span-names
Oct 1, 2025
+479
−49
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
af73a61
feat: add gen_ai.agent.name attribute to agent run logging
bitnahian 6454dd4
feat: update span naming convention for agent invocations in v3 instr…
bitnahian 785a928
refactor: extract default instrumentation version into a constant and…
bitnahian 723809f
feat: add instrumentation version field to RunContext for tracking se…
bitnahian 42268f0
feat: add default instrumentation version constant and update RunCont…
bitnahian 14eedd4
feat: add instrumentation version to run context using settings or de…
bitnahian 16e764e
refactor: move DEFAULT_INSTRUMENTATION_VERSION constant to _instrumen…
bitnahian 59d04cc
feat: add instrumentation version to tool execution tracing
bitnahian 233f496
feat: add InstrumentationConfig to manage versioned span names and at…
bitnahian f375a3c
fix: add gen_ai.agent.name attribute to fallback model test snapshots
bitnahian 7fe2c18
fix: add gen_ai.agent.name field to logfire test assertions
bitnahian 09db4de
feat: add support for version 3 instrumentation settings in logfire t…
bitnahian eb1229f
fix: add name field to SpanSummary and update test fixtures with span…
bitnahian 872fe1a
feat: add output tool span configuration and improve logfire schema a…
bitnahian 85d4a5d
refactor: consolidate version 2 and 3 test assertions into shared logic
bitnahian 926258d
test: add trace assertions for different instrumentation versions in …
bitnahian 7e3f652
refactor: revert logfire test by removing version parameter
bitnahian dd4b03c
refactor: consolidate output function test cases and add v2/v3 instru…
bitnahian c887a8e
fix: add missing gen_ai tool fields and json schema to logfire attrib…
bitnahian cb3163e
fix: remove redundant version check in test_instructions_with_structu…
bitnahian 037de25
Merge branch 'main' into bitnahian-update-otel-attrs-and-span-names
bitnahian 903410a
refactor: rename InstrumentationConfig class to InstrumentationNames …
bitnahian 2aeb162
refactor: replace next() with list comprehension for output function …
bitnahian e686564
fix: same
bitnahian 1e04c9a
refactor: rename instrumentation_config variable to instrumentation_n…
bitnahian 62fa945
Merge branch 'main' into bitnahian-update-otel-attrs-and-span-names
alexmojaki fb7ef44
fix: correct typo in output_function_attributes variable name
bitnahian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import Self | ||
|
||
DEFAULT_INSTRUMENTATION_VERSION = 2 | ||
"""Default instrumentation version for `InstrumentationSettings`.""" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class InstrumentationConfig: | ||
"""Configuration for instrumentation span names and attributes based on version.""" | ||
|
||
# Agent run span configuration | ||
agent_run_span_name: str | ||
agent_name_attr: str | ||
|
||
# Tool execution span configuration | ||
tool_span_name: str | ||
tool_arguments_attr: str | ||
tool_result_attr: str | ||
|
||
# Output Tool execution span configuration | ||
output_tool_span_name: str | ||
|
||
@classmethod | ||
def for_version(cls, version: int) -> Self: | ||
"""Create instrumentation configuration for a specific version. | ||
|
||
Args: | ||
version: The instrumentation version (1, 2, or 3+) | ||
|
||
Returns: | ||
InstrumentationConfig instance with version-appropriate settings | ||
""" | ||
if version <= 2: | ||
return cls( | ||
agent_run_span_name='agent run', | ||
agent_name_attr='agent_name', | ||
tool_span_name='running tool', | ||
tool_arguments_attr='tool_arguments', | ||
tool_result_attr='tool_response', | ||
output_tool_span_name='running output function', | ||
) | ||
else: | ||
return cls( | ||
agent_run_span_name='invoke_agent', | ||
agent_name_attr='gen_ai.agent.name', | ||
tool_span_name='execute_tool', # Will be formatted with tool name | ||
tool_arguments_attr='gen_ai.tool.call.arguments', | ||
tool_result_attr='gen_ai.tool.call.result', | ||
output_tool_span_name='execute_tool', | ||
) | ||
|
||
def get_agent_run_span_name(self, agent_name: str) -> str: | ||
"""Get the formatted agent span name. | ||
|
||
Args: | ||
agent_name: Name of the agent being executed | ||
|
||
Returns: | ||
Formatted span name | ||
""" | ||
if self.agent_run_span_name == 'invoke_agent': | ||
return f'invoke_agent {agent_name}' | ||
return self.agent_run_span_name | ||
|
||
def get_tool_span_name(self, tool_name: str) -> str: | ||
"""Get the formatted tool span name. | ||
|
||
Args: | ||
tool_name: Name of the tool being executed | ||
|
||
Returns: | ||
Formatted span name | ||
""" | ||
if self.tool_span_name == 'execute_tool': | ||
return f'execute_tool {tool_name}' | ||
return self.tool_span_name | ||
|
||
def get_output_tool_span_name(self, tool_name: str) -> str: | ||
"""Get the formatted output tool span name. | ||
|
||
Args: | ||
tool_name: Name of the tool being executed | ||
|
||
Returns: | ||
Formatted span name | ||
""" | ||
if self.output_tool_span_name == 'execute_tool': | ||
return f'execute_tool {tool_name}' | ||
return self.output_tool_span_name |
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.