MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / trackSpan

Method trackSpan

packages/cli/src/telemetry.ts:92–119  ·  view source on GitHub ↗
(
        startEvent: TelemetryEvents,
        completeEvent: TelemetryEvents,
        errorEvent: TelemetryEvents,
        properties: Record<string, unknown>,
        action: () => Promise<T> | T,
    )

Source from the content-addressed store, hash-verified

90 }
91
92 async trackSpan<T>(
93 startEvent: TelemetryEvents,
94 completeEvent: TelemetryEvents,
95 errorEvent: TelemetryEvents,
96 properties: Record<string, unknown>,
97 action: () => Promise<T> | T,
98 ) {
99 this.track(startEvent, properties);
100 const start = Date.now();
101 let success = true;
102 try {
103 return await action();
104 } catch (err: any) {
105 this.track(errorEvent, {
106 message: err.message,
107 stack: err.stack,
108 ...properties,
109 });
110 success = false;
111 throw err;
112 } finally {
113 this.track(completeEvent, {
114 duration: Date.now() - start,
115 success,
116 ...properties,
117 });
118 }
119 }
120
121 async trackCommand(command: string, action: () => Promise<void> | void) {
122 await this.trackSpan('cli:command:start', 'cli:command:complete', 'cli:command:error', { command }, action);

Callers 2

trackCommandMethod · 0.95
trackCliMethod · 0.95

Calls 1

trackMethod · 0.95

Tested by

no test coverage detected