Skip to content

refactor(trace): dynamic span names + share WtTraceLog across Cmd modes - #2555

Merged
max-sixty merged 1 commit into
mainfrom
trace
May 3, 2026
Merged

max-sixty merged 1 commit into
mainfrom
trace

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Two follow-ups from #2554.

Dynamic span names

Span::new now accepts impl Into<Cow<'static, str>>. Literals stay borrowed, format!(...) produces an owned span — useful when the name carries dynamic context.

Threaded through the alias/hook surface so chrome traces can finally attribute time per pipeline:

  • try_alias → try_alias:{name}
  • run_alias → run_alias:{name}
  • prepare_steps → prepare_steps:{alias}
  • template_render → template_render:{cmd.label}, with the concurrent-group span moved into the .map() closure (per-command render now gets its own span; the previous single span covering the whole map hid per-command attribution).

Cmd::run / Cmd::pipe_into share WtTraceLog

WtTraceLog (introduced in #2554 for Cmd::stream) gains a record_result(&Result<Output>) helper that does trace + log_output. Cmd::run and Cmd::pipe_into now construct WtTraceLog::new(...) instead of computing t0/ts/tid manually and calling the standalone log_command_result.

pipe_into emits each child's record inside thread::scope right after that child reaps — drops the explicit per-child dur_us capture and the post-scope emission step. End times are now recorded at reap rather than scope-exit (slightly more accurate). Trace tools sort by ts so the change in log-line order is invisible to them.

log_command_result deleted. All three Cmd modes share one emission path.

Net: -36 lines.

This was written by Claude Code on behalf of @max-sixty

Two follow-ups from #2554, surfaced as deferred items at merge time.

## Dynamic span names

`Span::new` now accepts `impl Into<Cow<'static, str>>` instead of
`&'static str`. Literals stay borrowed (allocation-free), and
`format!(...)` produces an owned span — useful when the name carries
dynamic context.

Threading that through the alias/hook surface:

- `try_alias` → `try_alias:{name}`
- `run_alias` → `run_alias:{name}`
- `prepare_steps` → `prepare_steps:{alias}`
- `template_render` → `template_render:{cmd.label}`, with the
  concurrent-group span moved into the `.map()` closure so each
  per-command render gets its own span (the previous single span
  hid per-command attribution).

This unblocks per-pipeline attribution in chrome traces — previously
all aliases shared the same span names so timeline tools couldn't tell
them apart.

## `Cmd::run` and `Cmd::pipe_into` share `WtTraceLog`

`WtTraceLog` (introduced in #2554 for `Cmd::stream`) gains a
`record_result(&Result<Output>)` helper that emits the trace record and
surfaces captured stdout/stderr to the debug log. `Cmd::run` and
`Cmd::pipe_into` now use it instead of computing `t0`/`ts`/`tid`
manually and calling the standalone `log_command_result`.

`pipe_into` emits each child's record inside the `thread::scope` right
after that child reaps, dropping the explicit per-child `dur_us`
capture and post-scope batching. End times in the trace are now
slightly more accurate (recorded at reap, not after scope exit). Trace
tools sort by `ts` so log line order doesn't matter.

Net: the standalone `log_command_result` helper is gone; all three
`Cmd` modes share one emission path.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 72176e5 into main May 3, 2026
27 checks passed
@max-sixty
max-sixty deleted the trace branch May 3, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants