Skip to content

Commit 062bb5b

Browse files
trevhudellipsis-dev[bot]arafatkatze
authored
Trevhud/telemetry optimization (RooCodeInc#3263)
* add collection method * collect messages * changeset * remove commented out parts * remove check to send events anytime a new task is created while on an existing task * Update src/core/controller/task/clearTask.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Update src/services/telemetry/TelemetryService.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Lower border radius --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: Ara <[email protected]>
1 parent b667224 commit 062bb5b

File tree

7 files changed

+378
-197
lines changed

7 files changed

+378
-197
lines changed

.changeset/calm-snakes-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Allow option to collect events to send them in a bundle to avoid sending too many events

src/core/controller/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,9 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
17921792
}
17931793

17941794
async clearTask() {
1795+
if (this.task) {
1796+
await telemetryService.sendCollectedEvents(this.task.taskId)
1797+
}
17951798
this.task?.abortTask()
17961799
this.task = undefined // removes reference to it, so once promises end it will be garbage collected
17971800
}

src/core/controller/task/clearTask.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Empty, EmptyRequest } from "../../../shared/proto/common"
88
* @returns Empty response
99
*/
1010
export async function clearTask(controller: Controller, _request: EmptyRequest): Promise<Empty> {
11+
// clearTask is called here when the user closes the task
1112
await controller.clearTask()
1213
await controller.postStateToWebview()
1314
return Empty.create()

src/core/task/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ export class Task {
35613561
content: userContent,
35623562
})
35633563

3564-
telemetryService.captureConversationTurnEvent(this.taskId, currentProviderId, this.api.getModel().id, "user")
3564+
telemetryService.captureConversationTurnEvent(this.taskId, currentProviderId, this.api.getModel().id, "user", true)
35653565

35663566
// 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
35673567
const lastApiReqIndex = findLastIndex(this.clineMessages, (m) => m.say === "api_req_started")
@@ -3638,7 +3638,13 @@ export class Task {
36383638
updateApiReqMsg(cancelReason, streamingFailedMessage)
36393639
await this.saveClineMessagesAndUpdateHistory()
36403640

3641-
telemetryService.captureConversationTurnEvent(this.taskId, currentProviderId, this.api.getModel().id, "assistant")
3641+
telemetryService.captureConversationTurnEvent(
3642+
this.taskId,
3643+
currentProviderId,
3644+
this.api.getModel().id,
3645+
"assistant",
3646+
true,
3647+
)
36423648

36433649
// signals to provider that it can retrieve the saved messages from disk, as abortTask can not be awaited on in nature
36443650
this.didFinishAbortingStream = true
@@ -3781,7 +3787,13 @@ export class Task {
37813787
// need to save assistant responses to file before proceeding to tool use since user can exit at any moment and we wouldn't be able to save the assistant's response
37823788
let didEndLoop = false
37833789
if (assistantMessage.length > 0) {
3784-
telemetryService.captureConversationTurnEvent(this.taskId, currentProviderId, this.api.getModel().id, "assistant")
3790+
telemetryService.captureConversationTurnEvent(
3791+
this.taskId,
3792+
currentProviderId,
3793+
this.api.getModel().id,
3794+
"assistant",
3795+
true,
3796+
)
37853797

37863798
await this.addToApiConversationHistory({
37873799
role: "assistant",

src/extension.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,12 @@ export function activate(context: vscode.ExtensionContext) {
434434
const { IS_DEV, DEV_WORKSPACE_FOLDER } = process.env
435435

436436
// This method is called when your extension is deactivated
437-
export function deactivate() {
437+
export async function deactivate() {
438+
await telemetryService.sendCollectedEvents()
439+
438440
// Clean up test mode
439441
cleanupTestMode()
440-
441-
telemetryService.shutdown()
442+
await telemetryService.shutdown()
442443
Logger.log("Cline extension deactivated")
443444
}
444445

0 commit comments

Comments
 (0)