Repository navigation
Conversation
Adds a `Span` guard alongside the existing `[wt-trace]` command/instant
records. Construct with `let _span = Span::new("name");` at the top of a
block; the span fires when it goes out of scope, attributing the elapsed
time as a Complete event with category `wt`. The `log_enabled!` check
runs at drop time so spans constructed before `init_logging` still emit
correctly when their drop runs after the logger is up.
Reorders main.rs so `init_logging(verbose)` registers env_logger before
`init_command_log` runs. The latter spawns
`Repository::current()` → `git rev-parse --git-common-dir`; with the
previous order that subprocess fired before any logger was registered,
leaving a 4ms hole in the trace. Same reason `init_logging` itself
reorders so env_logger.init() runs before log_files::init().
Spans wired through alias dispatch:
- main.rs: `init_logging`, `init_command_log`
- repository/mod.rs: `resolve_git_common_dir`
- alias.rs: `try_alias`, `user_config_load`, `project_config_load`,
`load_aliases`, `referenced_vars`, `parse_alias_args`, `run_alias`,
`alias_approve`, `build_hook_context`, `prepare_steps`
- command_executor.rs: per-var spans inside `build_hook_context`
(`var_default_branch`, `var_primary_worktree`, `var_commit`,
`var_remote`); `template_render`; `execute_shell_command`
(Cmd::stream doesn't currently emit a `[wt-trace] cmd=` record, so we
span the call externally for now)
Parser + chrome-trace renderer extended for the new `span="..."` records.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
approved these changes
May 3, 2026
worktrunk-bot
approved these changes
May 3, 2026
max-sixty
added a commit
that referenced
this pull request
May 3, 2026
Three small consolidations in the trace-trigger surface, following up on #2539. ## What this changes **1. `Cmd::stream()` emits `[wt-trace] cmd=...` natively.** Previously only `Cmd::run()` and `Cmd::pipe_into()` emitted per-subprocess records — `stream()` was a hole, which #2539 patched with a `Span::new(\"execute_shell_command\")` wrapper at the foreground hook/alias call site. The two surrogates aren't equivalent: spans render under `cat: \"wt\"`, subprocess records under `cat: \"git\"`/`\"network\"`, and spans don't carry the `ok` flag, so hook/alias child status was invisible in chrome traces. Stream now emits a record at every exit point (spawn fail, stdin write, wait fail, signal-derived exit, SIGPIPE-as-success, non-zero status, success) via a small `WtTraceLog` helper that mirrors `ExternalCommandLog`'s shape. **2. Drops the `Span::new(\"execute_shell_command\")` workaround** in `commands/command_executor.rs`. With `Cmd::stream()` emitting natively, the wrapper is redundant — foreground hook/alias step time is now captured by the canonical subprocess record (cat=`git`/`network`/none) instead of a generic span (cat=`wt`). **3. Re-exports `trace::instant` from `trace::mod`** alongside `Span`. Deletes the `shell_exec::trace_instant` shim (a one-line re-export of `trace::emit::instant`) and migrates all 14 callers in `commands/picker/mod.rs` and `commands/list/collect/mod.rs` to `worktrunk::trace::instant`. Symmetric public API: `trace::Span` for scopes, `trace::instant` for milestones — neither lives under `shell_exec` anymore, since neither has anything to do with shell execution. ## Verification Smoke-tested with `RUST_LOG=debug wt <alias>`: `cmd=\"echo hello-from-stream\" ok=true` and `cmd=\"exit 7\" ok=false` both fire correctly. `Span(\"execute_shell_command\")` no longer appears in the trace. Full pre-merge hook (3430 tests + clippy + lints) passes locally. --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.
Adds in-process spans to the existing `[wt-trace]` infrastructure so per-phase wall-time is attributable, not just subprocess time. Until now subprocess records (`cmd="git …"`) accounted for child-process work; everything else — config load, repo open, template render, fork+exec wait — was opaque. The new `Span` RAII guard fills that gap.
What this adds
Pre-init subprocess visibility
Reorders `main.rs` so `init_logging(verbose)` (which registers env_logger) runs before `init_command_log` (which spawns `Repository::current()` → `git rev-parse --git-common-dir`). With the previous order that subprocess fired before any logger was registered, leaving a 4ms hole in the trace where the work actually ran. Same reason `init_logging` reorders internally so `env_logger.init()` runs before `log_files::init()`.
How to use
```bash
RUST_LOG=debug wt myalias 2>trace.log
wt-perf trace trace.log > trace.json
Open trace.json in https://ui.perfetto.dev
```
Spans nest as parent/child stacks in Perfetto. Subprocess records (`cat=git`) interleave with span records (`cat=wt`) so cold-cache attribution down to ~µs is straightforward.
Notable trade-off
`execute_shell_command` is spanned externally because `Cmd::stream()` doesn't currently emit a per-subprocess `[wt-trace] cmd=` record (only `Cmd::run()` does). The external span captures the wall-time correctly; replacing it with native `Cmd::stream` tracing is a follow-up.
🤖 Generated with Claude Code