Skip to content

Commit 12b0397

Browse files
author
Calvinn Ng
committed
add user telemetry logging
1 parent b945b8b commit 12b0397

File tree

6 files changed

+60
-57
lines changed

6 files changed

+60
-57
lines changed

core/autocomplete/completionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
COUNT_COMPLETION_REJECTED_AFTER,
2121
DEFAULT_AUTOCOMPLETE_OPTS,
2222
} from "../util/parameters.js";
23-
import { Telemetry } from "../util/posthog.js";
23+
import { Telemetry } from "../util/logging.js";
2424
import { getRangeInString } from "../util/ranges.js";
2525
import { BracketMatchingService } from "./brackets.js";
2626
import AutocompleteLruCache from "./cache.js";

core/config/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ContinueConfig, ContinueRcJson, IDE, ILLM } from "..";
22
import { IdeSettings } from "../protocol";
3-
import { Telemetry } from "../util/posthog";
3+
import { Telemetry } from "../util/logging";
44
import {
55
BrowserSerializedContinueConfig,
66
finalToBrowserConfig,

core/llm/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { logDevData } from "../util/devdata.js";
1717
import { DevDataSqliteDb } from "../util/devdataSqlite";
1818
import mergeJson from "../util/merge";
19-
import { Telemetry } from "../util/posthog";
19+
import { Telemetry } from "../util/logging";
2020
import {
2121
autodetectPromptTemplates,
2222
autodetectTemplateFunction,

core/util/logging.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os from "os";
2+
3+
export class Telemetry {
4+
// Set to undefined whenever telemetry is disabled
5+
static serverUrl?: string = "https://your-server-url.com/telemetry";
6+
static uniqueId: string = "NOT_UNIQUE";
7+
static os: string | undefined = undefined;
8+
static extensionVersion: string | undefined = undefined;
9+
10+
static async capture(event: string, properties: { [key: string]: any }) {
11+
if (Telemetry.serverUrl) {
12+
const data = {
13+
distinctId: Telemetry.uniqueId,
14+
event,
15+
properties: {
16+
...properties,
17+
os: Telemetry.os,
18+
extensionVersion: Telemetry.extensionVersion,
19+
},
20+
};
21+
22+
try {
23+
const response = await fetch(Telemetry.serverUrl, {
24+
method: 'POST',
25+
headers: {
26+
'Content-Type': 'application/json',
27+
},
28+
body: JSON.stringify(data),
29+
});
30+
31+
if (!response.ok) {
32+
console.error(`Failed to send telemetry data: ${response.statusText}`);
33+
}
34+
} catch (e) {
35+
console.error(`Failed to send telemetry data: ${e}`);
36+
}
37+
}
38+
}
39+
40+
static async setup(
41+
allow: boolean,
42+
uniqueId: string,
43+
extensionVersion: string,
44+
serverUrl?: string
45+
) {
46+
Telemetry.uniqueId = uniqueId;
47+
Telemetry.os = os.platform();
48+
Telemetry.extensionVersion = extensionVersion;
49+
50+
if (!allow) {
51+
Telemetry.serverUrl = undefined;
52+
} else {
53+
Telemetry.serverUrl = serverUrl || Telemetry.serverUrl;
54+
}
55+
}
56+
}

core/util/posthog.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

core/util/verticalEdit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { streamDiff } from "../diff/streamDiff";
1010
import { streamLines } from "../diff/util";
1111
import { gptEditPrompt } from "../llm/templates/edit";
12-
import { Telemetry } from "./posthog";
12+
import { Telemetry } from "./logging";
1313

1414
function constructPrompt(
1515
prefix: string,

0 commit comments

Comments
 (0)