Skip to content

Track deployment commands in posthog#145

Merged
Fermionic-Lyu merged 3 commits into
mainfrom
codex/deployments-posthog-tracking
May 28, 2026
Merged

Track deployment commands in posthog#145
Fermionic-Lyu merged 3 commits into
mainfrom
codex/deployments-posthog-tracking

Conversation

@Fermionic-Lyu
Copy link
Copy Markdown
Member

@Fermionic-Lyu Fermionic-Lyu commented May 27, 2026


Summary by cubic

Add PostHog tracking for all deployment CLI commands to measure usage and outcomes. Each command emits a cli_deployments_invoked event with success status and key props, and analytics are flushed safely.

  • New Features

    • Added trackDeployments in src/lib/analytics.ts to send cli_deployments_invoked with subcommand, project/org/region info, and oss_mode.
    • Added trackDeploymentUsage in src/commands/deployments/utils.ts to read project config, merge custom props, and call shutdownAnalytics in a finally block.
    • Instrumented deploy, status, list, cancel, and env [list|set|delete] with success/failure and props (e.g., has_env, has_meta, ready, sync).
    • Replaced reportCliUsage with the new tracker for deployment commands.
  • Refactors

    • Simplified telemetry cleanup to always run shutdownAnalytics; aligned approach in src/commands/payments/utils.ts.
    • Bumped @insforge/cli version to 0.1.85.

Written for commit 17c3bbd. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Chores
    • Added usage tracking across deployment commands (cancel, deploy, env list/set/delete, list, status) to record success/failure and relevant flags.
    • Introduced shared telemetry support and a deployments analytics helper.
    • Minor telemetry refactor for payments to consolidate config retrieval and tracking.
    • Bumped CLI package version.

Review Change Stack

Note

Track deployment command invocations as PostHog analytics events

  • Adds a new trackDeployments function in src/lib/analytics.ts that emits a cli_deployments_invoked event with project metadata (org, region, OSS mode).
  • Introduces a trackDeploymentUsage utility in src/commands/deployments/utils.ts that wraps trackDeployments, records success/failure, and always flushes analytics via shutdownAnalytics.
  • Replaces the previous reportCliUsage calls in deploy, cancel, list, status, and env-vars subcommands with trackDeploymentUsage, passing subcommand-specific properties (e.g. has_env, has_meta, ready, sync).

Changes since #145 opened

  • Modified telemetry tracking flow in env list and deployments list subcommands [2939963]
  • Refactored error handling in trackDeploymentUsage and trackPaymentUsage utility functions [2939963]
  • Bumped package version from 0.1.84 to 0.1.85 [17c3bbd]

Macroscope summarized 47ce5c0.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0ce20ee3-4570-4f95-8c07-017e72d461d8

📥 Commits

Reviewing files that changed from the base of the PR and between 2939963 and 17c3bbd.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json

Walkthrough

Deployment commands now emit structured usage analytics through a new trackDeploymentUsage helper. A shared utility and analytics function capture subcommand names, success/failure status, and contextual properties, replacing prior reportCliUsage calls across cancel, deploy, env-vars, list, and status commands.

Changes

Deployment Usage Analytics

Layer / File(s) Summary
Analytics foundation
src/commands/deployments/utils.ts, src/lib/analytics.ts
Adds trackDeploymentUsage helper and trackDeployments analytics function; loads project config, emits cli_deployments_invoked events, suppresses telemetry errors, and always calls shutdownAnalytics() in finally.
Command tracking integration
src/commands/deployments/cancel.ts, src/commands/deployments/deploy.ts, src/commands/deployments/env-vars.ts, src/commands/deployments/list.ts, src/commands/deployments/status.ts
All deployment subcommands now call trackDeploymentUsage with subcommand name and success flag on both success and error paths. Deploy and env subcommands include flags/properties (--env, --meta, ready, sync) where applicable.

Payments formatting (minor)

Layer / File(s) Summary
Payments telemetry try-block formatting
src/commands/payments/utils.ts
Moves getProjectConfig() and trackPayments(...) into the existing try block for formatting/structure; behavior and error handling unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • InsForge/CLI#130: Both PRs modify package.json by bumping the @insforge/cli version number (different target versions though).
  • InsForge/CLI#131: Both PRs modify the shared PostHog analytics layer (src/lib/analytics.ts) by adding new CLI telemetry helpers and relying on shutdownAnalytics() around command execution (deployments tracking vs config tracking).

Suggested reviewers

  • jwfing

Poem

I nibble at logs with a twitch and a twitch,
Hopping through flags and the output switch,
Deploys, lists, cancels — I tally each cheer,
Sending soft pings that the dashboard can hear,
A rabbit with PostHog, happy and rich. 🐇📈

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding PostHog analytics tracking to deployment commands across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/deployments-posthog-tracking

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

Copy link
Copy Markdown
Member

@jwfing jwfing left a comment

Choose a reason for hiding this comment

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

Code Review — Track deployment commands in PostHog

Summary: Clean, focused instrumentation PR that migrates deployment commands from reportCliUsage to a richer PostHog tracker. No blocking issues found.

Requirements context: No /docs/superpowers/ directory exists in this repo. Assessment is based on the PR description and the surrounding code patterns established by existing analytics helpers (trackDiagnose, trackPayments, trackConfig).


Findings

Critical

(none)

Suggestion

Software Engineering — Missing tests for new utils.ts helper

src/commands/deployments/utils.ts introduces trackDeploymentUsage, but no test file is present — the project otherwise has full test coverage of analytics-adjacent helpers (see src/lib/skills.test.ts testing reportCliUsage). Per TDD convention, the following cases should be covered:

  • Happy path: getProjectConfig() returns a config → trackDeployments + shutdownAnalytics are called.
  • No-config path: getProjectConfig() returns null → neither trackDeployments is called, shutdownAnalytics still runs.
  • Error inside inner try: swallowed, shutdownAnalytics still runs.

A test for utils.ts would mirror the existing pattern in src/lib/skills.test.ts and give confidence that future refactors don't accidentally propagate analytics errors into command failures.


Information

Software Engineering — Redundant outer try wrapper in utils.ts:14-28

// utils.ts (current)
try {
  try {
    const config = getProjectConfig();
    if (config) {
      trackDeployments(subcommand, config, { success, ...properties });
    }
  } catch {
    // Telemetry should never affect command behavior.
  }
} finally {
  await shutdownAnalytics();
}

The outer try has no matching catch, so it adds no error-isolation — exceptions from shutdownAnalytics in the finally still propagate (although shutdownAnalytics internally swallows its own errors). Simplify to:

try {
  const config = getProjectConfig();
  if (config) {
    trackDeployments(subcommand, config, { success, ...properties });
  }
} catch {
  // Telemetry should never affect command behavior.
} finally {
  await shutdownAnalytics();
}

Functionality — Duplicate trackDeploymentUsage call in early-return branches

In src/commands/deployments/list.ts:36,50 and src/commands/deployments/env-vars.ts:38,52, trackDeploymentUsage(..., true) appears both in the early-return "empty results" branch and at the end of the normal path. These branches are mutually exclusive so there is no double-fire, but the duplication is easy to trip over in future edits. Consider restructuring so that tracking always happens in one place after the branching logic completes.


Functionality — Failure events silently dropped when project is not linked

trackDeploymentUsage in utils.ts:16-20 sends the event only when config is truthy. For commands that call requireAuth() before reading the config (e.g., cancel.ts), if auth throws before the config is loaded, the failure path calls trackDeploymentUsage('cancel', false) with getProjectConfig() returning null — so the error event is silently dropped. This is probably intentional (no project ID = no way to attribute the event), but it means auth-failure rates for deployment commands will not appear in the analytics. If that data is wanted, consider falling back to FAKE_PROJECT_ID (the same pattern trackConfig uses in src/lib/analytics.ts:107).


Verdict

approved (informational — human approval still required via the GitHub approve flow)

