Skip to content

[FEATURE] Add /traces shortcut and infer traces command (local span-tree viewer) #903

Description

@edenreich

Summary

PR #901 (towards #893) records the traces signal locally: every session writes a per-session
~/.infer/telemetry/<session>-traces.jsonl with a session root span, chat <model> spans per
LLM turn, and execute_tool <name> spans per tool call. Nothing in the CLI renders them yet -
the only consumer today is an OTLP collector, which most users don't run.

Add a local span-tree viewer, paired the same way infer stats / /stats are:

  • infer traces [session-id] - render the span tree of a session (default: the most recent one)
    from the local trace file, with durations, so per-run latency questions ("what took 27s in that
    run?") are answerable without any collector:
session (standard, success)                    42.1s
|-- chat deepseek/deepseek-v4-flash             3.2s
|-- execute_tool Read                           9ms
|-- chat deepseek/deepseek-v4-flash             2.8s
`-- execute_tool Bash                          27.5s
  • /traces [session-id] - the same view as a chat shortcut (markdown output), matching the
    internal/shortcuts/stats.go pattern.

This is read-only over the existing -traces.jsonl format (one stdouttrace span stub JSON object
per line, already parsed by internal/telemetry/tracer_test.go::readSpans). Once subprocess span
ingestion lands (#904), child-process spans appear in this view automatically as children of
their tool span - no viewer changes needed.

Acceptance Criteria

  • infer traces [session-id] renders the span tree (root -> LLM turns -> tool calls) with per-span durations from the local per-session trace file; with no argument it picks the most recent session.
  • infer traces --list (or equivalent) enumerates sessions that have trace files, so a session id can be found without ls-ing the telemetry dir.
  • /traces [session-id] chat shortcut renders the same tree as markdown, mirroring the stats command/shortcut pairing.
  • --format json emits the tree as structured output.
  • Spans with error status / error.type are visibly marked.
  • Works fully offline from local files; no OTLP endpoint required; no prompt/response content displayed beyond existing span names/attributes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for Feature.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions