Skip to content

Commit 946a1ef

Browse files
Address PR 142 review
Pass the typed LlmCompletionEvent to attribute_enrichers on the success path instead of None; widens the enricher signature to accept LlmCompletionEvent so enrichers can read LLM-call context that the sentinel-pair path used to expose via the closing NodeEvent. Switch the shared typed-event test helper's default node_name and namespace to "ask" so they reflect the calling-node semantics the typed event documents, not the legacy sentinel value.
1 parent 452ff0b commit 946a1ef

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/openarmature/observability/otel/observer.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,10 @@ class OTelObserver:
408408
construction time below that).
409409
- ``attribute_enrichers``: optional sequence of callables run just
410410
before the observer ends each span. Each receives the live
411-
:class:`Span` plus the :class:`NodeEvent` that triggered the
412-
close (or ``None`` on synthetic close sites). Exceptions are
413-
caught and warned; never propagated.
411+
:class:`Span` plus the :class:`NodeEvent` or
412+
:class:`LlmCompletionEvent` that triggered the close (or
413+
``None`` on synthetic close sites). Exceptions are caught and
414+
warned; never propagated.
414415
- ``spec_version``: string surfaced as
415416
``openarmature.graph.spec_version`` on the invocation span.
416417
- ``implementation_name``: string surfaced as
@@ -459,7 +460,7 @@ class OTelObserver:
459460
# span.end() the observer issues. NodeEvent is None on synthetic
460461
# close sites (subgraph dispatch, detached root, fan-out instance,
461462
# invocation span, shutdown drain).
462-
attribute_enrichers: Sequence[Callable[[Span, NodeEvent | None], None]] = ()
463+
attribute_enrichers: Sequence[Callable[[Span, NodeEvent | LlmCompletionEvent | None], None]] = ()
463464
# Read from the package's ``__spec_version__`` (one of the three
464465
# places the spec version is pinned per CLAUDE.md). Bumping the
465466
# spec submodule + the two version fields automatically updates
@@ -530,7 +531,7 @@ def __post_init__(self) -> None:
530531
# warned, never propagated to the dispatch worker.
531532
# ``event`` is None on synthetic close sites (subgraph dispatch,
532533
# detached root, fan-out instance, invocation span, orphan drain).
533-
def _run_enrichers(self, span: Span, event: NodeEvent | None) -> None:
534+
def _run_enrichers(self, span: Span, event: NodeEvent | LlmCompletionEvent | None) -> None:
534535
"""Invoke configured enrichers against ``span`` before
535536
``span.end()`` is called."""
536537
if not self.attribute_enrichers:
@@ -1235,11 +1236,7 @@ def _handle_typed_llm_completion(self, event: LlmCompletionEvent) -> None:
12351236
attrs_out = _truncate_for_attribute(event.output_content, self.payload_max_bytes)
12361237
span.set_attribute("openarmature.llm.output.content", attrs_out)
12371238
span.set_status(Status(StatusCode.OK))
1238-
# Enrichers receive None for the NodeEvent slot — the typed
1239-
# event is not a NodeEvent. Enricher signatures already accept
1240-
# ``NodeEvent | None`` for the same reason synthetic close
1241-
# sites pass None.
1242-
self._run_enrichers(span, None)
1239+
self._run_enrichers(span, event)
12431240
span.end(end_time=end_time_ns)
12441241

12451242
def _handle_llm_error_event(self, event: NodeEvent) -> None:

tests/_helpers/typed_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def make_typed_event(**overrides: Any) -> LlmCompletionEvent:
1919
base: dict[str, Any] = {
2020
"invocation_id": "inv-1",
2121
"correlation_id": None,
22-
"node_name": "openarmature.llm.complete",
23-
"namespace": ("openarmature.llm.complete",),
22+
"node_name": "ask",
23+
"namespace": ("ask",),
2424
"attempt_index": 0,
2525
"fan_out_index": None,
2626
"branch_name": None,

0 commit comments

Comments
 (0)