MCPcopy
hub / github.com/foambubble/foam / TelemetryService

Class TelemetryService

packages/foam-vscode/src/vscode/services/telemetry.ts:32–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 * `docs/user/tools/telemetry.md` for the full list.
31 */
32export class TelemetryService implements IDisposable {
33 private reporter: TelemetryReporter;
34 private sessionWithCommandFired = false;
35 private sessionWithNoteFired = false;
36
37 constructor(opts: TelemetryServiceOptions) {
38 this.reporter = new TelemetryReporter(
39 TELEMETRY_CONNECTION_STRING,
40 undefined,
41 undefined,
42 undefined,
43 {
44 commonProperties: {
45 'foam.component': 'vscode',
46 'foam.version': opts.foamVersion,
47 'foam.coreVersion': opts.coreVersion,
48 },
49 }
50 );
51 }
52
53 trackEvent(name: string, properties?: Record<string, string>): void {
54 const fullName = EVENT_PREFIX + name;
55 Logger.debug(
56 `[telemetry] ${fullName}${properties ? ' ' + JSON.stringify(properties) : ''}`
57 );
58 this.reporter.sendTelemetryEvent(fullName, properties);
59 }
60
61 trackError(
62 context: string,
63 error: unknown,
64 properties?: Record<string, string>
65 ): void {
66 const errorType =
67 error instanceof Error ? error.constructor.name : 'UnknownError';
68 const fullName = EVENT_PREFIX + 'error';
69 Logger.debug(`[telemetry] ${fullName} in ${context}: ${errorType}`);
70 this.reporter.sendTelemetryErrorEvent(fullName, {
71 context,
72 errorType,
73 ...properties,
74 });
75 }
76
77 /**
78 * Fired once per activation, before Foam loads. The canonical "active session" metric.
79 */
80 trackSession(): void {
81 this.trackEvent('session-started');
82 }
83
84 /**
85 * Fired every time a command is invoked. Also fires `session-with-command` once
86 * per session on the first invocation, distinguishing "Foam loaded" from "Foam was used".
87 */
88 trackCommand(command: string): void {
89 if (!this.sessionWithCommandFired) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected