Skip to content

Commit 13ac369

Browse files
committed
refactor: split command instrumentation and tighten telemetry API
Split instrumentation/commands.ts into workspaceOpen.ts, diagnostics.ts, and shared outcomes.ts to mirror a future commands.ts split. Unify trace methods on the cancel/fail/succeed* trio, shorten trace<Noun> names, and make ExportTelemetryObserver a required structural subset of DiagnosticTrace so callers pass their trace directly. Commands now keep business bodies in named run* methods instead of inline closures, the open source defaults to "command" rather than being inferred from argument presence, and the dead openWorkspace wrapper is gone. Restore workspaceName on workspace.update.prompted and workspace.start.prompted to match the other operation traces. Rename the telemetry-only test to updateWorkspace.telemetry.test.ts.
1 parent 72e8726 commit 13ac369

13 files changed

Lines changed: 668 additions & 659 deletions

File tree

src/commands.ts

Lines changed: 181 additions & 190 deletions
Large diffs are not rendered by default.

src/instrumentation/commands.ts

Lines changed: 0 additions & 299 deletions
This file was deleted.

src/instrumentation/diagnostics.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { recordCancelled, recordFailure } from "./outcomes";
2+
3+
import type { SpeedtestResult } from "@repo/shared";
4+
5+
import type { TelemetryReporter } from "../telemetry/reporter";
6+
import type { Span } from "../telemetry/span";
7+
8+
import type { WorkspacePickerFailureCategory } from "./workspaceOpen";
9+
10+
export type DiagnosticCommand =
11+
| "speed_test"
12+
| "support_bundle"
13+
| "export_telemetry";
14+
export type DiagnosticFailureCategory =
15+
| WorkspacePickerFailureCategory
16+
| "parse_error"
17+
| "unsupported_cli"
18+
| "error";
19+
export type DiagnosticCancelStage =
20+
| "workspace_picker"
21+
| "input"
22+
| "prompt"
23+
| "save_dialog"
24+
| "progress";
25+
26+
export interface DiagnosticTrace {
27+
cancel(stage: DiagnosticCancelStage): void;
28+
fail(category?: DiagnosticFailureCategory): void;
29+
setRequestedDuration(seconds: number): void;
30+
succeedSpeedtest(result: SpeedtestResult): void;
31+
succeedExport(format: string, eventCount: number): void;
32+
}
33+
34+
/** Emits `command.diagnostic.completed` around each diagnostic command. */
35+
export class DiagnosticTelemetry {
36+
public constructor(private readonly telemetry: TelemetryReporter) {}
37+
38+
public trace(
39+
command: DiagnosticCommand,
40+
fn: (trace: DiagnosticTrace) => Promise<void>,
41+
): Promise<void> {
42+
return this.telemetry.trace(
43+
"command.diagnostic.completed",
44+
(span) => fn(new SpanDiagnosticTrace(span)),
45+
{ command },
46+
);
47+
}
48+
}
49+
50+
class SpanDiagnosticTrace implements DiagnosticTrace {
51+
public constructor(private readonly span: Span) {}
52+
53+
public cancel(stage: DiagnosticCancelStage): void {
54+
recordCancelled(this.span, stage);
55+
}
56+
57+
public fail(category: DiagnosticFailureCategory = "error"): void {
58+
recordFailure(this.span, category);
59+
}
60+
61+
public setRequestedDuration(seconds: number): void {
62+
this.span.setMeasurement("requested_duration_seconds", seconds);
63+
}
64+
65+
public succeedSpeedtest(result: SpeedtestResult): void {
66+
this.span.setMeasurement("interval_count", result.intervals.length);
67+
this.span.setMeasurement(
68+
"throughput_mbits",
69+
result.overall.throughput_mbits,
70+
);
71+
}
72+
73+
public succeedExport(format: string, eventCount: number): void {
74+
this.span.setProperty("format", format);
75+
this.span.setMeasurement("event_count", eventCount);
76+
}
77+
}

0 commit comments

Comments
 (0)