diff --git a/packages/cli-v3/src/entryPoints/dev-index-worker.ts b/packages/cli-v3/src/entryPoints/dev-index-worker.ts index da5c6ee750..971bda1ec7 100644 --- a/packages/cli-v3/src/entryPoints/dev-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/dev-index-worker.ts @@ -13,18 +13,29 @@ 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 { 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, -}); +let sourceMapSupportInstalled = false; + +async function installSourceMapSupport() { + if (sourceMapSupportInstalled) return; + sourceMapSupportInstalled = true; + + try { + const sourceMapSupport = await import("source-map-support"); + sourceMapSupport.default.install({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); + } catch (error) { + console.warn("Failed to install source-map-support:", error); + } +} process.on("uncaughtException", function (error, origin) { if (error instanceof Error) { @@ -80,6 +91,11 @@ async function bootstrap() { const { config } = await importConfig(buildManifest.configPath); + // Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection) + if (config.sourceMapSupport !== false) { + installSourceMapSupport(); + } + // This needs to run or the PrismaInstrumentation will throw an error const tracingSDK = new TracingSDK({ url: env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318", diff --git a/packages/cli-v3/src/entryPoints/dev-run-worker.ts b/packages/cli-v3/src/entryPoints/dev-run-worker.ts index 7cd88ab5a9..62a96c53f4 100644 --- a/packages/cli-v3/src/entryPoints/dev-run-worker.ts +++ b/packages/cli-v3/src/entryPoints/dev-run-worker.ts @@ -63,17 +63,28 @@ 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, -}); +let sourceMapSupportInstalled = false; + +async function installSourceMapSupport() { + if (sourceMapSupportInstalled) return; + sourceMapSupportInstalled = true; + + try { + const sourceMapSupport = await import("source-map-support"); + sourceMapSupport.default.install({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); + } catch (error) { + console.warn("Failed to install source-map-support:", error); + } +} process.on("uncaughtException", function (error, origin) { logError("Uncaught exception", { error, origin }); @@ -271,6 +282,11 @@ async function doBootstrap() { }); } + // Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection) + if (config.sourceMapSupport !== false) { + installSourceMapSupport(); + } + log("Bootstrapped worker"); return { diff --git a/packages/cli-v3/src/entryPoints/managed-index-worker.ts b/packages/cli-v3/src/entryPoints/managed-index-worker.ts index 5ff9f1b62e..86dbbc8e07 100644 --- a/packages/cli-v3/src/entryPoints/managed-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-index-worker.ts @@ -13,18 +13,29 @@ 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 { 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, -}); +let sourceMapSupportInstalled = false; + +async function installSourceMapSupport() { + if (sourceMapSupportInstalled) return; + sourceMapSupportInstalled = true; + + try { + const sourceMapSupport = await import("source-map-support"); + sourceMapSupport.default.install({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); + } catch (error) { + console.warn("Failed to install source-map-support:", error); + } +} process.on("uncaughtException", function (error, origin) { if (error instanceof Error) { @@ -80,6 +91,11 @@ async function bootstrap() { const { config } = await importConfig(buildManifest.configPath); + // Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection) + if (config.sourceMapSupport !== false) { + installSourceMapSupport(); + } + // This needs to run or the PrismaInstrumentation will throw an error const tracingSDK = new TracingSDK({ url: env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318", diff --git a/packages/cli-v3/src/entryPoints/managed-run-worker.ts b/packages/cli-v3/src/entryPoints/managed-run-worker.ts index f1512f27f0..a0d1ef8474 100644 --- a/packages/cli-v3/src/entryPoints/managed-run-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-run-worker.ts @@ -63,17 +63,28 @@ 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, -}); +let sourceMapSupportInstalled = false; + +async function installSourceMapSupport() { + if (sourceMapSupportInstalled) return; + sourceMapSupportInstalled = true; + + try { + const sourceMapSupport = await import("source-map-support"); + sourceMapSupport.default.install({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); + } catch (error) { + console.warn("Failed to install source-map-support:", error); + } +} process.on("uncaughtException", function (error, origin) { console.error("Uncaught exception", { error, origin }); @@ -250,6 +261,11 @@ async function doBootstrap() { }); } + // Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection) + if (config.sourceMapSupport !== false) { + installSourceMapSupport(); + } + return { tracer, tracingSDK, diff --git a/packages/core/src/v3/config.ts b/packages/core/src/v3/config.ts index 9c6871a264..c84fc880ad 100644 --- a/packages/core/src/v3/config.ts +++ b/packages/core/src/v3/config.ts @@ -171,6 +171,15 @@ export type TriggerConfig = { */ disableConsoleInterceptor?: boolean; + /** + * Enable or disable source-map-support for enhanced stack traces. + * Disabling this can help prevent OOM issues when using Sentry's debug ID injection + * with large projects that have many bundled files. + * + * @default true + */ + sourceMapSupport?: boolean; + build?: { /** * Add custom conditions to the esbuild build. For example, if you are importing `ai/rsc`, you'll need to add "react-server" condition.