feat: add lightweight CLI telemetry#23
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds anonymous PostHog CLI telemetry: a telemetry client with persisted anonymousId, create-command tracking (success/failure with failure stages and properties), integration into the create command flow, telemetry exports, CI/build env vars, a runtime dependency, and README docs. Changes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
PR preview published
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: cfc45d6e-b281-47b1-b08b-49b4f017a582
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (8)
.github/workflows/publish.ymlREADME.mdpackage.jsonsrc/commands/create.tssrc/telemetry/client.tssrc/telemetry/create.tssrc/telemetry/index.tstsdown.config.ts
There was a problem hiding this comment.
♻️ Duplicate comments (2)
src/telemetry/client.ts (2)
37-41:⚠️ Potential issue | 🟠 MajorHonor telemetry opt-out flags by presence, not truthy value parsing.
Line 37-Line 41 currently requires
1|true|yes|on, soDO_NOT_TRACK=<any other value>still sends telemetry. For privacy kill switches, presence should disable.Proposed fix
function shouldDisableTelemetry(): boolean { if (TELEMETRY_API_KEY.length === 0) { return true; } if (isTruthyEnvValue(process.env.CI) || isTruthyEnvValue(process.env.GITHUB_ACTIONS)) { return true; } return ( - isTruthyEnvValue(process.env.CREATE_PRISMA_DISABLE_TELEMETRY) || - isTruthyEnvValue(process.env.CREATE_PRISMA_TELEMETRY_DISABLED) || - isTruthyEnvValue(process.env.DO_NOT_TRACK) + process.env.CREATE_PRISMA_DISABLE_TELEMETRY !== undefined || + process.env.CREATE_PRISMA_TELEMETRY_DISABLED !== undefined || + process.env.DO_NOT_TRACK !== undefined ); }
65-68:⚠️ Potential issue | 🟠 MajorValidate persisted
anonymousIdformat before reuse.Line 67 accepts any non-empty string from disk. If the file is edited/corrupted, non-anonymous identifiers can be sent as
distinctId.Proposed fix
+const UUID_V4_REGEX = + /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + async function getAnonymousId(): Promise<string> { const telemetryConfigPath = path.join(getTelemetryConfigDir(), TELEMETRY_CONFIG_FILE); try { const config = (await fs.readJSON(telemetryConfigPath)) as Partial<TelemetryConfig>; - if (typeof config.anonymousId === "string" && config.anonymousId.length > 0) { + if ( + typeof config.anonymousId === "string" && + UUID_V4_REGEX.test(config.anonymousId) + ) { return config.anonymousId; } } catch {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d3f1a915-5856-48c4-aec5-4ed7252b5f4a
📒 Files selected for processing (3)
README.mdsrc/telemetry/client.tssrc/telemetry/create.ts
Summary by CodeRabbit
New Features
Documentation
Chores