Skip to content

Commit 78bc6bf

Browse files
committed
refactor: rename emitters to generators and update method names for clarity
1 parent 770f878 commit 78bc6bf

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

util/opentelemetry-util-genai/src/opentelemetry/util/genai/emitters.py renamed to util/opentelemetry-util-genai/src/opentelemetry/util/genai/generators.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,24 +296,24 @@ def _record_duration(
296296
duration_histogram.record(elapsed, attributes=metric_attributes)
297297

298298

299-
class BaseEmitter:
299+
class BaseTelemetryGenerator:
300300
"""
301301
Abstract base for emitters mapping GenAI types -> OpenTelemetry.
302302
"""
303303

304-
def init(self, invocation: LLMInvocation) -> None:
304+
def start(self, invocation: LLMInvocation) -> None:
305305
raise NotImplementedError
306306

307-
def emit(self, invocation: LLMInvocation) -> None:
307+
def finish(self, invocation: LLMInvocation) -> None:
308308
raise NotImplementedError
309309

310310
def error(self, error: Error, invocation: LLMInvocation) -> None:
311311
raise NotImplementedError
312312

313313

314-
class SpanMetricEventEmitter(BaseEmitter):
314+
class SpanMetricEventGenerator(BaseTelemetryGenerator):
315315
"""
316-
Emits spans, metrics and events for a full telemetry picture.
316+
Generates spans, metrics and events for a full telemetry picture.
317317
"""
318318

319319
def __init__(
@@ -358,7 +358,7 @@ def _end_span(self, run_id: UUID):
358358
child_state.span.end()
359359
state.span.end()
360360

361-
def init(self, invocation: LLMInvocation):
361+
def start(self, invocation: LLMInvocation):
362362
if (
363363
invocation.parent_run_id is not None
364364
and invocation.parent_run_id in self.spans
@@ -378,7 +378,7 @@ def init(self, invocation: LLMInvocation):
378378
if log and self._logger:
379379
self._logger.emit(log)
380380

381-
def emit(self, invocation: LLMInvocation):
381+
def finish(self, invocation: LLMInvocation):
382382
system = invocation.attributes.get("system")
383383
span = self._start_span(
384384
name=f"{system}.chat",
@@ -496,9 +496,9 @@ def error(self, error: Error, invocation: LLMInvocation):
496496
)
497497

498498

499-
class SpanMetricEmitter(BaseEmitter):
499+
class SpanMetricGenerator(BaseTelemetryGenerator):
500500
"""
501-
Emits only spans and metrics (no events).
501+
Generates only spans and metrics (no events).
502502
"""
503503

504504
def __init__(
@@ -541,7 +541,7 @@ def _end_span(self, run_id: UUID):
541541
child_state.span.end()
542542
state.span.end()
543543

544-
def init(self, invocation: LLMInvocation):
544+
def start(self, invocation: LLMInvocation):
545545
if (
546546
invocation.parent_run_id is not None
547547
and invocation.parent_run_id in self.spans
@@ -550,7 +550,7 @@ def init(self, invocation: LLMInvocation):
550550
invocation.run_id
551551
)
552552

553-
def emit(self, invocation: LLMInvocation):
553+
def finish(self, invocation: LLMInvocation):
554554
system = invocation.attributes.get("system")
555555
span = self._start_span(
556556
name=f"{system}.chat",

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from opentelemetry.trace import get_tracer
4747

4848
from .data import ChatGeneration, Error, Message
49-
from .emitters import SpanMetricEmitter, SpanMetricEventEmitter
49+
from .generators import SpanMetricEventGenerator, SpanMetricGenerator
5050
from .types import LLMInvocation
5151

5252
# TODO: Get the tool version for emitting spans, use GenAI Utils for now
@@ -92,15 +92,15 @@ def __init__(self, emitter_type_full: bool = True, **kwargs: Any):
9292
schema_url=Schemas.V1_36_0.value,
9393
)
9494

95-
self._emitter = (
96-
SpanMetricEventEmitter(
95+
self._generator = (
96+
SpanMetricEventGenerator(
9797
tracer=self._tracer,
9898
meter=self._meter,
9999
logger=self._logger,
100100
capture_content=self._should_collect_content(),
101101
)
102102
if emitter_type_full
103-
else SpanMetricEmitter(
103+
else SpanMetricGenerator(
104104
tracer=self._tracer,
105105
meter=self._meter,
106106
capture_content=self._should_collect_content(),
@@ -129,7 +129,7 @@ def start_llm(
129129
)
130130
with self._lock:
131131
self._llm_registry[invocation.run_id] = invocation
132-
self._emitter.init(invocation)
132+
self._generator.start(invocation)
133133

134134
def stop_llm(
135135
self,
@@ -142,7 +142,7 @@ def stop_llm(
142142
invocation.end_time = time.time()
143143
invocation.chat_generations = chat_generations
144144
invocation.attributes.update(attributes)
145-
self._emitter.emit(invocation)
145+
self._generator.finish(invocation)
146146
return invocation
147147

148148
def fail_llm(
@@ -152,13 +152,10 @@ def fail_llm(
152152
invocation = self._llm_registry.pop(run_id)
153153
invocation.end_time = time.time()
154154
invocation.attributes.update(**attributes)
155-
self._emitter.error(error, invocation)
155+
self._generator.error(error, invocation)
156156
return invocation
157157

158158

159-
# Singleton accessor (avoid global statement by storing on function attribute)
160-
161-
162159
def get_telemetry_handler(
163160
emitter_type_full: bool = True, **kwargs: Any
164161
) -> TelemetryHandler:

0 commit comments

Comments
 (0)