Skip to content

Commit 0b18708

Browse files
committed
update span name
1 parent bb184da commit 0b18708

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ def _span_for_invocation(self, invocation: LLMInvocation):
227227
The span is not ended automatically on exiting the context; callers
228228
must finalize via _finalize_invocation.
229229
"""
230-
request_model = invocation.attributes.get("request_model")
231230
span = self._start_span(
232-
name=f"{GenAI.GenAiOperationNameValues.CHAT.value} {request_model}",
231+
name=f"{GenAI.GenAiOperationNameValues.CHAT.value} {invocation.request_model}",
233232
kind=SpanKind.CLIENT,
234233
parent_run_id=invocation.parent_run_id,
235234
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ def __init__(self, emitter_type_full: bool = True, **kwargs: Any):
6666

6767
def start_llm(
6868
self,
69+
request_model: str,
6970
prompts: List[InputMessage],
7071
run_id: UUID,
7172
parent_run_id: Optional[UUID] = None,
7273
**attributes: Any,
7374
) -> None:
7475
invocation = LLMInvocation(
76+
request_model=request_model,
7577
messages=prompts,
7678
run_id=run_id,
7779
parent_run_id=parent_run_id,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class LLMInvocation:
8080
"""
8181

8282
run_id: UUID
83+
request_model: str
8384
parent_run_id: Optional[UUID] = None
8485
start_time: float = field(default_factory=time.time)
8586
end_time: Optional[float] = None

util/opentelemetry-util-genai/tests/test_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ def test_llm_start_and_stop_creates_span(self): # pylint: disable=no-self-use
132132

133133
# Start and stop LLM invocation
134134
self.telemetry_handler.start_llm(
135-
[message], run_id=run_id, custom_attr="value", system="test-system"
135+
request_model="test-model",
136+
prompts=[message],
137+
run_id=run_id,
138+
custom_attr="value",
139+
system="test-system",
136140
)
137141
invocation = self.telemetry_handler.stop_llm(
138142
run_id, chat_generations=[chat_generation], extra="info"
@@ -142,7 +146,7 @@ def test_llm_start_and_stop_creates_span(self): # pylint: disable=no-self-use
142146
spans = self.span_exporter.get_finished_spans()
143147
assert len(spans) == 1
144148
span = spans[0]
145-
assert span.name == "test-system.chat"
149+
assert span.name == "chat test-model"
146150
assert span.kind == trace.SpanKind.CLIENT
147151

148152
# Verify span attributes

0 commit comments

Comments
 (0)