MCPcopy Index your code
hub / github.com/codeaashu/claude-code / shutdownTelemetry

Function shutdownTelemetry

src/utils/telemetry/instrumentation.ts:527–560  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

525
526 // Register shutdown for beta tracing
527 const shutdownTelemetry = async () => {
528 const timeoutMs = parseInt(
529 process.env.CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS || '2000',
530 )
531 try {
532 endInteractionSpan()
533
534 // Force flush + shutdown together inside the timeout. Previously forceFlush
535 // was awaited unbounded BEFORE the race, blocking exit on slow OTLP endpoints.
536 // Each provider's flush→shutdown is chained independently so a slow logger
537 // flush doesn't delay meterProvider/tracerProvider shutdown (no waterfall).
538 const loggerProvider = getLoggerProvider()
539 const tracerProvider = getTracerProvider()
540
541 const chains: Promise<void>[] = [meterProvider.shutdown()]
542 if (loggerProvider) {
543 chains.push(
544 loggerProvider.forceFlush().then(() => loggerProvider.shutdown()),
545 )
546 }
547 if (tracerProvider) {
548 chains.push(
549 tracerProvider.forceFlush().then(() => tracerProvider.shutdown()),
550 )
551 }
552
553 await Promise.race([
554 Promise.all(chains),
555 telemetryTimeout(timeoutMs, 'OpenTelemetry shutdown timeout'),
556 ])
557 } catch {
558 // Ignore shutdown errors
559 }
560 }
561 registerCleanup(shutdownTelemetry)
562
563 return meterProvider.getMeter('com.anthropic.claude_code', MACRO.VERSION)

Callers

nothing calls this directly

Calls 8

endInteractionSpanFunction · 0.85
getLoggerProviderFunction · 0.85
getTracerProviderFunction · 0.85
telemetryTimeoutFunction · 0.85
logForDebuggingFunction · 0.85
shutdownMethod · 0.45
pushMethod · 0.45
forceFlushMethod · 0.45

Tested by

no test coverage detected