Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report cell execution status to Foyle. #1745

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
13 changes: 10 additions & 3 deletions src/extension/ai/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
LogEventsRequest,
LogEventType,
LogEvent,
LogEvent_ExecuteStatus,
} from '@buf/jlewi_foyle.bufbuild_es/foyle/v1alpha1/agent_pb'
import * as vscode from 'vscode'
import { ulid } from 'ulidx'
Expand All @@ -17,7 +18,7 @@ import * as converters from './converters'
// Interface for the event reporter
// This allows us to swap in a null op logger when AI isn't enabled
export interface IEventReporter {
reportExecution(cell: vscode.NotebookCell): Promise<void>
reportExecution(cell: vscode.NotebookCell, status: boolean): Promise<void>
reportEvents(events: LogEvent[]): Promise<void>
}

Expand All @@ -31,7 +32,7 @@ export class EventReporter implements IEventReporter {
this.log = getLogger('AIEventReporter')
}

async reportExecution(cell: vscode.NotebookCell) {
async reportExecution(cell: vscode.NotebookCell, executionSuccess: boolean) {
const contextCells: vscode.NotebookCell[] = []

// Include some previous cells as context.
Expand All @@ -58,6 +59,12 @@ export class EventReporter implements IEventReporter {
event.type = LogEventType.EXECUTE
event.cells = cells
event.contextId = SessionManager.getManager().getID()

if (executionSuccess) {
event.executeStatus = LogEvent_ExecuteStatus.SUCCEEDED
} else {
event.executeStatus = LogEvent_ExecuteStatus.FAILED
}
return this.reportEvents([event])
}

Expand All @@ -77,7 +84,7 @@ export class EventReporter implements IEventReporter {

// NullOpEventReporter is a null op implementation of the event reporter
export class NullOpEventReporter implements IEventReporter {
async reportExecution(_cell: vscode.NotebookCell) {
async reportExecution(_cell: vscode.NotebookCell, _status: boolean) {
// Do nothing
}

Expand Down
8 changes: 4 additions & 4 deletions src/extension/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,6 @@ export class Kernel implements Disposable {
}

TelemetryReporter.sendTelemetryEvent('cell.startExecute')
// todo(sebastian): rewrite to use non-blocking impl
const execCellReport = getEventReporter().reportExecution(cell)
runmeExec.start(Date.now())

const annotations = getAnnotations(cell)
Expand Down Expand Up @@ -825,10 +823,12 @@ export class Kernel implements Disposable {
successfulCellExecution = false
log.error('Error executing cell', e.message)
window.showErrorMessage(e.message)
} finally {
await execCellReport
}

// todo(sebastian): rewrite to use non-blocking impl
const execCellReport = getEventReporter().reportExecution(cell, successfulCellExecution)
await execCellReport

TelemetryReporter.sendTelemetryEvent('cell.endExecute', {
'cell.success': successfulCellExecution?.toString(),
'cell.mimeType': annotations.mimeType,
Expand Down