Skip to content

Epic: Enhanced distributed tracing #444

Open
22 of 28 issues completed
Open

Description

@psschwei

Overview

This epic refreshes the tracing telemetry plan to bring it in line with the canonical plugin/hook pattern established by the metrics (#443) and logging (#442) epics, both closed 2026-04-27.

The original plan (2026-02-10) and its nine sub-issues (#469–#477) predate two major refactors that reshape tracing's design surface:

The original sub-issues have been retired and replaced by the phased plan below. See the companion comment on this epic for a feature-level mapping of retired issues to their replacements.

Current state (2026-05-07)

  • Tracing lives in mellea/telemetry/tracing.py and mellea/telemetry/backend_instrumentation.py.
  • Uses direct inline instrumentation in all 5 backends (~20 call sites) — no plugin/hook usage.
  • No tracing_plugins.py; tracing is the only telemetry pillar still on pre-plugin patterns.
  • Stores the active backend span in mot._meta["_telemetry_span"] so it survives coroutine boundaries — collides with Epic: ModelOutputThunk structural cleanup #909 item 2.
  • Reads raw provider responses for attribute extraction instead of mot.generation (the normalized GenerationMetadata).
  • Uses deprecated gen_ai.system attribute (current GenAI semconv is gen_ai.provider.name, which metrics uses). @planetf1's PR feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036 is adding dual-emission.
  • Env vars split and non-uniform: MELLEA_TRACE_APPLICATION, MELLEA_TRACE_BACKEND, MELLEA_TRACE_CONSOLE. No single umbrella flag. Only honors generic OTEL_EXPORTER_OTLP_ENDPOINT; no OTEL_EXPORTER_OTLP_TRACES_ENDPOINT support.
  • Initialized at module import; tests require importlib.reload (vs logging's lazy init).
  • Error-path span closure happens in core/base.py:520–541 before the generation_error hook fires — would block a tracing plugin hooking that event.
  • Missing span coverage per current semconv: tool calls, streaming events (first-token / chunk / complete), chat content events, gen_ai.conversation.id, most gen_ai.request.* parameters, SpanKind.CLIENT on backend calls.

Scope

Phase 1 — Foundation (serial, blocking)

These must land before Phase 2/3. Likely one PR, separate tracking issues for clarity.

Phase 2 — Coverage (parallelizable once Phase 1 lands)

Phase 3 — Polish

Acceptance Criteria

  • mellea/telemetry/tracing_plugins.py exists and parallels metrics_plugins.py in shape.
  • No backend file imports tracing helpers directly.
  • mot._meta["_telemetry_span"] is removed.
  • Env vars renamed to plural MELLEA_TRACES_* (aligned with OTel standard partner var and MELLEA_METRICS_*). Old MELLEA_TRACE_* names emit deprecation warnings for one release.
  • All emitted gen_ai.* attributes match current OTel GenAI semconv (gen_ai.provider.name, not gen_ai.system).
  • Span events emitted for streaming milestones (TTFB, first token, complete).
  • Tool calls produce spans via tool_post_invoke.
  • OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is respected when set.
  • Docs example for full traces lands (docs: add Telemtry example for getting full traces #945).

Coordination

Related / Retired

Sub-issues

Sub-issues

22 of 28 Issues completed
Loading 28 sub-issues

Activity

  1. added
    area/telemetry
    on Feb 10, 2026
  2. self-assigned this
    on Mar 18, 2026
  3. added this to the Release 0.6.0 milestone on May 6, 2026
  4. 10 remaining items

  5. planetf1 commented on May 13, 2026

    @planetf1
    Contributor

    Attribute naming audit note — cache and reasoning token attributes (PR #1036)

    PR #1036 emits the following token-usage attributes for Anthropic-specific fields:

    • gen_ai.usage.cache_read.input_tokens
    • gen_ai.usage.cache_creation.input_tokens
    • gen_ai.usage.reasoning.output_tokens

    These are not yet defined in the upstream OTel GenAI semconv as of v1.37.0. They follow the gen_ai.usage.* namespace convention but are Anthropic-specific names we chose. The names may conflict with or diverge from whatever the OTel working group eventually standardises.

    A secondary gap: OpenAI and LiteLLM report cache/reasoning tokens under nested paths (prompt_tokens_details.cached_tokens, completion_tokens_details.reasoning_tokens), which get_value cannot traverse — those attributes are silently absent for non-Anthropic providers today. Tracked in #1074.

    Suggested action for #1054 (coverage parity audit): cross-check these three attribute names against the OTel GenAI semconv at the time Phase 1 lands, and rename to match the spec if it has caught up. If the spec still has no equivalent, add a comment in the code flagging them as Anthropic-specific extensions pending standardisation.

  6. added
    enhancement
    epic
    on May 20, 2026
  7. added
    p2
    on Jun 18, 2026
  8. removed this from the Release 0.7.0 milestone on Jul 13, 2026
  9. ajbozarth commented on Aug 4, 2026

    @ajbozarth
    Member

    Pasting some notes here for myself that came out of my planning for #1051 so I don't have to re-investigate this again for the Nth time


    Remaining backend-telemetry work — planning notes

    Findings from a scoping pass over the remaining epic issues. Core insight: #1209 is the only "look-forward" issue — it dictates the semconv names everything else must use. The additive issues (#1067/#1068/#1073) are peers that don't constrain each other, so they only need to look forward at #1209, not at each other.

    Issues in current epic order

    Plan of attack

    1. Do feat: streaming span events #1051 now (events mechanism + streaming events).
    2. Optionally fold in feat(telemetry): emit gen_ai.input/output.messages content events from tracing plugin (post-#1045) #1073 here, or defer it to reuse feat: streaming span events #1051's helpers (recommended — feat(telemetry): emit gen_ai.input/output.messages content events from tracing plugin (post-#1045) #1073 needs design first).
    3. Move feat(telemetry): adopt OTel GenAI semantic convention names for spans and metrics #1209 to next so we can stop "looking forward" — it's the only forward dependency that matters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/telemetryenhancementepicp2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions