Skip to content

Commit

Permalink
{wip} [editor] add telemetry for more events
Browse files Browse the repository at this point in the history
As discussed offline, we want to enable telemetry in the local editor for the following events:

- RUN_PROMPT_START
- RUN_PROMPT_CANCEL
- RUN_PROMPT_ERROR
- RUN_PROMPT_SUCCESS

This diff implements the logging telemetry for those events.

Next up but not included in this diff is be adding "mode" to log telemetry

## Testplan
  • Loading branch information
Ankush Pala ankush@lastmileai.dev committed Jan 16, 2024
1 parent 9db62ce commit 46d5ce5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
} from "../utils/promptUtils";
import { IconDeviceFloppy } from "@tabler/icons-react";
import CopyButton from "./CopyButton";
import { log } from "console";

type Props = {
aiconfig: AIConfig;
Expand Down Expand Up @@ -671,6 +672,8 @@ export default function EditorContainer({

const cancellationToken = uuidv4();

logEventHandler?.("RUN_PROMPT_START");

dispatch({
// This sets the isRunning and runningPromptId flags
type: "RUN_PROMPT_START",
Expand All @@ -679,6 +682,8 @@ export default function EditorContainer({
});

const onPromptError = (message: string | null) => {
logEventHandler?.("RUN_PROMPT_ERROR");

dispatch({
type: "RUN_PROMPT_ERROR",
promptId,
Expand Down Expand Up @@ -721,6 +726,7 @@ export default function EditorContainer({
config: event.data,
});
} else if (event.type === "stop_streaming") {
logEventHandler?.("RUN_PROMPT_SUCCESS");
// Pass this event at the end of streaming to signal
// that the prompt is done running and we're ready
// to reset the ClientAIConfig to a non-running state
Expand All @@ -738,6 +744,7 @@ export default function EditorContainer({
if (event.data.code === 499) {
// This is a cancellation
// Reset the aiconfig to the state before we started running the prompt
logEventHandler?.("RUN_PROMPT_CANCELED");
dispatch({
type: "RUN_PROMPT_CANCEL",
promptId,
Expand Down Expand Up @@ -766,6 +773,8 @@ export default function EditorContainer({
// Keep this here in case any server implementations don't return
// aiconfig as a streaming format
if (serverConfigResponse?.aiconfig) {
// Do we need to log here
logEventHandler?.("RUN_PROMPT_SUCCESS");
dispatch({
type: "RUN_PROMPT_SUCCESS",
promptId,
Expand Down
9 changes: 8 additions & 1 deletion python/src/aiconfig/editor/client/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export function aiConfigToClientConfig(aiconfig: AIConfig): ClientAIConfig {
};
}

export type LogEvent = "ADD_PROMPT" | "SAVE_BUTTON_CLICKED";
export type LogEvent =
| "ADD_PROMPT"
| "SAVE_BUTTON_CLICKED"
| "RUN_PROMPT_START"
| "RUN_PROMPT_CANCELED"
| "RUN_PROMPT_ERROR"
| "RUN_PROMPT_SUCCESS";

// TODO: schematize this
export type LogEventData = JSONObject;

0 comments on commit 46d5ce5

Please sign in to comment.