Skip to content

refactor: move tracing onto plugin/hook pattern #1045

@ajbozarth

Description

@ajbozarth

Background

Tracing is the only telemetry pillar still using pre-plugin instrumentation. Metrics (#443) and logging (#442) both migrated to the canonical plugin/hook pattern during their epics; tracing needs the same treatment to unblock the rest of epic #444.

Current state

  • mellea/telemetry/backend_instrumentation.py exposes instrument_generate_from_context, instrument_generate_from_raw, start_generate_span, record_token_usage, record_response_metadata.
  • Each of 5 backends (openai, ollama, huggingface, litellm, watsonx) calls these helpers inline (~20 call sites total).
  • The active span is stored in mot._meta["_telemetry_span"] so it can survive the asyncio.create_task boundary and be closed in post_processing() / error path.
  • Tracing reads raw provider responses for attribute extraction instead of mot.generation.

Scope

Phase & dependencies

Phase 1 (foundation). No internal deps. Blocks all of Phase 2 and Phase 3. Sequencing within Phase 1: this issue → #1046#1047; all three likely land as a single PR per the epic plan.

Coordination notes

Acceptance criteria

Parent epic: #444

Metadata

Metadata

Assignees

Labels

area/backendsProvider-specific work: Ollama, HF, LiteLLM, OpenAI, Bedrock, vLLMarea/telemetryOTel spans, metrics, tracing, semconvrefactor

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions