Skip to content

feat(telemetry): implement CLI usage tracking#6691

Open
agusayerza wants to merge 2 commits into
masterfrom
agus/NAN-4555/cli-metrics
Open

feat(telemetry): implement CLI usage tracking#6691
agusayerza wants to merge 2 commits into
masterfrom
agus/NAN-4555/cli-metrics

Conversation

@agusayerza

@agusayerza agusayerza commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
  • Added telemetry support for CLI commands to track usage events.
  • Introduced device ID generation and storage for anonymous tracking.
  • Updated CLI options to enable/disable telemetry.
  • Created a new endpoint for receiving telemetry data on the server.
  • Enhanced headers in HTTP requests to include device ID for tracking.

This change aims to improve insights into CLI usage patterns while respecting user privacy preferences.

Review in cubic

@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

NAN-4555

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4 issues found across 14 files

Confidence score: 3/5

  • In packages/cli/lib/utils.ts, telemetry headers are computed at import time, so --no-telemetry cannot reliably suppress the device ID for normal CLI runs; merging as-is risks violating explicit user opt-out expectations — move header/device-id resolution to execution time after CLI flags are parsed.
  • In packages/cli/lib/index.ts, commandTelemetryEvents omits deploy and pull, which means two key workflows won’t be tracked and telemetry will be systematically incomplete after release — add explicit mappings for both commands before merging.
  • In packages/cli/lib/services/telemetry.service.ts, the catch path swallows delivery errors entirely, so dropped events become invisible and troubleshooting telemetry regressions is harder — add lightweight failure logging/metrics while keeping best-effort behavior.
  • In packages/server/lib/controllers/sync/deploy/postDeploy.ts, attaching device-id to team-authenticated track() events can create high-cardinality and account-linking side effects in PostHog; merging now may add noisy analytics dimensions and governance concerns — remove, hash, or gate this property before rollout.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/cli/lib/utils.ts Outdated
Comment thread packages/cli/lib/index.ts
Comment thread packages/cli/lib/services/telemetry.service.ts Outdated
Comment thread packages/server/lib/controllers/sync/deploy/postDeploy.ts
- Added telemetry support for CLI commands to track usage events.
- Introduced device ID generation and storage for anonymous tracking.
- Updated CLI options to enable/disable telemetry.
- Created a new endpoint for receiving telemetry data on the server.
- Enhanced headers in HTTP requests to include device ID for tracking.

This change aims to improve insights into CLI usage patterns while respecting user privacy preferences.
@agusayerza agusayerza force-pushed the agus/NAN-4555/cli-metrics branch from 6f20dcd to e292e88 Compare July 6, 2026 12:15
@agusayerza agusayerza marked this pull request as ready for review July 6, 2026 12:54
@agusayerza agusayerza requested a review from a team July 6, 2026 12:55
Comment thread packages/cli/lib/utils.ts Outdated
'User-Agent': getUserAgent()
};
if (!isTelemetryDisabled()) {
headers['Nango-CLI-Device-Id'] = getDeviceId();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

header is going to be attached on all requests. not just the one for telemetry. Is that on purpose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is intended. Idea being we can correlate the commands with an actual team/user once they do an auth call to the BE (deploy / pull)

Comment thread packages/cli/lib/utils.ts Outdated
}

export function isTelemetryDisabled(): boolean {
return process.env['TELEMETRY'] === 'false' || process.env['NANGO_CLI_TELEMETRY'] === 'false';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we have a conflict with another tool using TELEMETRY env var and disable it by accident?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed. Considering adding support for DO_NOT_TRACK https://donottrack.sh/ , although adoption isnt widespread

Comment thread packages/cli/lib/state.ts Outdated
let deviceId = state.get('deviceId') as string | undefined;
if (!deviceId) {
deviceId = randomUUID();
state.set('deviceId', deviceId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can this throw?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch

'cli:migrate_to_zero_yaml',
'cli:deploy',
'cli:pull'
]),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the enum should be shared with CliTelemetryEvent types

'cli:deploy',
'cli:pull'
]),
properties: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should properties be constrained?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed them. Original plan was to add additional information to track, but not currently used, so lets add it if we need it later down the line

@agusayerza agusayerza requested a review from a team July 7, 2026 14:11
// The `satisfies` above rejects entries that aren't valid `CliTelemetryEvent`s;
// the assertion below rejects any `CliTelemetryEvent` missing from this array.
// Together they keep the two lists in sync.
true satisfies [Exclude<CliTelemetryEvent, (typeof cliTelemetryEvents)[number]>] extends [never] ? true : never;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why is this file in utils package and not in server?

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