Skip to content

Commit e3bda93

Browse files
committed
Feedback and style/lint updates
1 parent 56d4373 commit e3bda93

3 files changed

Lines changed: 5 additions & 12 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
get_tracer,
8383
set_span_in_context,
8484
)
85-
from opentelemetry.trace.status import Status, StatusCode
8685
from opentelemetry.util.genai.metrics import InvocationMetricsRecorder
8786
from opentelemetry.util.genai.span_utils import (
8887
_apply_embedding_finish_attributes,
@@ -261,7 +260,7 @@ def _fail(self, invocation: _T, error: Error) -> _T:
261260
invocation.error_type = error_type
262261
_finish_tool_call_span(span, invocation, capture_content=True)
263262
self._record_metrics(invocation, span, error_type=error_type)
264-
span.set_status(Status(StatusCode.ERROR, error.message))
263+
_apply_error_attributes(span, error, error_type)
265264
elif isinstance(invocation, WorkflowInvocation):
266265
_apply_workflow_finish_attributes(span, invocation)
267266
_apply_error_attributes(span, error, error_type)

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ def record(
4848
# Build attributes based on invocation type
4949
attributes: Dict[str, AttributeValue] = {}
5050

51+
attributes[GenAI.GEN_AI_OPERATION_NAME] = invocation.operation_name
52+
5153
if isinstance(invocation, LLMInvocation):
52-
attributes[GenAI.GEN_AI_OPERATION_NAME] = (
53-
GenAI.GenAiOperationNameValues.CHAT.value
54-
)
5554
if invocation.request_model:
5655
attributes[GenAI.GEN_AI_REQUEST_MODEL] = (
5756
invocation.request_model
@@ -60,11 +59,6 @@ def record(
6059
attributes[GenAI.GEN_AI_RESPONSE_MODEL] = (
6160
invocation.response_model_name
6261
)
63-
else:
64-
# ToolCall
65-
attributes[GenAI.GEN_AI_OPERATION_NAME] = (
66-
GenAI.GenAiOperationNameValues.EXECUTE_TOOL.value
67-
)
6862

6963
# Common attributes across invocation types
7064
if invocation.provider:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ def _get_embedding_response_attributes(
402402
def _get_tool_call_span_name(tool_call: ToolCall) -> str:
403403
"""Get span name for tool call execution per semantic convention.
404404
405-
Format: "execute_tool {gen_ai.tool.name}"
405+
Format: "{operation_name} {gen_ai.tool.name}"
406406
"""
407-
return f"{tool_call.operation_name} {tool_call.name}"
407+
return f"{tool_call.operation_name} {tool_call.name}".strip()
408408

409409

410410
def _apply_tool_call_attributes(

0 commit comments

Comments
 (0)