MCPcopy Create free account
hub / github.com/Noumena-Network/code / shutdownTelemetry

Function shutdownTelemetry

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected