fix(docs): restore telemetry and root pre-run for docs commands - #1982
Merged
Conversation
`stripe docs` declared its own PersistentPreRunE, a shape it inherited from the docs plugin it was inlined from in v1.43.3. Cobra runs only the closest PersistentPreRun hook in the chain, so that declaration shadowed the root command's hook and silently disabled, for every command under `stripe docs`: - command-invocation telemetry and all of its metadata (merchant, command path, user agent, machine UUID, flags) - config file migration - --access-base validation, and the OAuth access base URL that the token refresher inside ResolveCredentials depends on - Sentry command context via reporting.SetCommandPath - the legacy profile name warning The telemetry gap is measurable: of 14,266 `stripe docs` telemetry events in a recent 7-day window, 14,264 came from pre-1.43.3 builds and none from any release at or after 1.43.3, while `/v2/docs/page` traffic from 1.45+ clients grew steadily and went entirely unrecorded. Normalize the tree to match every other command in the CLI, none of which declares a pre-run hook: move the docs setup out of PersistentPreRunE and into RunE through a withSetup wrapper, the same place runListenCmd does its post-flag validation. This leaves the PersistentPreRun slot to the root command, so docs gets telemetry for free like everything else. Note this restores `Command Invoked` events only. Docs page fetches still emit no `API Request` events, because pkg/docs/client.go uses its own http.Client rather than the instrumented pkg/stripe client. That is a separate change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Committed-By-Agent: claude
joelzwarrington
approved these changes
Sep 2, 2026
hngo-stripe
approved these changes
Sep 2, 2026
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.
Problem
stripe docsdeclares its ownPersistentPreRunE(pkg/cmd/docs/root.go) — a shape it inherited from the docs plugin it was inlined from in v1.43.3 (#1663). In a standalone plugin binary that's correct: there's no CLI root above you, so nothing is shadowed.Inside the CLI it is not. Cobra runs only the closest
PersistentPreRunhook in the chain (EnableTraverseRunHooksis off), so that declaration shadowsrootCmd.PersistentPreRunEand silently disables, for every command understripe docs:--access-basevalidation, plus the OAuth access base URL that the token refresher insideResolveCredentialsrelies onreporting.SetCommandPath(bears on Stop Sentry noise from rate-limit errors and fix uninformative issue titles #1970)stripe docsis currently the only command in the CLI that declares a pre-run hook, which is why it's the only one affected.Reproducing
Only the root hook rejects a non-Stripe
--access-base, so it makes a clean probe:Rejected for
config, silently accepted fordocs.Fix
Normalize the docs tree to match every other command in the CLI, none of which declares a pre-run hook. The setup moves out of
PersistentPreRunEand intoRunEvia awithSetupwrapper — the same placerunListenCmddoes its post-flag--api-basevalidation. That leaves thePersistentPreRunslot to the root command, so docs gets telemetry for free like everything else.Setup still runs after flag parsing and before the command body, so behavior is unchanged; it simply no longer occupies a slot it was never entitled to. The root hook now also runs before docs resolves credentials, which is the correct order — it is what validates and publishes the access base URL the OAuth refresher uses.
Considered and rejected:
cobra.EnableTraverseRunHooks = true(fixes the class, but changes hook semantics for every command to fix one), and having the docs hook reach up to invoke its ancestor's (contained, but inverted control flow that the next inlined plugin has to remember to repeat).Scope
This restores
Command Invokedevents. Docs page fetches still emit noAPI Requestevents, becausepkg/docs/client.gobuilds its ownhttp.Clientinstead of using the instrumentedpkg/stripeclient, soSendAPIRequestEventis never reached. That's a separate change.Testing
TestDocsRunsRootPersistentPreRun, which uses the--access-baseprobe through a nested subcommand (docs prefs list) so the hook is reached through more than one parent. Verified it fails on master and passes with this change.go test ./pkg/cmd/ ./pkg/cmd/docs/...passes, exceptTestSearchCommand, which fails identically on master (unrelated, pre-existing, and not agent-env dependent).stripe docsandstripe docs prefs liststill work normally.🤖 Generated with Claude Code