diff --git a/.changeset/fix-sentry-oom-2920.md b/.changeset/fix-sentry-oom-2920.md new file mode 100644 index 0000000000..7c770e4cd2 --- /dev/null +++ b/.changeset/fix-sentry-oom-2920.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/cli-v3": patch +--- + +Fix Sentry OOM: Allow disabling `source-map-support` via `TRIGGER_SOURCE_MAPS=false`. Also supports `node` for native source maps. (#2920) diff --git a/packages/cli-v3/src/entryPoints/dev-index-worker.ts b/packages/cli-v3/src/entryPoints/dev-index-worker.ts index da5c6ee750..e217127a00 100644 --- a/packages/cli-v3/src/entryPoints/dev-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/dev-index-worker.ts @@ -13,18 +13,14 @@ import { } from "@trigger.dev/core/v3/workers"; import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler"; import { readFile } from "node:fs/promises"; -import sourceMapSupport from "source-map-support"; +import { installSourceMapSupport } from "../utilities/sourceMaps.js"; import { registerResources } from "../indexing/registerResources.js"; import { env } from "std-env"; import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; import { detectRuntimeVersion } from "@trigger.dev/core/v3/build"; import { schemaToJsonSchema } from "@trigger.dev/schema-to-json"; -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { if (error instanceof Error) { diff --git a/packages/cli-v3/src/entryPoints/dev-run-worker.ts b/packages/cli-v3/src/entryPoints/dev-run-worker.ts index 7cd88ab5a9..405ea8aad4 100644 --- a/packages/cli-v3/src/entryPoints/dev-run-worker.ts +++ b/packages/cli-v3/src/entryPoints/dev-run-worker.ts @@ -63,17 +63,9 @@ import { import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc"; import { readFile } from "node:fs/promises"; import { setInterval, setTimeout } from "node:timers/promises"; -import sourceMapSupport from "source-map-support"; -import { env } from "std-env"; -import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; -import { VERSION } from "../version.js"; -import { promiseWithResolvers } from "@trigger.dev/core/utils"; - -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +import { installSourceMapSupport } from "../utilities/sourceMaps.js"; + +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { logError("Uncaught exception", { error, origin }); @@ -109,9 +101,8 @@ process.on("uncaughtException", function (error, origin) { } }); -process.title = `trigger-dev-run-worker (${ - getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version" -})`; +process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version" + })`; const heartbeatIntervalMs = getEnvVar("HEARTBEAT_INTERVAL_MS"); @@ -156,7 +147,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager( apiClientManager.clientOrThrow(), getEnvVar("TRIGGER_STREAM_URL", getEnvVar("TRIGGER_API_URL")) ?? "https://api.trigger.dev", (getEnvVar("TRIGGER_STREAMS_DEBUG") === "1" || getEnvVar("TRIGGER_STREAMS_DEBUG") === "true") ?? - false + false ); realtimeStreams.setGlobalManager(standardRealtimeStreamsManager); @@ -285,12 +276,12 @@ async function doBootstrap() { let bootstrapCache: | { - tracer: TriggerTracer; - tracingSDK: TracingSDK; - consoleInterceptor: ConsoleInterceptor; - config: TriggerConfig; - workerManifest: WorkerManifest; - } + tracer: TriggerTracer; + tracingSDK: TracingSDK; + consoleInterceptor: ConsoleInterceptor; + config: TriggerConfig; + workerManifest: WorkerManifest; + } | undefined; async function bootstrap() { diff --git a/packages/cli-v3/src/entryPoints/managed-index-worker.ts b/packages/cli-v3/src/entryPoints/managed-index-worker.ts index 5ff9f1b62e..f4e58fe9e0 100644 --- a/packages/cli-v3/src/entryPoints/managed-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-index-worker.ts @@ -13,18 +13,14 @@ import { } from "@trigger.dev/core/v3/workers"; import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler"; import { readFile } from "node:fs/promises"; -import sourceMapSupport from "source-map-support"; +import { installSourceMapSupport } from "../utilities/sourceMaps.js"; import { registerResources } from "../indexing/registerResources.js"; import { env } from "std-env"; import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; import { detectRuntimeVersion } from "@trigger.dev/core/v3/build"; import { schemaToJsonSchema } from "@trigger.dev/schema-to-json"; -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { if (error instanceof Error) { @@ -168,8 +164,8 @@ await sendMessageInCatalog( typeof processKeepAlive === "object" ? processKeepAlive : typeof processKeepAlive === "boolean" - ? { enabled: processKeepAlive } - : undefined, + ? { enabled: processKeepAlive } + : undefined, timings, }, importErrors, diff --git a/packages/cli-v3/src/entryPoints/managed-run-worker.ts b/packages/cli-v3/src/entryPoints/managed-run-worker.ts index f1512f27f0..31f646ee4c 100644 --- a/packages/cli-v3/src/entryPoints/managed-run-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-run-worker.ts @@ -63,17 +63,9 @@ import { import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc"; import { readFile } from "node:fs/promises"; import { setInterval, setTimeout } from "node:timers/promises"; -import sourceMapSupport from "source-map-support"; -import { env } from "std-env"; -import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; -import { VERSION } from "../version.js"; -import { promiseWithResolvers } from "@trigger.dev/core/utils"; - -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +import { installSourceMapSupport } from "../utilities/sourceMaps.js"; + +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { console.error("Uncaught exception", { error, origin }); @@ -136,7 +128,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager( apiClientManager.clientOrThrow(), getEnvVar("TRIGGER_STREAM_URL", getEnvVar("TRIGGER_API_URL")) ?? "https://api.trigger.dev", (getEnvVar("TRIGGER_STREAMS_DEBUG") === "1" || getEnvVar("TRIGGER_STREAMS_DEBUG") === "true") ?? - false + false ); realtimeStreams.setGlobalManager(standardRealtimeStreamsManager); @@ -262,12 +254,12 @@ async function doBootstrap() { let bootstrapCache: | { - tracer: TriggerTracer; - tracingSDK: TracingSDK; - consoleInterceptor: ConsoleInterceptor; - config: TriggerConfig; - workerManifest: WorkerManifest; - } + tracer: TriggerTracer; + tracingSDK: TracingSDK; + consoleInterceptor: ConsoleInterceptor; + config: TriggerConfig; + workerManifest: WorkerManifest; + } | undefined; async function bootstrap() { diff --git a/packages/cli-v3/src/utilities/sourceMaps.test.ts b/packages/cli-v3/src/utilities/sourceMaps.test.ts new file mode 100644 index 0000000000..5b8e220a81 --- /dev/null +++ b/packages/cli-v3/src/utilities/sourceMaps.test.ts @@ -0,0 +1,62 @@ + +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; +import sourceMapSupport from "source-map-support"; +import { installSourceMapSupport } from "./sourceMaps.js"; + +vi.mock("source-map-support", () => ({ + default: { + install: vi.fn(), + }, +})); + +describe("installSourceMapSupport", () => { + const originalEnv = process.env; + const originalSetSourceMapsEnabled = process.setSourceMapsEnabled; + + beforeEach(() => { + vi.clearAllMocks(); + process.env = { ...originalEnv }; + // Mock setSourceMapsEnabled if it doesn't exist (Node < 16.6) or restore it + process.setSourceMapsEnabled = vi.fn(); + }); + + afterEach(() => { + process.env = originalEnv; + process.setSourceMapsEnabled = originalSetSourceMapsEnabled; + }); + + it("should install source-map-support by default (undefined env var)", () => { + delete process.env.TRIGGER_SOURCE_MAPS; + installSourceMapSupport(); + expect(sourceMapSupport.install).toHaveBeenCalledWith({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); + }); + + it("should install source-map-support if env var is 'true'", () => { + process.env.TRIGGER_SOURCE_MAPS = "true"; + installSourceMapSupport(); + expect(sourceMapSupport.install).toHaveBeenCalled(); + }); + + it("should NOT install source-map-support if env var is 'false'", () => { + process.env.TRIGGER_SOURCE_MAPS = "false"; + installSourceMapSupport(); + expect(sourceMapSupport.install).not.toHaveBeenCalled(); + }); + + it("should NOT install source-map-support if env var is '0'", () => { + process.env.TRIGGER_SOURCE_MAPS = "0"; + installSourceMapSupport(); + expect(sourceMapSupport.install).not.toHaveBeenCalled(); + }); + + it("should enable native node source maps if env var is 'node'", () => { + process.env.TRIGGER_SOURCE_MAPS = "node"; + installSourceMapSupport(); + expect(sourceMapSupport.install).not.toHaveBeenCalled(); + expect(process.setSourceMapsEnabled).toHaveBeenCalledWith(true); + }); +}); diff --git a/packages/cli-v3/src/utilities/sourceMaps.ts b/packages/cli-v3/src/utilities/sourceMaps.ts new file mode 100644 index 0000000000..746caab94a --- /dev/null +++ b/packages/cli-v3/src/utilities/sourceMaps.ts @@ -0,0 +1,22 @@ +import sourceMapSupport from "source-map-support"; + +export function installSourceMapSupport() { + const sourceMaps = process.env.TRIGGER_SOURCE_MAPS; + + if (sourceMaps === "false" || sourceMaps === "0") { + return; + } + + if (sourceMaps === "node") { + if (process.setSourceMapsEnabled) { + process.setSourceMapsEnabled(true); + } + return; + } + + sourceMapSupport.install({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); +}