Skip to content

refactor: move tracing error-path closure into generation_error plugin hook #1047

@ajbozarth

Description

@ajbozarth

Background

Today, mellea/core/base.py:520–541 reaches into mot._meta["_telemetry_span"], calls set_span_error / end_backend_span, and then fires the generation_error hook. This means:

  1. Core code knows about tracing internals.
  2. Any tracing plugin hooking generation_error would find the span already closed.

After PR #1036 lands, the error-path closure is consolidated through finalize_backend_span(error=...) but still lives in core/base.py. Once #1045 lands, tracing plugins should own error-path span closure.

Scope

  • Remove the tracing-specific block from core/base.py entirely.
  • Handle error-path span closure inside BackendTracingPlugin (or a dedicated ErrorTracingPlugin if cleaner) via the generation_error hook.
  • Retire or internalize finalize_backend_span as part of this move — its logic becomes plugin-internal rather than a helper called from core/base.py.
  • Ensure the span's status is set to ERROR with record_exception() so semconv-compliant receivers see it correctly. This overlaps with the error-status gap addressed by feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036.

Phase & dependencies

Phase 1 (foundation). Depends on #1045. Likely lands in the same PR as #1045 and {{NEW-B}}.

Acceptance criteria

  • mellea/core/base.py no longer imports anything from mellea.telemetry.tracing or backend_instrumentation.
  • A failing generation emits a span with OTel ERROR status and a recorded exception.
  • finalize_backend_span is either deleted or made plugin-internal.
  • Existing error-path tests pass.

Parent epic: #444

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions