Repository navigation
Description
Problem
Gap 5 from #1035: Mellea does not emit chat content span events, so the conversation transcript is invisible in OTel backends. Metadata (tokens, model, latency) is present on backend spans but prompts and responses are not.
Per the OTel GenAI semconv, content capture should use span events with these names, each carrying structured role + content:
gen_ai.system.messagegen_ai.user.messagegen_ai.assistant.messagegen_ai.tool.messagegen_ai.choice
Additionally, OpenInference-compatible system instruction capture:
gen_ai.system_instructions
Why deferred from PR #1036
The component-level approach (passing conversation/output_text through finalize_backend_span) required changes to all 5 backends and was withdrawn as too much churn. After #1045, BackendTracingPlugin receives GenerationPostCallPayload which contains the conversation and output — no backend changes needed at all.
Approach
After #1045 lands and BackendTracingPlugin exists:
- In
BackendTracingPlugin, checkis_content_tracing_enabled()before emitting. - If enabled, call the existing
add_span_event()helper (already wired inmellea/telemetry/tracing.pyfrom PR feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036) to emitgen_ai.user.message,gen_ai.assistant.message, etc. fromGenerationPostCallPayload. - Content capture remains off by default — opt in via
MELLEA_TRACE_CONTENT(renamedMELLEA_TRACES_CONTENTunder refactor: rename tracing env vars to plural and align with OTel semconv #1046) orOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT.
The infrastructure is already in place from PR #1036: is_content_tracing_enabled(), add_span_event(), and the _TRACE_CONTENT_ENABLED flag.
Prerequisites
- refactor: move tracing onto plugin/hook pattern #1045 (Phase 1 plugin/hook pattern) must merge first —
BackendTracingPluginandGenerationPostCallPayloadare not available until then.
Related
- Epic Epic: Enhanced distributed tracing #444 Phase 2 — alongside OTel omissions/gaps: chat content events, gen_ai.conversation.id, prompt templates, error status #1035, feat(telemetry): emit llm.prompt_template.* from tracing plugin (post-#1045) #1067
- PR feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036 (infrastructure landed; content emission deferred)
- refactor: rename tracing env vars to plural and align with OTel semconv #1046 (env var rename —
MELLEA_TRACE_CONTENT→MELLEA_TRACES_CONTENT)
Activity