Skip to content

feat: add lightweight CLI telemetry#23

Merged
AmanVarshney01 merged 5 commits intomainfrom
aman/add-telemetry
Mar 17, 2026
Merged

feat: add lightweight CLI telemetry#23
AmanVarshney01 merged 5 commits intomainfrom
aman/add-telemetry

Conversation

@AmanVarshney01
Copy link
Member

@AmanVarshney01 AmanVarshney01 commented Mar 16, 2026

Summary by CodeRabbit

  • New Features

    • Anonymous CLI telemetry for the create command: tracks completions, failures, failure stages, and durations.
  • Documentation

    • Added telemetry docs describing what is collected, privacy exclusions, persistence behavior, and how to disable telemetry.
  • Chores

    • Added PostHog runtime dependency and exposed telemetry-related environment variables for CI preview and release workflows.

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e0db83bb-a8e6-4a02-8ad7-49e661fcd2a8

📥 Commits

Reviewing files that changed from the base of the PR and between e8d6c71 and cd056d8.

📒 Files selected for processing (1)
  • src/telemetry/client.ts

Walkthrough

Adds 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

Cohort / File(s) Summary
Telemetry implementation
src/telemetry/client.ts, src/telemetry/create.ts, src/telemetry/index.ts
New PostHog telemetry client with platform-aware anonymousId persistence and safe reporting; create-specific tracking functions trackCreateCompleted and trackCreateFailed; exported CreateTelemetryFailureStage.
Create command integration
src/commands/create.ts
Modifies create flow to record start time, propagate structured ExecuteCreateContextResult (ok/failed with stage), track failure stages/duration, and emit telemetry on success or failure instead of throwing from inner steps.
Build/config & CI
.github/workflows/publish.yml, tsdown.config.ts
Adds environment variables CREATE_PRISMA_TELEMETRY_API_KEY and CREATE_PRISMA_TELEMETRY_HOST to CI workflow and build config (host default provided).
Dependencies
package.json
Adds runtime dependency posthog-node (4.18.0).
Docs
README.md
Adds a telemetry documentation block describing anonymous PostHog telemetry for create runs, privacy exclusions, and disable flags.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a lightweight CLI telemetry feature across multiple files including telemetry client, create flow tracking, and environment configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aman/add-telemetry
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 16, 2026

PR preview published

  • Version: 0.2.0-pr.23.32.1
  • Tag: pr23
  • Run with Bun: bunx create-prisma@pr23
  • Run with npm: npx create-prisma@pr23
  • Run with Yarn: yarn dlx create-prisma@pr23
  • Run with pnpm: pnpm dlx create-prisma@pr23
  • Run with Deno: deno run -A npm:create-prisma@pr23
  • Workflow run: https://github.com/prisma/create-prisma/actions/runs/23153207841

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cfc45d6e-b281-47b1-b08b-49b4f017a582

📥 Commits

Reviewing files that changed from the base of the PR and between 87fb49e and dc6ecaf.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .github/workflows/publish.yml
  • README.md
  • package.json
  • src/commands/create.ts
  • src/telemetry/client.ts
  • src/telemetry/create.ts
  • src/telemetry/index.ts
  • tsdown.config.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
src/telemetry/client.ts (2)

37-41: ⚠️ Potential issue | 🟠 Major

Honor telemetry opt-out flags by presence, not truthy value parsing.

Line 37-Line 41 currently requires 1|true|yes|on, so DO_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 | 🟠 Major

Validate persisted anonymousId format 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

📥 Commits

Reviewing files that changed from the base of the PR and between dc6ecaf and 0c14fa0.

📒 Files selected for processing (3)
  • README.md
  • src/telemetry/client.ts
  • src/telemetry/create.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0fda0710-a8ce-400e-b12a-ae7379372d55

📥 Commits

Reviewing files that changed from the base of the PR and between 0c14fa0 and e8d6c71.

📒 Files selected for processing (1)
  • src/telemetry/client.ts

@AmanVarshney01 AmanVarshney01 merged commit 26644af into main Mar 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants