feat(render): show durations, error messages, and LLM details in the span tree#61
Open
dark-sorceror wants to merge 6 commits into
Open
feat(render): show durations, error messages, and LLM details in the span tree#61dark-sorceror wants to merge 6 commits into
dark-sorceror wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #54
The
traces getspan tree — the centerpiece of the human view — used to render exactly two things per span: name and an[ok]/[error]marker. No duration, no error text, no model/token/cost, even though all of that was already sitting in the payload the CLI had just fetched. A human asking "why was this trace slow" or "what actually failed" got zero signal from the tree and had to drop to--json | jq.This PR surfaces that data directly in the tree: per-span durations (right-aligned), error
status_messagebeneath failing spans, and a compact model/token/cost line under LLM spans.--jsonoutput is untouched — this is a human-view-only change.How it works
Each span line now computes its own duration from
span_start_time/span_end_timevia a sharedelapsedMshelper (lifted out oftraces/get.tsintoutil/index.tsso the tree renderer can use it too, without duplicating the zone-less-UTC parsing logic). A still-running span (nospan_end_time) falls back to elapsed-so-far against anowtimestamp the caller passes in —traces getcomputesnowonce and threads it through both the header's live-duration display andrenderTree, so the two never drift apart from separateDate.now()reads.Error spans append their trimmed, width-truncated
status_messageas a line directly beneath the span, indented to the child prefix and colored the same red as the marker (or plain when color is off). LLM spans (detected by presence ofmodel_name) get a dimmodel · tokens · costline, e.g.claude-sonnet-4-6 · 7.4k tok · $0.0309— tokens prefertotal_tokens, falling back toinput_tokens + output_tokens; tokens and cost are each omitted individually when unknown so a span with only a model name still renders that much.The renderer stays a pure, dependency-free string transform: no
Date.now()calls, no I/O —widthandnoware both passed in by the caller.Before
After
What's included
Renderer (
src/render/tree.ts)SpanLikeextended withspan_end_time,status_message,model_name,input_tokens/output_tokens/total_tokens,costRenderTreeOptions.width(default 80) — durations right-aligned to this column, error messages truncated to itRenderTreeOptions.now— ISO "now" instant for elapsed-so-far duration on still-running spans; omitted means no duration is shown rather than reading a fresh clocknow), right-aligned with a minimum 1-space gapstatus_messageline beneath[error]spans, red when color is on, truncated via the existing (previously-dead)truncate()helpermodel · N tok · $costdetail line beneath LLM spans, dim when color is onCommand (
src/commands/traces/get.ts)nowIsoand threads it into both the header's live-duration calculation andrenderTree'snowoption, so they can't disagreewidth: process.stdout.columns ?? 80intorenderTreeShared utility (
src/util/index.ts)elapsedMslifted out oftraces/get.ts(unchanged behavior) sotree.tscan share it instead of reimplementing zone-less-UTC-safe duration mathTests
tests/render/tree.test.ts— duration formatting/right-alignment (including the 80-column default and the minimum-1-space-gap edge case), elapsed-so-far viaoptions.now, error status_message with/without a message and on non-error spans, message truncation, LLM detail (total_tokens preferred over input+output sum, partial data, dim styling, no ANSI when color is off)tests/commands/traces-get.test.ts— end-to-end coverage thatrunGetsurfaces duration, error message, and LLM detail lines in the rendered outputtests/util.test.ts—elapsedMsunit tests (zone-less UTC handling, null end, unparseable input, negative-duration guard)Test plan
vitest— 617/617 passing, including new renderer tests for duration alignment, error message with/withoutstatus_message, missing end time, andNO_COLOR/non-TTY outputValueError: Intentional simulated API failure!beneath the failing span (see "After" tree above, from a real trace)claude-sonnet-4-6 · 7.4k tok · $0.0309-style detail--jsonoutput byte-identical to the base binary on both test tracesSummary by cubic
Show per-span durations, error messages, and compact LLM details in the
traces getspan tree. Makes slow or failing spans easy to spot;--jsonis unchanged.New Features
status_messageunder failing spans, colored when enabled; truncation keeps the line within the terminal width and drops the suffix when it can’t fit.model · N tok · $costwith sensible fallbacks.Refactors
elapsedMstosrc/util/index.tsand share it across the header and tree.widthand ISOnow; no I/O or clock reads.traces getcomputes onenowand passes it with terminal columns torenderTreeto avoid drift.Written for commit f5957cd. Summary will update on new commits.