Skip to content

scout traces show: span durations render ~1000x too small (bars, colors, slow-warning all dead) #26

Open

Description

@quinnmil

Problem

scout traces show renders every span's duration roughly 1000x too small, which silences the whole "where did the time go" visualization: progress bars, color thresholds, and the slow-span warning.

The API's span fields duration_ms / exclusive_duration_ms are actually reported in seconds, not milliseconds, despite the name. Confirmed by cross-checking a trace's duration_in_seconds against its root span's duration_ms — they're numerically identical, which they should not be if one were really 1000x the other.

$ scout traces show 12345 --app 6
Trace #12345 — Controller/users/index — 7.9s       # header: correct
 └── Middleware/Summary                        8ms  █░░░░░░░░░░░░░░░░░░░  # root span of the SAME trace

Root cause

internal/output/tree.go:

  • renderSpan calls FormatMs(span.DurationMs) directly on the raw API value, formatting seconds as if they were milliseconds ("8ms" for an 8-second span).
  • The bar-fill ratio span.DurationMs / totalMs is therefore always ≈0.001 regardless of the span's actual share of the trace, so filled is always forced to the 1-block minimum. This means:
    • Every span's bar looks identical.
    • The color thresholds (ratio > 0.5 yellow, > 0.8 red) can never trigger.
    • The ⚠ slow warning (also gated on ratio > 0.5) is unreachable.

internal/output/format_mb_test.go's TestRenderSpanTreeMemoryFooter currently constructs a TraceSpan with DurationMs: 500 alongside DurationInSeconds: 0.5 on the parent trace — i.e. it bakes in the same wrong assumption and will need updating alongside the fix.

Fix

Scale span.DurationMs / span.ExclusiveDurationMs by 1000 when consuming them (either at the API boundary in internal/api/types.go's TraceSpan, or at the point of use in renderSpan), and rename the struct fields/doc comments to make the actual unit (seconds) explicit rather than relying on a misleading _ms suffix from the API. Add a regression test asserting the header duration and the sum of top-level span durations are on the same order of magnitude.

Found during

A pre-1.0 audit of the whole CLI against a live account (see internal discussion — not filed verbatim here to avoid pasting live production data into a public issue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions