Skip to content

chore(misc): richer telemetry for init and connect commands#35389

Open
jaysoo wants to merge 4 commits intomasterfrom
NXC-4262
Open

chore(misc): richer telemetry for init and connect commands#35389
jaysoo wants to merge 4 commits intomasterfrom
NXC-4262

Conversation

@jaysoo
Copy link
Copy Markdown
Member

@jaysoo jaysoo commented Apr 22, 2026

Current Behavior

nx init error telemetry is largely opaque: ~22% of starts land in a bare Command failed: npm install bucket, and ~5% record an empty errorMessage. We can't tell what's actually going wrong. nx connect has no start/error events at all — failures (missing remote, auth, network) go untracked.

Expected Behavior

Telemetry-only change. Child-process calls in init pipe stderr so the captured output reaches the error payload; error events now include errorName (from Node e.code or an extracted E…/ERR_… token like E404, ERESOLVE, EINTEGRITY, ERR_PNPM_*) and the same env context (nodeVersion, os, packageManager, isCI, aiAgent) as start events. toErrorString fixes the empty-message bucket. nx connect gains proper start/complete/error events.

No behavioral fixes — once the enriched data comes in we'll prioritize real fixes by actual failure distribution.

Related Issue(s)

Fixes NXC-4262

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit ee84b94
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69e941327042630008702579
😎 Deploy Preview https://deploy-preview-35389--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit ee84b94
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69e94132d2111c00080be177
😎 Deploy Preview https://deploy-preview-35389--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 22, 2026

View your CI Pipeline Execution ↗ for commit ee84b94

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 46m 44s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 4s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 22s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 29s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 8s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-22 22:35:05 UTC

@jaysoo jaysoo marked this pull request as ready for review April 22, 2026 19:45
@jaysoo jaysoo requested a review from a team as a code owner April 22, 2026 19:45
@jaysoo jaysoo requested a review from MaxKless April 22, 2026 19:45
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

const checkRemote = process.env.NX_SKIP_CHECK_REMOTE !== 'true';
await (
await handleImport('./connect-to-nx-cloud.js', __dirname)
).connectToNxCloudCommand({ ...args, checkRemote });
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.

Can you move this logic into connectToNxCloudCommand itself and keep this file as is?

@@ -3,6 +3,15 @@ import { handleImport } from '../../../utils/handle-import';
import { linkToNxDevAndExamples } from '../../yargs-utils/documentation';
import { nxVersion } from '../../../utils/versions';
import { withVerbose } from '../../yargs-utils/shared-options';
import { recordStat } from '../../../utils/ab-testing';
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.

we don't want to add these imports here because then it'll slow down every comand even if it's not connect

nx-cloud[bot]

This comment was marked as outdated.

`nx init` error telemetry is largely opaque: ~22% of starts land in a
bare `Command failed: npm install` bucket, and ~5% record an empty
`errorMessage`. We can't tell what's actually going wrong. `nx connect`
has no start/error events at all — failures (missing remote, auth,
network) go untracked.

Telemetry-only change. Child-process calls in init pipe stderr so the
captured output reaches the error payload; error events now include
`errorName` (from Node `e.code` or an extracted `E…`/`ERR_…` token
like `E404`, `ERESOLVE`, `EINTEGRITY`, `ERR_PNPM_*`) and the same env
context (`nodeVersion`, `os`, `packageManager`, `isCI`, `aiAgent`) as
start events. `toErrorString` fixes the empty-message bucket. `nx
connect` gains proper start/complete/error events.

No behavioral fixes — once the enriched data comes in we'll prioritize
real fixes by actual failure distribution.

Fixes NXC-4262
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

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

✅ The fix from Nx Cloud was applied automatically

We ran pnpm nx format to fix the format:check failure caused by unformatted code introduced in the telemetry changes. The two affected files — command-object.ts and utils.spec.ts — were not passed through Prettier before committing, which caused the CI format check to fail. These formatting-only changes will resolve the error without altering any logic.

Tip

We verified this fix by re-running nx-cloud record -- nx format:check.

Suggested Fix changes
diff --git a/packages/nx/src/command-line/init/command-object.ts b/packages/nx/src/command-line/init/command-object.ts
index d653bfdb..a5a015e4 100644
--- a/packages/nx/src/command-line/init/command-object.ts
+++ b/packages/nx/src/command-line/init/command-object.ts
@@ -92,7 +92,9 @@ export const yargsInitCommand: CommandModule = {
       // `stdio: 'pipe'`) so telemetry gets the real cause.
       const stderr = readErrorStderr(error).trim();
       const telemetryMessage = (
-        stderr ? `${errorMessage} | stderr: ${stderr.slice(-250)}` : errorMessage
+        stderr
+          ? `${errorMessage} | stderr: ${stderr.slice(-250)}`
+          : errorMessage
       ).slice(0, 500);
       // Structured code for bucketing. Prefer Node's `e.code` (set on
       // syscall failures); fall back to E-codes/ERR_* extracted from full
diff --git a/packages/nx/src/command-line/init/implementation/utils.spec.ts b/packages/nx/src/command-line/init/implementation/utils.spec.ts
index 4dc71987..63e57435 100644
--- a/packages/nx/src/command-line/init/implementation/utils.spec.ts
+++ b/packages/nx/src/command-line/init/implementation/utils.spec.ts
@@ -328,7 +328,9 @@ describe('utils', () => {
 
   describe('extractErrorName', () => {
     it('prefers Node e.code when set', () => {
-      expect(extractErrorName({ code: 'EACCES' }, 'stderr E404')).toBe('EACCES');
+      expect(extractErrorName({ code: 'EACCES' }, 'stderr E404')).toBe(
+        'EACCES'
+      );
     });
 
     it.each([

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.

Revert fix via Nx Cloud  

View interactive diff ↗

🎓 Learn more about Self-Healing CI on nx.dev

nx-cloud Bot and others added 3 commits April 22, 2026 20:56
Co-authored-by: jaysoo <jaysoo@users.noreply.github.com>
Addresses PR review: command-object.ts should not pull in ab-testing,
native (isAiAgent), utils helpers etc. at module load time — those run
for every nx command. Move the start/error telemetry and AI-mode error
output into the init-v2 outer handler, guarded by the `!inner` flag
so the downloaded-latest nx re-invocation does not double-record.
command-object.ts is now minimal again (yargs wiring only).

v1 path left untouched; slated for deletion in a follow-up.
Remove 5 PR-added comments that restated the code they sat above:
- configure-plugins.ts "Invoke the nx wrapper..." (try/catch makes it obvious)
- utils.ts "stderr piped so the error carries it..."
- utils.ts readErrorStderr JSDoc (self-describing)
- utils.ts extractErrorName JSDoc (self-describing)
- init-v2.ts "Structured code for bucketing..." (restates extractErrorName)

Kept the genuine "why" comments (selfRecord rationale, PII-stack drop,
toErrorString edge-case JSDoc, cursor-restore AI-agent caveat).
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