Add telemetry for checkpoint save/restore/diff

This commit is contained in:
Matt Rubens 2025-03-09 22:55:23 -04:00
parent 85775ce0a5
commit 9c08d044b3
2 changed files with 21 additions and 0 deletions

View file

@ -3798,6 +3798,8 @@ export class Cline {
return
}
telemetryService.captureCheckpointDiffed(this.taskId)
if (!previousCommitHash && mode === "checkpoint") {
const previousCheckpoint = this.clineMessages
.filter(({ say }) => say === "checkpoint_saved")
@ -3849,6 +3851,8 @@ export class Cline {
return
}
telemetryService.captureCheckpointCreated(this.taskId)
// Start the checkpoint process in the background.
service.saveCheckpoint(`Task: ${this.taskId}, Time: ${Date.now()}`).catch((err) => {
console.error("[Cline#checkpointSave] caught unexpected error, disabling checkpoints", err)
@ -3880,6 +3884,8 @@ export class Cline {
try {
await service.restoreCheckpoint(commitHash)
telemetryService.captureCheckpointRestored(this.taskId)
await this.providerRef.deref()?.postMessageToWebview({ type: "currentCheckpointUpdated", text: commitHash })
if (mode === "restore") {

View file

@ -22,6 +22,9 @@ class PostHogClient {
CONVERSATION_MESSAGE: "Conversation Message",
MODE_SWITCH: "Mode Switched",
TOOL_USED: "Tool Used",
CHECKPOINT_CREATED: "Checkpoint Created",
CHECKPOINT_RESTORED: "Checkpoint Restored",
CHECKPOINT_DIFFED: "Checkpoint Diffed",
},
}
@ -246,6 +249,18 @@ class TelemetryService {
})
}
public captureCheckpointCreated(taskId: string): void {
this.captureEvent(PostHogClient.EVENTS.TASK.CHECKPOINT_CREATED, { taskId })
}
public captureCheckpointDiffed(taskId: string): void {
this.captureEvent(PostHogClient.EVENTS.TASK.CHECKPOINT_DIFFED, { taskId })
}
public captureCheckpointRestored(taskId: string): void {
this.captureEvent(PostHogClient.EVENTS.TASK.CHECKPOINT_RESTORED, { taskId })
}
/**
* Checks if telemetry is currently enabled
* @returns Whether telemetry is enabled