MCPcopy
hub / github.com/coder/mux / initialize

Method initialize

src/node/services/telemetryService.ts:198–227  ·  view source on GitHub ↗

* Initialize the PostHog client. * Should be called once on app startup.

()

Source from the content-addressed store, hash-verified

196 * Should be called once on app startup.
197 */
198 async initialize(): Promise<void> {
199 if (this.client) {
200 return;
201 }
202
203 const env = process.env;
204
205 // Fast path: avoid Electron imports when telemetry is obviously disabled.
206 if (isTelemetryDisabledByEnv(env)) {
207 return;
208 }
209
210 const isElectron = typeof process.versions.electron === "string";
211 const isPackaged = await getElectronIsPackaged(isElectron);
212
213 if (!shouldEnableTelemetry({ env, isElectron, isPackaged })) {
214 return;
215 }
216
217 // Load or generate distinct ID
218 this.distinctId = await this.loadOrCreateDistinctId();
219
220 this.client = new PostHog(DEFAULT_POSTHOG_KEY, {
221 host: DEFAULT_POSTHOG_HOST,
222 // Avoid geo-IP enrichment (we don't need coarse location for mux telemetry)
223 disableGeoip: true,
224 });
225
226 console.debug("[TelemetryService] Initialized", { host: DEFAULT_POSTHOG_HOST });
227 }
228
229 /**
230 * Load existing distinct ID or create a new one.

Callers

nothing calls this directly

Calls 5

isTelemetryDisabledByEnvFunction · 0.85
getElectronIsPackagedFunction · 0.85
shouldEnableTelemetryFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected