Elffuss BraidHub

kikocis/continue public

main · 1.2 KiBRawPermalink
1import net from "node:net";
2
3import { Analytics } from "@continuedev/config-types";
4
5import {
6 ControlPlaneProxyInfo,
7 IAnalyticsProvider,
8} from "./IAnalyticsProvider.js";
9
10export default class LogStashAnalyticsProvider implements IAnalyticsProvider {
11 private host?: string;
12 private port?: number;
13 private uniqueId?: string;
14
15 async capture(
16 event: string,
17 properties: { [key: string]: any },
18 ): Promise<void> {
19 if (this.host === undefined || this.port === undefined) {
20 console.warn("LogStashAnalyticsProvider not set up yet.");
21 }
22
23 const payload = {
24 event,
25 properties,
26 uniqueId: this.uniqueId,
27 };
28 const client = new net.Socket();
29
30 client.connect(this.port!, this.host!, () => {
31 client.write(JSON.stringify(payload));
32 client.end();
33 });
34 }
35
36 async setup(
37 config: Analytics,
38 uniqueId: string,
39 controlPlaneProxyInfo?: ControlPlaneProxyInfo,
40 ): Promise<void> {
41 if (!config.url) {
42 console.warn("LogStashAnalyticsProvider is missing a URL");
43 return;
44 }
45 const url = new URL(config.url);
46 this.host = url.hostname;
47 this.port = parseInt(url.port);
48 this.uniqueId = uniqueId;
49 }
50
51 async shutdown(): Promise<void> {}
52}