Skip to content

Commit 69b4ce6

Browse files
authored
fix(telemetry): emit dev command telemetry before blocking (#1375)
* feat(telemetry): allow dynamic attribute merging * refactor: avoid killing the process on validation errors * fix(telemetry): capture dev validation failures by wrapping at top-level * fix: avoid defaulting to http protocol on telemetry failures * fix: remove redundant property check * feat(telemetry): support partial attribute overrides * refactor: leverage mutable recorder in favor of immutable returns
1 parent 6915c47 commit 69b4ce6

5 files changed

Lines changed: 394 additions & 223 deletions

File tree

integ-tests/dev-server.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('integration: dev server', () => {
8888
});
8989

9090
it.skipIf(!hasNpm || !hasGit || !hasUv)(
91-
'starts dev server and responds to health check',
91+
'starts dev server, responds to health check, and emits telemetry',
9292
async () => {
9393
expect(projectPath, 'Project should have been created').toBeTruthy();
9494

@@ -98,12 +98,21 @@ describe('integration: dev server', () => {
9898
devProcess = spawn('node', [cliPath, 'dev', '--port', String(port), '--logs'], {
9999
cwd: projectPath,
100100
stdio: 'pipe',
101-
env: { ...process.env, INIT_CWD: undefined },
101+
env: { ...process.env, INIT_CWD: undefined, ...telemetry.env },
102102
});
103103

104104
const serverReady = await waitForServer(port, 20000);
105105
expect(serverReady, 'Dev server should respond to ping within 20s').toBeTruthy();
106106

107+
// Verify telemetry was emitted for the server startup (before blocking)
108+
telemetry.assertMetricEmitted({
109+
command: 'dev',
110+
dev_action: 'server',
111+
ui_mode: 'terminal',
112+
exit_reason: 'success',
113+
});
114+
telemetry.clearEntries();
115+
107116
// Invoke the running server and verify telemetry
108117
const invokeResult = await runCLI(['dev', 'hello', '--port', String(port)], projectPath, {
109118
env: telemetry.env,
@@ -135,4 +144,27 @@ describe('integration: dev server', () => {
135144
},
136145
30000
137146
);
147+
148+
it.skipIf(!hasNpm || !hasGit || !hasUv)(
149+
'exits with error when runtime not found and emits failure telemetry',
150+
async () => {
151+
expect(projectPath, 'Project should have been created').toBeTruthy();
152+
153+
telemetry.clearEntries();
154+
const result = await runCLI(['dev', '--logs', '--runtime', 'nonexistent-agent'], projectPath, {
155+
env: telemetry.env,
156+
});
157+
158+
expect(result.exitCode).toBe(1);
159+
expect(result.stderr).toContain('nonexistent-agent');
160+
expect(result.stderr).toContain('not found');
161+
162+
telemetry.assertMetricEmitted({
163+
command: 'dev',
164+
dev_action: 'server',
165+
exit_reason: 'failure',
166+
});
167+
},
168+
15000
169+
);
138170
});

0 commit comments

Comments
 (0)