Skip to content

Commit 71572c6

Browse files
committed
Fix the span name of LLM invocations
Change-Id: I1b9f40e5576e699b1f61fa3d7e7790ee4b1448a5 Co-developed-by: Cursor <[email protected]>
1 parent b4f0887 commit 71572c6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
get_logger,
7171
)
7272
from opentelemetry.metrics import MeterProvider, get_meter
73-
from opentelemetry.semconv._incubating.attributes import (
74-
gen_ai_attributes as GenAI,
75-
)
7673
from opentelemetry.semconv.schemas import Schemas
7774
from opentelemetry.trace import (
7875
Span,
@@ -141,7 +138,7 @@ def start_llm(
141138
"""Start an LLM invocation and create a pending span entry."""
142139
# Create a span and attach it as current; keep the token to detach later
143140
span = self._tracer.start_span(
144-
name=f"{GenAI.GenAiOperationNameValues.CHAT.value} {invocation.request_model}",
141+
name=f"{invocation.operation_name} {invocation.request_model}",
145142
kind=SpanKind.CLIENT,
146143
)
147144
# Record a monotonic start timestamp (seconds) for duration

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from opentelemetry.context import Context
2525
from opentelemetry.trace import Span
2626

27+
from opentelemetry.semconv._incubating.attributes import (
28+
gen_ai_attributes as GenAI,
29+
)
30+
2731
ContextToken: TypeAlias = Token[Context]
2832

2933

@@ -182,6 +186,8 @@ class LLMInvocation:
182186
"""
183187

184188
request_model: str
189+
# Chat by default
190+
operation_name: str = GenAI.GenAiOperationNameValues.CHAT.value
185191
context_token: ContextToken | None = None
186192
span: Span | None = None
187193
input_messages: list[InputMessage] = field(

0 commit comments

Comments
 (0)