MCPcopy
hub / github.com/claude-code-best/claude-code / doInitializeTelemetry

Function doInitializeTelemetry

src/entrypoints/init.ts:330–355  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

328}
329
330async function doInitializeTelemetry(): Promise<void> {
331 if (telemetryInitialized) {
332 // Already initialized, nothing to do
333 return
334 }
335
336 // Skip entire OTel initialization when telemetry is not enabled.
337 // Prevents PerformanceMeasure accumulation in long-running sessions.
338 if (!isEnvTruthy(process.env.CLAUDE_CODE_ENABLE_TELEMETRY)) {
339 telemetryInitialized = true
340 logForDebugging(
341 '[3P telemetry] Skipped — CLAUDE_CODE_ENABLE_TELEMETRY not set',
342 )
343 return
344 }
345
346 // Set flag before init to prevent double initialization
347 telemetryInitialized = true
348 try {
349 await setMeterState()
350 } catch (error) {
351 // Reset flag on failure so subsequent calls can retry
352 telemetryInitialized = false
353 throw error
354 }
355}
356
357async function setMeterState(): Promise<void> {
358 // Lazy-load instrumentation to defer ~400KB of OpenTelemetry + protobuf

Callers 1

Calls 3

setMeterStateFunction · 0.85
isEnvTruthyFunction · 0.50
logForDebuggingFunction · 0.50

Tested by

no test coverage detected