From 2004cca486e93def3c84fea2f703fc29bcf04528 Mon Sep 17 00:00:00 2001 From: ShayBC Date: Sat, 8 Mar 2025 06:23:22 +0200 Subject: [PATCH] changed telemetry methods to async and changed refrences to await --- src/core/Cline.ts | 12 ++++---- src/core/webview/ClineProvider.ts | 2 +- src/services/telemetry/TelemetryService.ts | 32 +++++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 51fb5265d41..081997f5779 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -192,8 +192,10 @@ export class Cline { this.checkpointStorage = checkpointStorage if (historyItem) { + // not awaiting since we are in a constructor - should not influence execution telemetryService.captureTaskRestarted(this.taskId) } else { + // not awaiting since we are in a constructor - should not influence execution telemetryService.captureTaskCreated(this.taskId) } @@ -1454,7 +1456,7 @@ export class Cline { } if (!block.partial) { - telemetryService.captureToolUsage(this.taskId, block.name) + await telemetryService.captureToolUsage(this.taskId, block.name) } // Validate tool use before execution @@ -2941,7 +2943,7 @@ export class Cline { if (lastMessage && lastMessage.ask !== "command") { // havent sent a command message yet so first send completion_result then command await this.say("completion_result", result, undefined, false) - telemetryService.captureTaskCompleted(this.taskId) + await telemetryService.captureTaskCompleted(this.taskId) if (this.isSubTask) { // tell the provider to remove the current subtask and resume the previous task in the stack await this.providerRef @@ -2966,7 +2968,7 @@ export class Cline { commandResult = execCommandResult } else { await this.say("completion_result", result, undefined, false) - telemetryService.captureTaskCompleted(this.taskId) + await telemetryService.captureTaskCompleted(this.taskId) if (this.isSubTask) { // tell the provider to remove the current subtask and resume the previous task in the stack await this.providerRef @@ -3132,7 +3134,7 @@ export class Cline { userContent.push({ type: "text", text: environmentDetails }) await this.addToApiConversationHistory({ role: "user", content: userContent }) - telemetryService.captureConversationMessage(this.taskId, "user") + await telemetryService.captureConversationMessage(this.taskId, "user") // since we sent off a placeholder api_req_started message to update the webview while waiting to actually start the API request (to load potential details for example), we need to update the text of that message const lastApiReqIndex = findLastIndex(this.clineMessages, (m) => m.say === "api_req_started") @@ -3334,7 +3336,7 @@ export class Cline { role: "assistant", content: [{ type: "text", text: assistantMessage }], }) - telemetryService.captureConversationMessage(this.taskId, "assistant") + await telemetryService.captureConversationMessage(this.taskId, "assistant") // NOTE: this comment is here for future reference - this was a workaround for userMessageContent not getting set to true. It was due to it not recursively calling for partial blocks when didRejectTool, so it would get stuck waiting for a partial block to complete before it could continue. // in case the content blocks finished diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 70feb45c2fc..5d30637ca3c 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1864,7 +1864,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { // Capture mode switch telemetry event const currentTaskId = this.getCurrentCline()?.taskId if (currentTaskId) { - telemetryService.captureModeSwitch(currentTaskId, newMode) + await telemetryService.captureModeSwitch(currentTaskId, newMode) } await this.updateGlobalState("mode", newMode) diff --git a/src/services/telemetry/TelemetryService.ts b/src/services/telemetry/TelemetryService.ts index 45a34bda4e2..f1faaa60dbd 100644 --- a/src/services/telemetry/TelemetryService.ts +++ b/src/services/telemetry/TelemetryService.ts @@ -198,9 +198,9 @@ class TelemetryService { * Captures a telemetry event if telemetry is enabled * @param event The event to capture with its properties */ - public capture(event: { event: string; properties?: any }): void { + public async capture(event: { event: string; properties?: any }) { if (!this.isReady()) return - this.client!.capture(event) + await this.client!.capture(event) } /** @@ -208,39 +208,39 @@ class TelemetryService { * @param eventName The event name to capture * @param properties The event properties */ - public captureEvent(eventName: string, properties?: any): void { - this.capture({ event: eventName, properties }) + public async captureEvent(eventName: string, properties?: any) { + await this.capture({ event: eventName, properties }) } // Task events convenience methods - public captureTaskCreated(taskId: string): void { - this.captureEvent(PostHogClient.EVENTS.TASK.CREATED, { taskId }) + public async captureTaskCreated(taskId: string) { + await this.captureEvent(PostHogClient.EVENTS.TASK.CREATED, { taskId }) } - public captureTaskRestarted(taskId: string): void { - this.captureEvent(PostHogClient.EVENTS.TASK.RESTARTED, { taskId }) + public async captureTaskRestarted(taskId: string) { + await this.captureEvent(PostHogClient.EVENTS.TASK.RESTARTED, { taskId }) } - public captureTaskCompleted(taskId: string): void { - this.captureEvent(PostHogClient.EVENTS.TASK.COMPLETED, { taskId }) + public async captureTaskCompleted(taskId: string) { + await this.captureEvent(PostHogClient.EVENTS.TASK.COMPLETED, { taskId }) } - public captureConversationMessage(taskId: string, source: "user" | "assistant"): void { - this.captureEvent(PostHogClient.EVENTS.TASK.CONVERSATION_MESSAGE, { + public async captureConversationMessage(taskId: string, source: "user" | "assistant") { + await this.captureEvent(PostHogClient.EVENTS.TASK.CONVERSATION_MESSAGE, { taskId, source, }) } - public captureModeSwitch(taskId: string, newMode: string): void { - this.captureEvent(PostHogClient.EVENTS.TASK.MODE_SWITCH, { + public async captureModeSwitch(taskId: string, newMode: string) { + await this.captureEvent(PostHogClient.EVENTS.TASK.MODE_SWITCH, { taskId, newMode, }) } - public captureToolUsage(taskId: string, tool: string): void { - this.captureEvent(PostHogClient.EVENTS.TASK.TOOL_USED, { + public async captureToolUsage(taskId: string, tool: string) { + await this.captureEvent(PostHogClient.EVENTS.TASK.TOOL_USED, { taskId, tool, })