Skip to content

Commit 56d4373

Browse files
committed
move operation name to genaiinvocation, update tool span name
1 parent 8e6ce17 commit 56d4373

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

util/opentelemetry-util-genai/src/opentelemetry/util/genai/span_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def _get_tool_call_span_name(tool_call: ToolCall) -> str:
404404
405405
Format: "execute_tool {gen_ai.tool.name}"
406406
"""
407-
return f"execute_tool {tool_call.name}".strip()
407+
return f"{tool_call.operation_name} {tool_call.name}"
408408

409409

410410
def _apply_tool_call_attributes(

util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class GenAIInvocation:
260260
span: Span | None = None
261261
attributes: dict[str, Any] = field(default_factory=_new_str_any_dict)
262262
error_type: str | None = None
263+
operation_name: str = ""
263264

264265
monotonic_start_s: float | None = None
265266
"""
@@ -277,7 +278,6 @@ class WorkflowInvocation(GenAIInvocation):
277278
"""
278279

279280
name: str = ""
280-
operation_name: str = "invoke_workflow"
281281
input_messages: list[InputMessage] = field(
282282
default_factory=_new_input_messages
283283
)
@@ -297,7 +297,6 @@ class LLMInvocation(GenAIInvocation):
297297
set by the TelemetryHandler.
298298
"""
299299

300-
operation_name: str = GenAI.GenAiOperationNameValues.CHAT.value
301300
request_model: str | None = None
302301
input_messages: list[InputMessage] = field(
303302
default_factory=_new_input_messages
@@ -336,6 +335,9 @@ class LLMInvocation(GenAIInvocation):
336335
server_address: str | None = None
337336
server_port: int | None = None
338337

338+
def __post_init__(self) -> None:
339+
self.operation_name = GenAI.GenAiOperationNameValues.CHAT.value
340+
339341

340342
@dataclass
341343
class EmbeddingInvocation(GenAIInvocation):
@@ -345,7 +347,6 @@ class EmbeddingInvocation(GenAIInvocation):
345347
and context_token attributes are set by the TelemetryHandler.
346348
"""
347349

348-
operation_name: str = GenAI.GenAiOperationNameValues.EMBEDDINGS.value
349350
request_model: str | None = None
350351
provider: str | None = None # e.g., azure.ai.openai, openai, aws.bedrock
351352
server_address: str | None = None
@@ -372,6 +373,9 @@ class EmbeddingInvocation(GenAIInvocation):
372373
These attributes will not be set on spans or events.
373374
"""
374375

376+
def __post_init__(self) -> None:
377+
self.operation_name = GenAI.GenAiOperationNameValues.EMBEDDINGS.value
378+
375379

376380
@dataclass()
377381
class ToolCall(GenAIInvocation):
@@ -428,6 +432,9 @@ class ToolCall(GenAIInvocation):
428432
# Timing field (not inherited from GenAIInvocation, matches LLMInvocation pattern)
429433
monotonic_start_s: float | None = None
430434

435+
def __post_init__(self) -> None:
436+
self.operation_name = GenAI.GenAiOperationNameValues.EXECUTE_TOOL.value
437+
431438

432439
@dataclass
433440
class Error:

0 commit comments

Comments
 (0)