Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 16 additions & 16 deletions src/services/telemetry/TelemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,49 +198,49 @@ 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)
}

/**
* Generic method to capture any type of event with specified properties
* @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,
})
Expand Down