log dev data

This commit is contained in:
Dallin Romney 2025-01-31 12:17:06 -08:00
parent 7dc1b51867
commit fd85340cc1
8 changed files with 107 additions and 51 deletions

View file

@ -97,7 +97,7 @@ export class AutocompleteLoggingService {
private logAutocompleteOutcome(outcome: AutocompleteOutcome) {
void DataLogger.getInstance().logDevData({
schema: "autocomplete",
name: "autocomplete",
data: outcome,
});

View file

@ -36,7 +36,7 @@ import historyManager from "./util/history";
import {
editConfigJson,
getConfigJsonPath,
setupInitialDotContinueDirectory,
migrateV1DevDataFiles,
} from "./util/paths";
import { localPathToUri } from "./util/pathToUri";
import { Telemetry } from "./util/posthog";
@ -100,7 +100,7 @@ export class Core {
private readonly onWrite: (text: string) => Promise<void> = async () => {},
) {
// Ensure .continue directory is created
setupInitialDotContinueDirectory();
migrateV1DevDataFiles();
this.codebaseIndexingState = {
status: "loading",
@ -147,7 +147,6 @@ export class Core {
// Dev Data Logger
const dataLogger = DataLogger.getInstance();
dataLogger.core = this;
dataLogger.ide = this.ide;
// Codebase Indexer and ContinueServerClient depend on IdeSettings
let codebaseIndexerResolve: (_: any) => void | undefined;

View file

@ -1,4 +1,5 @@
import fs from "fs";
import path from "path";
import { getDevDataFilePath } from "../util/paths.js";
import { Core } from "../core.js";
@ -11,19 +12,13 @@ import {
import { fetchwithRequestOptions } from "@continuedev/fetch";
import { joinPathsToUri } from "../util/uri.js";
import * as URI from "uri-js";
import { IDE } from "../index.js";
import { fileURLToPath } from "url";
// const localDevDataFileNamesMap: Record<Dev, string> = {
// // tokensGenerated: "tokens_generated",
// // chat: "chat",
// // quickEdit: "quickEdit",
// autocomplete: "autocomplete",
// };
const DEFAULT_DEV_DATA_LEVEL: DataLogLevel = "all";
export const LOCAL_DEV_DATA_VERSION = "0.2.0";
export class DataLogger {
private static instance: DataLogger | null = null;
core?: Core;
ide?: IDE;
// Private constructor to prevent direct class instantiation
private constructor() {}
@ -36,8 +31,11 @@ export class DataLogger {
}
async logDevData(event: DevDataLogEvent) {
// Local logs (always on)
const filepath: string = getDevDataFilePath(event.schema);
// Local logs (always on for all levels)
const filepath: string = getDevDataFilePath(
event.name,
LOCAL_DEV_DATA_VERSION,
);
const jsonLine = JSON.stringify(event.data);
fs.writeFileSync(filepath, `${jsonLine}\n`, { flag: "a" });
@ -47,24 +45,52 @@ export class DataLogger {
await Promise.allSettled(
config.data.map(async (dataConfig) => {
try {
const version = dataConfig.version;
const level = dataConfig.level ?? DEFAULT_DEV_DATA_LEVEL;
const events = dataConfig.events ?? allDevEventNames;
// First extract the data schema based on the version and level
const { schemaVersion } = dataConfig;
const versionSchemas = devDataVersionedSchemas[version];
const level = dataConfig.level ?? DEFAULT_DEV_DATA_LEVEL;
// Skip event if `events` is specified and does not include the event
const events = dataConfig.events ?? allDevEventNames;
if (!events.includes(event.name)) {
return;
}
const versionSchemas = devDataVersionedSchemas[schemaVersion];
if (!versionSchemas) {
throw new Error(
`Logging dev data to version ${version} is not supported.`,
`Attempting to log dev data to non-existent version ${schemaVersion}`,
);
}
const levelSchemas = versionSchemas[level];
if (!levelSchemas) {
throw new Error(
`Attempting to log dev data at level ${level} for version ${schemaVersion} which does not exist`,
);
}
const schema = levelSchemas[event.name];
if (!schema) {
throw new Error(
`Attempting to log dev data for event ${event.name} at level ${level} for version ${schemaVersion}: no schema found`,
);
}
const parsed = schema.safeParse(event.data);
if (!parsed.success) {
throw new Error(
`Failed to parse event data ${parsed.error.toString()}`,
);
}
const uriComponents = URI.parse(dataConfig.destination);
// Send to remote server
if (
uriComponents.scheme === "https" ||
uriComponents.scheme === "http"
) {
// Send to remote server
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
@ -77,10 +103,10 @@ export class DataLogger {
method: "POST",
headers,
body: JSON.stringify({
schema: event.schema,
version: dataConfig.version,
data: event.data,
// x: dataConfig.
name: event.name,
data: parsed.data,
schemaVersion,
level,
}),
},
dataConfig.requestOptions,
@ -90,10 +116,23 @@ export class DataLogger {
`Failed to log data to ${dataConfig.destination}: ${response.statusText}`,
);
}
} else if (uriComponents.scheme === "file") {
// Write to jsonc file for local file URIs
const dirUri = joinPathsToUri(
dataConfig.destination,
schemaVersion,
);
const dirPath = fileURLToPath(dirUri);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
const filepath = path.join(dirPath, `${event.name}.jsonl`);
const jsonLine = JSON.stringify(event.data);
fs.writeFileSync(filepath, `${jsonLine}\n`, { flag: "a" });
} else {
joinPathsToUri(dataConfig.destination, "version");
throw new Error(`Unsupported scheme ${uriComponents.scheme}`);
}
// Write to jsonc file using IDE
} catch (error) {
console.error(
`Error logging data to ${dataConfig.destination}: ${error instanceof Error ? error.message : error}`,

View file

@ -340,7 +340,7 @@ export abstract class BaseLLM implements ILLM {
);
void DataLogger.getInstance().logDevData({
schema: "tokensGenerated",
name: "tokensGenerated",
data: {
model: model,
provider: this.providerName,

View file

@ -8,10 +8,7 @@ import dotenv from "dotenv";
import { IdeType, SerializedContinueConfig } from "../";
import { defaultConfig, defaultConfigJetBrains } from "../config/default";
import Types from "../config/types";
import {
DevDataSchemaName,
localDevDataFileNamesMap,
} from "../../packages/config-yaml/src/schemas/data";
import { DevEventName } from "../../packages/config-yaml/src/schemas/data";
dotenv.config();
@ -202,7 +199,7 @@ export function getContinueRcPath(): string {
return continuercPath;
}
export function devDataPath(): string {
function getDevDataPath(): string {
const sPath = path.join(getContinueGlobalPath(), "dev_data");
if (!fs.existsSync(sPath)) {
fs.mkdirSync(sPath);
@ -211,11 +208,18 @@ export function devDataPath(): string {
}
export function getDevDataSqlitePath(): string {
return path.join(devDataPath(), "devdata.sqlite");
return path.join(getDevDataPath(), "devdata.sqlite");
}
export function getDevDataFilePath(schema: DevDataSchemaName): string {
return path.join(devDataPath(), `${localDevDataFileNamesMap[schema]}.jsonl`);
export function getDevDataFilePath(
eventName: DevEventName,
schemaVersion: string,
): string {
const versionPath = path.join(getDevDataPath(), schemaVersion);
if (!fs.existsSync(versionPath)) {
fs.mkdirSync(versionPath);
}
return path.join(versionPath, `${eventName}.jsonl`);
}
export function editConfigJson(
@ -377,19 +381,29 @@ export function getEsbuildBinaryPath(): string {
return path.join(getContinueUtilsPath(), "esbuild");
}
export function setupInitialDotContinueDirectory() {
const devDataTypes: DevDataSchemaName[] = [
"chat",
"autocomplete",
"quickEdit",
"tokensGenerated",
];
devDataTypes.forEach((p) => {
const devDataPath = getDevDataFilePath(p);
if (!fs.existsSync(devDataPath)) {
fs.writeFileSync(devDataPath, "");
export function migrateV1DevDataFiles() {
const devDataPath = getDevDataPath();
function moveToV1FolderIfExists(
oldFileName: string,
newFileName: DevEventName,
) {
const oldFilePath = path.join(devDataPath, `${oldFileName}.jsonl`);
if (fs.existsSync(oldFilePath)) {
const newFilePath = getDevDataFilePath(newFileName, "0.1.0");
if (!fs.existsSync(newFilePath)) {
fs.copyFileSync(oldFilePath, newFilePath);
fs.unlinkSync(oldFilePath);
} else {
console.warn(
`V1 Dev data migration: ${newFilePath} already exists, skipping ${oldFileName}`,
);
}
}
});
}
moveToV1FolderIfExists("tokens_generated", "tokensGenerated");
moveToV1FolderIfExists("chat", "chatFeedback");
moveToV1FolderIfExists("quickEdit", "quickEdit");
moveToV1FolderIfExists("autocomplete", "autocomplete");
}
export function getDiffsDirectoryPath(): string {

View file

@ -33,6 +33,7 @@ import { Battery } from "./util/battery";
import { VsCodeIde } from "./VsCodeIde";
import type { VsCodeWebviewProtocol } from "./webviewProtocol";
import { LOCAL_DEV_DATA_VERSION } from "core/data/log";
let fullScreenPanel: vscode.WebviewPanel | undefined;
@ -981,7 +982,10 @@ const getCommandsMap: (
});
if (feedback) {
const client = await continueServerClientPromise;
const completionsPath = getDevDataFilePath("autocomplete");
const completionsPath = getDevDataFilePath(
"autocomplete",
LOCAL_DEV_DATA_VERSION,
);
const lastLines = await readLastLines.read(completionsPath, 2);
client.sendFeedback(feedback, lastLines);

View file

@ -228,7 +228,7 @@ export class QuickEdit {
let model = await this.getCurModelTitle();
void DataLogger.getInstance().logDevData({
schema: "quickEdit",
name: "quickEdit",
data: {
prompt,
path,

View file

@ -22,7 +22,7 @@ export default function FeedbackButtons({ item }: FeedbackButtonsProps) {
if (item.promptLogs?.length) {
for (const promptLog of item.promptLogs) {
ideMessenger.post("devdata/log", {
schema: "chat",
name: "chatFeedback",
data: { ...promptLog, feedback, sessionId },
});
}