Refactor command telemetry#198
Conversation
fdcc03d to
d4709a1
Compare
anisaoshafi
left a comment
There was a problem hiding this comment.
LGTM, much simpler 🚀
Question: I wasn't aware we want to track "lstk" differently from "lstk start". Why do we want to check them separately? I assume we need to adjust the dashboard queries so that start events count "lstk" in addition to "lstk start".
In AGENTS.md this part needs to be removed: "Wrap the command's RunE with commandWithTelemetry(name, tel, fn) — this handles timing, exit code, and error message automatically".
Good point. The different command name comes for free with the refactoring, and I assumed it would be better to have this added visibility over
I cannot find this string in AGENTS.md, is it Claude or myself hallucinating 🙃? |
@carole-lavillonniere sorry, my bad. I meant in add-commands/SKILL.md |
There was a problem hiding this comment.
Thank you for following up on this @carole-lavillonniere! To me this is much cleaner now and objectively better!
- Telemetry is now treated as a cross-cutting concern. By centralizing instrumentation in root.go, the individual commands (like aws, logs, or status) don't need to know that they are being timed or tracked.
- Adding a new command is now simpler. You don't have to worry about telemetry wiring, the framework handles it automatically.
- The use of recursive command wrapping ensures 100% coverage. Every command in the tree is now automatically instrumented with basic telemetry (execution time, exit code, flags), which makes analytics much more reliable.
I would consider adding a way to disable telemetry for individual commands that we may not want to track, once that need comes up.
| In `cmd/root.go`, add the new command to `root.AddCommand(...)`. | ||
|
|
||
| If the command constructor needs dependencies (like `*env.Env` or `*telemetry.Client`), add them as parameters matching the existing pattern. | ||
| If the command constructor needs dependencies (like `*env.Env`), add them as parameters matching the existing pattern. |
There was a problem hiding this comment.
praise: updating skills is sometimes forgotten! great that you keep it up to date with every change 🙌
There are two separate things we might want to understand from the
In either case, we need to be careful with In terms of implementation, #1 is most important for me to track, so I don't mind whether differentiation is done but want to be sure counting is correct. #2 is nice to have. |
fae84d9 to
ef2abb5
Compare
Thanks @mmaureenliu, and @anisaoshafi for bringing attention to the matter. |
Refactoring addressing suggested improvement #2 from @thrau in this comment #127 (review)
Changes
commandWithTelemetrydecorator and per-command manual telemetry with a singleinstrumentCommandsfunction inroot.gothat walks the Cobra command tree and wraps everyRunEautomaticallycmd.CommandPath()(stripping thelstkprefix) — no more hardcoded strings that can drift*telemetry.Clientfrom constructors that only needed it for the decorator (logout, status, logs, setup, config, volume, update, aws); kept where still needed for lifecycle events (start, stop, restart) or token updates (login)Deviation from the suggestion
The PR instead captures
startTimedirectly inside theRunEclosure ininstrumentCommands. This is simpler because local to the closure and there is no shared state needed.telmust still be passed to constructors for commands that do more things with it: emitting lifecycle events, updating auth token.Change in telemetry data
Before this change
lstk(without subcommand) andlstk startboth emittedcommand="start"and could not be differentiated in telemetry. Nowlstkemits"lstk"instead.