UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

33 lines (32 loc) • 1.04 kB
import { captureException, defineIntegration, isObjectLike } from "@sentry/core"; import { subscribeDiagnosticsChannel } from "@sentry/server-utils"; // src/integrations/workerThreads.ts const INTEGRATION_NAME = "WorkerThreads"; /** * Capture events and errors of worker threads. * For child process events, use `childProcessIntegration()` instead. */ const workerThreadsIntegration = defineIntegration(() => { return { name: INTEGRATION_NAME, setup() { subscribeDiagnosticsChannel("worker_threads", (event) => { if (isObjectLike(event) && "worker" in event) captureWorkerThreadEvents(event.worker); }); } }; }); function captureWorkerThreadEvents(worker) { let threadId; worker.on("online", () => { threadId = worker.threadId; }).on("error", (error) => { captureException(error, { mechanism: { type: "auto.node.worker_threads", handled: false, data: threadId !== void 0 ? { threadId: String(threadId) } : void 0 } }); }); } export { workerThreadsIntegration }; //# sourceMappingURL=workerThreads.js.map