Skip to content

Commit 94547e7

Browse files
committed
feat: instrument telemetry for dev command
Add telemetry recording to the dev command across all execution paths: - Invoke: wrapped with withCommandRunTelemetry, emits on success/failure - Exec: wrapped with withCommandRunTelemetry for container exec - Server modes (--logs, --no-browser, browser): emit on SIGINT/exit Schema changes: - Expand Action enum to include 'exec' - Add UiMode enum ('browser' | 'terminal') - Add 'agui' to Protocol enum - Add ui_mode field to DevAttrs Refactored invoke helpers to throw instead of process.exit(1) so telemetry wrapper can record failures before exit. Attributes emitted: action, ui_mode, has_stream, protocol, invoke_count
1 parent ce00f57 commit 94547e7

5 files changed

Lines changed: 265 additions & 106 deletions

File tree

integ-tests/dev-server.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { runCLI } from '../src/test-utils/index.js';
1+
import { createTelemetryHelper, runCLI } from '../src/test-utils/index.js';
22
import { type ChildProcess, execSync, spawn } from 'node:child_process';
33
import { randomUUID } from 'node:crypto';
44
import { mkdir, rm } from 'node:fs/promises';
@@ -38,6 +38,8 @@ describe('integration: dev server', () => {
3838
let projectPath: string;
3939
let devProcess: ChildProcess | null = null;
4040

41+
const telemetry = createTelemetryHelper();
42+
4143
beforeAll(async () => {
4244
testDir = join(tmpdir(), `agentcore-integ-dev-${randomUUID()}`);
4345
await mkdir(testDir, { recursive: true });
@@ -81,6 +83,7 @@ describe('integration: dev server', () => {
8183
if (devProcess) {
8284
devProcess.kill('SIGKILL');
8385
}
86+
telemetry.destroy();
8487
await rm(testDir, { recursive: true, force: true });
8588
});
8689

@@ -101,6 +104,31 @@ describe('integration: dev server', () => {
101104
const serverReady = await waitForServer(port, 20000);
102105
expect(serverReady, 'Dev server should respond to ping within 20s').toBeTruthy();
103106

107+
// Invoke the running server and verify telemetry
108+
const invokeResult = await runCLI(['dev', 'hello', '--port', String(port)], projectPath, {
109+
env: telemetry.env,
110+
});
111+
expect(invokeResult.exitCode).toBe(0);
112+
113+
telemetry.assertMetricEmitted({
114+
command: 'dev',
115+
action: 'invoke',
116+
ui_mode: 'terminal',
117+
exit_reason: 'success',
118+
protocol: 'http',
119+
});
120+
121+
// Verify failure telemetry when invoking a non-running port
122+
telemetry.clearEntries();
123+
const failResult = await runCLI(['dev', 'hello', '--port', '19999'], projectPath, { env: telemetry.env });
124+
expect(failResult.exitCode).toBe(1);
125+
126+
telemetry.assertMetricEmitted({
127+
command: 'dev',
128+
action: 'invoke',
129+
exit_reason: 'failure',
130+
});
131+
104132
// Clean shutdown
105133
devProcess.kill('SIGTERM');
106134
devProcess = null;

0 commit comments

Comments
 (0)