UNPKG

@ogcio/o11y-sdk-node

Version:

Opentelemetry standard instrumentation SDK for NodeJS based project

22 lines (21 loc) 797 B
export function _shutdownHook(sdk) { let isShuttingDown = false; const shutdownSdk = async () => { if (isShuttingDown) return; isShuttingDown = true; try { // Flushing before shutdown is implemented on a per-exporter basis. await sdk.shutdown(); console.log("NodeJS OpenTelemetry instrumentation shutdown successfully"); } catch (error) { console.error("Error shutting down NodeJS OpenTelemetry instrumentation:", error); } }; // For external kills (Kubernetes, docker stop, etc.) process.once("SIGTERM", shutdownSdk); process.once("SIGINT", shutdownSdk); // For normal process exit (event loop drained naturally) process.once("beforeExit", shutdownSdk); }