UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

53 lines (52 loc) • 1.55 kB
import { addBreadcrumb, defineIntegration, isObjectLike } from "@sentry/core"; import { subscribeDiagnosticsChannel } from "@sentry/server-utils"; // src/integrations/childProcess.ts const INTEGRATION_NAME = "ChildProcess"; /** * Capture breadcrumbs and events for child processes. * For worker thread events, use `workerThreadsIntegration()` instead. */ const childProcessIntegration = defineIntegration((options = {}) => { return { name: INTEGRATION_NAME, setup() { subscribeDiagnosticsChannel("child_process", (event) => { if (isObjectLike(event) && "process" in event) captureChildProcessEvents(event.process, options); }); } }; }); function captureChildProcessEvents(child, options) { let hasExited = false; let data; child.on("spawn", () => { if (child.spawnfile === "/usr/bin/sw_vers") { hasExited = true; return; } data = { spawnfile: child.spawnfile }; if (options.includeChildProcessArgs) data.spawnargs = child.spawnargs; }).on("exit", (code) => { if (!hasExited) { hasExited = true; if (code !== null && code !== 0) addBreadcrumb({ category: "child_process", message: `Child process exited with code '${code}'`, level: code === 0 ? "info" : "warning", data }); } }).on("error", (error) => { if (!hasExited) { hasExited = true; addBreadcrumb({ category: "child_process", message: `Child process errored with '${error.message}'`, level: "error", data }); } }); } export { childProcessIntegration }; //# sourceMappingURL=childProcess.js.map