No correctness, security, or data-loss issues found. The implementation follows the existing pattern established by trackDiagnose and trackPayments. Adding tests for the new utils.ts helper would close the only meaningful gap.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR adds PostHog analytics tracking to all five deployment CLI subcommands (deploy, cancel, status, list, env [list|set|delete]) by introducing a new trackDeployments analytics function and a shared trackDeploymentUsage utility, mirroring the existing payments analytics pattern.

  • New trackDeployments in src/lib/analytics.ts emits a cli_deployments_invoked event with project/org/region metadata and an oss_mode flag, consistent with trackPayments.
  • New trackDeploymentUsage in src/commands/deployments/utils.ts wraps telemetry in a try/catch/finally so it can never surface errors to users; shutdownAnalytics is idempotent and safe to call from both success and catch call sites.
  • Early-return removal in env-vars.ts and list.ts converts empty-list guards from return statements to else if branches, ensuring telemetry is captured for the empty-result case as well.

Confidence Score: 5/5

Safe to merge — changes are additive telemetry instrumentation that cannot throw or alter command output.

The implementation is structurally identical to the already-shipped payments analytics, shutdownAnalytics is guarded against double-invocation, and all error paths are swallowed by the catch block in trackDeploymentUsage. No logic that affects command correctness, user output, or error handling has changed beyond the intentional early-return removal in the list/env-vars commands.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/analytics.ts New trackDeployments function added; mirrors the existing trackPayments pattern exactly, including oss_mode detection, property spreading, and the same captureEvent call signature.
src/commands/deployments/utils.ts New shared trackDeploymentUsage helper; correctly wraps telemetry in try/catch/finally, and shutdownAnalytics is idempotent so no double-shutdown risk even when called from both success and catch paths.
src/commands/deployments/deploy.ts Replaces reportCliUsage with trackDeploymentUsage; success path captures has_env, has_meta, and ready from an already-resolved result object — all accesses are safe at that point in the flow.
src/commands/deployments/cancel.ts Straightforward instrumentation added; only one of the two trackDeploymentUsage paths runs per execution since the helper itself never throws.
src/commands/deployments/env-vars.ts Removes early return on empty env-var list, converting it to an else if branch so telemetry is now captured in the empty-list case; behavioral improvement.
src/commands/deployments/list.ts Same early-return removal as env-vars.ts; empty-deployments case now reports telemetry consistently.
src/commands/deployments/status.ts Adds trackDeploymentUsage in both success and catch paths with sync flag; opts is Commander-provided and safe to access in the catch block.
src/commands/payments/utils.ts Refactored from double-nested try/catch to a flat try/catch/finally, matching the new deployment helper pattern; semantics are identical.

Sequence Diagram

sequenceDiagram
    participant User
    participant Command as CLI Command<br/>(cancel/deploy/status/list/env-vars)
    participant Util as trackDeploymentUsage<br/>(deployments/utils.ts)
    participant Analytics as trackDeployments<br/>(lib/analytics.ts)
    participant PostHog

    User->>Command: run subcommand
    Command->>Command: execute business logic
    alt success
        Command->>Util: trackDeploymentUsage(subcmd, true, props)
    else error
        Command->>Util: trackDeploymentUsage(subcmd, false, props)
    end
    Util->>Util: getProjectConfig()
    alt project linked
        Util->>Analytics: "trackDeployments(subcmd, config, {success, ...props})"
        Analytics->>PostHog: captureEvent(project_id, 'cli_deployments_invoked', ...)
    else project not linked
        Util-->>Util: skip (no event emitted)
    end
    Util->>Analytics: shutdownAnalytics()
    Analytics->>PostHog: client.shutdown()
    Command->>Command: handleError(err) [if error path]
Loading

Reviews (3): Last reviewed commit: "bump version" | Re-trigger Greptile

Comment thread src/commands/deployments/utils.ts
Comment thread src/commands/deployments/utils.ts Outdated
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

Re-trigger cubic

Copy link
Copy Markdown
Member

@jwfing jwfing left a comment

Choose a reason for hiding this comment

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

LGTM, approved.

@Fermionic-Lyu Fermionic-Lyu merged commit 6a0502b into main May 28, 2026
3 of 4 checks passed
@Fermionic-Lyu Fermionic-Lyu deleted the codex/deployments-posthog-tracking branch May 28, 2026 00:25
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.

2 participants