Repository navigation
Closed
Labels
area/backendsProvider-specific work: Ollama, HF, LiteLLM, OpenAI, Bedrock, vLLMarea/telemetryOTel spans, metrics, tracing, semconvrefactor
Description
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.pyexposesinstrument_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 theasyncio.create_taskboundary and be closed inpost_processing()/ error path. - Tracing reads raw provider responses for attribute extraction instead of
mot.generation.
Scope
- Create
mellea/telemetry/tracing_plugins.pyfollowingmellea/telemetry/metrics_plugins.pyas the reference. Example structure:BackendTracingPlugin(priority ~50) — hooksgeneration_post_callinFIRE_AND_FORGETmode, readspayload.model_output.generation, emits the backend generation span withgen_ai.*attributes.- Register plugins through a
_TRACING_PLUGIN_CLASSEStuple insidetracing.pyat import time when tracing is enabled.
- Remove all direct tracing imports from
mellea/backends/*.py. Delete the ~20 inline instrumentation calls. - Remove the
mot._meta["_telemetry_span"]stash. Spans now live inside the plugin and don't need to round-trip through the MOT.- This closes out Epic: ModelOutputThunk structural cleanup #909 item 2 as a side effect.
- Keep
mellea/telemetry/tracing.pyas the low-level setup module (tracer provider, exporters,Tracercreation). Plugins consumeget_application_tracer()/get_backend_tracer(). - Application-level spans (session, aact) stay as a separate question — tracked in feat: session and act spans via plugin hooks #1048.
- Must preserve all attributes PR feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036 lands:
gen_ai.provider.name,gen_ai.conversation.id,error.type, and cache/reasoning token attrs (gen_ai.usage.cache_read.input_tokens,gen_ai.usage.cache_creation.input_tokens,gen_ai.usage.reasoning.output_tokens). Prompt-template attrs, request params, and content capture are tracked as follow-up issues (feat(telemetry): emit llm.prompt_template.* from tracing plugin (post-#1045) #1067, feat(telemetry): emit gen_ai.request.* from tracing plugin (post-#1045) #1068, feat(telemetry): emit gen_ai.input/output.messages content events from tracing plugin (post-#1045) #1073) and are not in scope here.
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
- Streaming generation path has an open question about when
GENERATION_POST_CALLfires (see feat: streaming validation — per-chunk requirement checking with early exit #891 discussion, Epic: ModelOutputThunk structural cleanup #909 comment thread). Whatever resolves that concern forTokenMetricsPluginapplies here identically. - Coordinate with @planetf1 on PR feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036 (emission gaps) — that PR is compatible to merge as-is; after it lands, the attribute emission moves from
backend_instrumentation.pyinto the plugin added here. - Three Phase 2 issues (feat(telemetry): emit llm.prompt_template.* from tracing plugin (post-#1045) #1067, feat(telemetry): emit gen_ai.request.* from tracing plugin (post-#1045) #1068, feat(telemetry): emit gen_ai.input/output.messages content events from tracing plugin (post-#1045) #1073) explicitly depend on this refactor to make their plugin-layer implementations possible. The plugin architecture here should accommodate a
GENERATION_PRE_CALLhook (needed by feat(telemetry): emit gen_ai.request.* from tracing plugin (post-#1045) #1068) and formatter-layer attribute emission (needed by feat(telemetry): emit llm.prompt_template.* from tracing plugin (post-#1045) #1067) so those follow-ups don't hit design blockers.
Acceptance criteria
-
mellea/telemetry/tracing_plugins.pyexists with at leastBackendTracingPlugin. - No file under
mellea/backends/imports frommellea.telemetry.backend_instrumentationormellea.telemetry.tracing. -
mot._meta["_telemetry_span"]is not set or read anywhere (closes Epic: ModelOutputThunk structural cleanup #909 item 2). - All attributes from PR feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036 continue to be emitted by the plugin with no regression.
- Existing tracing tests pass (adjust as needed).
- A basic integration test asserts spans are emitted for at least one backend with the new plugin path.
Parent epic: #444
Metadata
Metadata
Assignees
Labels
area/backendsProvider-specific work: Ollama, HF, LiteLLM, OpenAI, Bedrock, vLLMarea/telemetryOTel spans, metrics, tracing, semconvrefactor
Activity
refactor(telemetry): trim PR to gaps 1, 2, 4 per review
feat(telemetry): close five OTel GenAI semantic convention emission g…
feat(telemetry): close five OTel GenAI semantic convention emission g…
refactor(telemetry)!: move backend tracing onto plugin/hook pattern
refactor(telemetry)!: move backend tracing onto plugin/hook pattern (g…