Conversation
Wraps every command (init/login/logout/whoami/build/start/dev) with a shared telemetry helper that emits cli_command_started, _completed, and _failed events. Distinct ID is derived from credentials.json (Auth0 sub or anonymousId), falling back to a locally generated UUID at ~/.arkor/telemetry-id when not signed in. Opt-out is honored unconditionally via DO_NOT_TRACK=1 or ARKOR_TELEMETRY_DISABLED=1: when set, the PostHog client is not instantiated and no network request is made. The PostHog project key is inlined at build time via tsdown's define, so local dev builds without ARKOR_POSTHOG_KEY ship with telemetry effectively disabled.
Greptile SummaryAdds PostHog telemetry to all CLI commands via a Confidence Score: 5/5Safe to merge; all remaining findings are P2 style/documentation issues that do not affect correctness. The telemetry implementation is solid: opt-out flags work correctly, errors are safely swallowed, the PostHog client is cleanly shut down, and test coverage is thorough. The only open findings are a minor README wording inaccuracy and a theoretical (low-probability) event-loss window for No files require special attention for merge. Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as CLI (main.ts)
participant WT as withTelemetry wrapper
participant GI as getIdentity()
participant PH as PostHog client
participant CMD as Command handler
CLI->>WT: call wrapped action
WT->>WT: isEnabled()? (checks env flags + POSTHOG_KEY)
alt telemetry disabled
WT->>CMD: handler(...args) directly
else telemetry enabled
WT->>GI: getIdentity()
GI-->>WT: { distinctId, authMode }
WT->>PH: capture cli_command_started
WT->>CMD: await handler(...args)
alt success + not longRunning
WT->>PH: capture cli_command_completed
else longRunning (dev)
Note over WT,PH: cli_command_completed skipped
else handler throws
WT->>PH: capture cli_command_failed
WT-->>CLI: rethrow error
end
end
CLI->>PH: shutdownTelemetry() [in finally block]
Reviews (3): Last reviewed commit: "feat(telemetry): enhance withTelemetry t..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d89b33234c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "esbuild": "^0.28.0", | ||
| "hono": "^4.7.0", | ||
| "open": "^10.0.0", | ||
| "posthog-node": "^5.30.6", |
There was a problem hiding this comment.
Use a PostHog SDK version compatible with supported Node versions
Adding posthog-node@^5.30.6 introduces an engine floor (^20.20.0 || >=22.22.0 in the lockfile) that is higher than this package’s declared support ("node": ">=22.6"), so users on Node 22.6–22.21 are now in an unsupported/install-failing state (hard failure with engine-strict, and undefined runtime support otherwise). Please either bump the package engine requirement to >=22.22 or pin a PostHog version that supports the advertised Node range.
Useful? React with 👍 / 👎.
| await handler(...args); | ||
| if (identity) { | ||
| safeCapture(identity.distinctId, "cli_command_completed", { | ||
| ...baseProps, | ||
| duration_ms: Date.now() - start, |
There was a problem hiding this comment.
Delay
cli_command_completed until long-running commands actually stop
This emits cli_command_completed immediately after the command handler resolves, which misreports long-lived commands like arkor dev: runDev() starts the server and returns, so telemetry records a very short duration_ms and a completed state while the process is still serving (and before late failures can surface). This skews command-duration analytics and completion/failure rates for long-running sessions.
Useful? React with 👍 / 👎.
…loor posthog-node 5.22.0 tightened its engines field to "^20.20.0 || >=22.22.0", which excludes Node 22.6 to 22.21.x even though arkor itself targets >=22.6. Pin to the last 5.21.x release so the dependency's supported Node range fully covers arkor's.
…engine floor" This reverts commit 78cf71f.
Added an option to the withTelemetry function to handle long-running commands, which skips the cli_command_completed event on success while still emitting cli_command_started. Updated related tests to verify this behavior.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82ca1705d0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // under vitest, where this transform doesn't run. | ||
| define: { | ||
| __SDK_VERSION__: JSON.stringify(pkg.version), | ||
| __ARKOR_POSTHOG_KEY__: JSON.stringify(process.env.ARKOR_POSTHOG_KEY ?? ""), |
There was a problem hiding this comment.
Pass ARKOR_POSTHOG_KEY into release builds
__ARKOR_POSTHOG_KEY__ is compiled to "" whenever ARKOR_POSTHOG_KEY is unset at build time, and isEnabled() hard-disables telemetry when that value is empty, so the published CLI will never emit telemetry unless the release build injects this env var. I checked .github/workflows/release.yaml and its Build step (pnpm run build) does not set ARKOR_POSTHOG_KEY, so this commit’s telemetry feature is effectively off in production packages.
Useful? React with 👍 / 👎.

Summary
init,login,logout,whoami,build,start,dev) via a sharedwithTelemetry()wrapper, emittingcli_command_started,cli_command_completed, andcli_command_failedevents.~/.arkor/credentials.json(Auth0suboranonymousId), with a UUID fallback at~/.arkor/telemetry-idwhen not signed in.DO_NOT_TRACK=1orARKOR_TELEMETRY_DISABLED=1short-circuits before the PostHog client is instantiated. The project key is injected at build time via tsdown'sdefine, so local dev builds (noARKOR_POSTHOG_KEY) ship with telemetry effectively disabled.Event schema
cli_command_startedcommand,sdk_version,node_version,platform,auth_modecli_command_completedduration_mscli_command_failedduration_ms,error_name,error_message(trimmed to 200 chars)Test plan
pnpm --filter arkor typecheckpnpm --filter arkor build(clean build with noARKOR_POSTHOG_KEYproduces a bundle that contains no key literal)pnpm --filter arkor buildwithARKOR_POSTHOG_KEY=phc_fake_key_for_testinjects the key oncepnpm --filter arkor test(16 new telemetry tests, 106 total pass)DO_NOT_TRACK=1 dist/bin.mjs whoamiruns cleanly with no PostHog activity even underARKOR_TELEMETRY_DEBUG=1ARKOR_POSTHOG_KEYinto the release workflow before the next published buildarkor whoamiinvocation producescli_command_started+cli_command_completedin the PostHog project, and that an intentionally failing command producescli_command_failed