From 3b9ac683f80796aae92bf126f9ca6746349bac12 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 16 Jul 2026 11:18:59 +0100 Subject: [PATCH 1/2] feat(server-utils): Allow passing custom transforms to orchestrion --- .../astro-7-orchestrion/package.json | 2 +- .../nuxt-4-orchestrion/package.json | 2 +- .../sveltekit-2-orchestrion/package.json | 2 +- packages/bun/package.json | 2 +- packages/server-utils/package.json | 2 +- .../src/orchestrion/bundler/options.ts | 30 +++++++++++++++---- .../src/orchestrion/bundler/webpack.ts | 10 +++---- yarn.lock | 8 ++--- 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/astro-7-orchestrion/package.json b/dev-packages/e2e-tests/test-applications/astro-7-orchestrion/package.json index aeb882821dd2..83c12f774095 100644 --- a/dev-packages/e2e-tests/test-applications/astro-7-orchestrion/package.json +++ b/dev-packages/e2e-tests/test-applications/astro-7-orchestrion/package.json @@ -24,7 +24,7 @@ "mysql": "^2.18.1" }, "devDependencies": { - "@apm-js-collab/code-transformer-bundler-plugins": "^0.5.0" + "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.0" }, "volta": { "node": "22.22.0", diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4-orchestrion/package.json b/dev-packages/e2e-tests/test-applications/nuxt-4-orchestrion/package.json index fe2f8129165d..0ec5d68db235 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-4-orchestrion/package.json +++ b/dev-packages/e2e-tests/test-applications/nuxt-4-orchestrion/package.json @@ -27,7 +27,7 @@ "vue-router": "^5.1.0" }, "devDependencies": { - "@apm-js-collab/code-transformer-bundler-plugins": "^0.5.0", + "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.0", "@playwright/test": "~1.56.0", "@sentry-internal/test-utils": "link:../../../test-utils" }, diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json index 63bdd148f9ac..a3cc62e226b4 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json @@ -24,7 +24,7 @@ "mysql": "^2.18.1" }, "devDependencies": { - "@apm-js-collab/code-transformer-bundler-plugins": "^0.5.0", + "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.0", "@playwright/test": "~1.56.0", "@sentry-internal/test-utils": "link:../../../test-utils", "@sveltejs/adapter-auto": "^7.0.1", diff --git a/packages/bun/package.json b/packages/bun/package.json index f8793cdc0263..660dc6344500 100644 --- a/packages/bun/package.json +++ b/packages/bun/package.json @@ -49,7 +49,7 @@ "access": "public" }, "dependencies": { - "@apm-js-collab/code-transformer-bundler-plugins": "^0.6.1", + "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.0", "@sentry/core": "10.65.0", "@sentry/node": "10.65.0", "@sentry/server-utils": "10.65.0" diff --git a/packages/server-utils/package.json b/packages/server-utils/package.json index a905ad45b5f8..ef4301cf7eaf 100644 --- a/packages/server-utils/package.json +++ b/packages/server-utils/package.json @@ -116,7 +116,7 @@ "access": "public" }, "dependencies": { - "@apm-js-collab/code-transformer-bundler-plugins": "^0.6.1", + "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.0", "@apm-js-collab/code-transformer": "^0.18.0", "@apm-js-collab/tracing-hooks": "^0.13.0", "@sentry/conventions": "^0.16.0", diff --git a/packages/server-utils/src/orchestrion/bundler/options.ts b/packages/server-utils/src/orchestrion/bundler/options.ts index 2fa610d02b51..f554a22ab2d4 100644 --- a/packages/server-utils/src/orchestrion/bundler/options.ts +++ b/packages/server-utils/src/orchestrion/bundler/options.ts @@ -1,4 +1,4 @@ -import type { InstrumentationConfig } from '@apm-js-collab/code-transformer'; +import type { InstrumentationConfig, CustomTransform } from '@apm-js-collab/code-transformer'; import { SENTRY_INSTRUMENTATIONS } from '../config'; import type codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/rollup'; @@ -7,8 +7,20 @@ export type PluginOptions = { * Additional instrumentations to include with the default instrumentation. */ instrumentations?: InstrumentationConfig[]; + /** + * Custom transforms that can be applied using the `transform` option in each `InstrumentationConfig`. + */ + customTransforms?: Record; + /** + * Whether to inject the global diagnostics. + * + * Defaults to `true`. + */ + shouldInjectDiagnostics?: boolean; }; +type OrchestrionTransformOptions = Parameters[0]; + /** * The `@apm-js-collab/code-transformer-bundler-plugins` options shared by every * orchestrion bundler plugin. @@ -19,10 +31,18 @@ export type PluginOptions = { * visible to the runtime). */ export function orchestrionTransformOptions(options: PluginOptions): Parameters[0] { - return { + const injectDiagnostics = (diag: { transformedModules: string[]; failedModules: string[] }) => { + return `(globalThis.__SENTRY_ORCHESTRION__=globalThis.__SENTRY_ORCHESTRION__||{}).bundler=${JSON.stringify(diag.transformedModules)};`; + }; + + const outputOptions: OrchestrionTransformOptions = { instrumentations: [...SENTRY_INSTRUMENTATIONS, ...(options.instrumentations || [])], - injectDiagnostics: (diag: { transformedModules: string[]; failedModules: string[] }) => { - return `(globalThis.__SENTRY_ORCHESTRION__=globalThis.__SENTRY_ORCHESTRION__||{}).bundler=${JSON.stringify(diag.transformedModules)};`; - }, + customTransforms: options.customTransforms, }; + + if (options.shouldInjectDiagnostics !== false) { + outputOptions.injectDiagnostics = injectDiagnostics; + } + + return outputOptions; } diff --git a/packages/server-utils/src/orchestrion/bundler/webpack.ts b/packages/server-utils/src/orchestrion/bundler/webpack.ts index 04eb56a2c6b9..e6ea99b3045c 100644 --- a/packages/server-utils/src/orchestrion/bundler/webpack.ts +++ b/packages/server-utils/src/orchestrion/bundler/webpack.ts @@ -5,6 +5,8 @@ import { createRequire } from 'node:module'; import { dirname } from 'node:path'; import type { InstrumentationConfig } from '@apm-js-collab/code-transformer'; import { SENTRY_INSTRUMENTATIONS } from '../config'; +import type { PluginOptions } from './options'; +import { orchestrionTransformOptions } from './options'; // Both branches use `createRequire` (never alias the CJS `require`) so bundlers consuming this // module don't emit a "Critical dependency" warning. @@ -42,14 +44,12 @@ export function getSentryInstrumentations(): InstrumentationConfig[] { } /** - * The code-transform webpack plugin, pre-fed the instrumentation config. Unlike the Vite plugin it - * does NOT inject the `__SENTRY_ORCHESTRION__.bundler` marker — that would disable the runtime - * module hook, which externalized packages still need (hybrid setup). + * The code-transform webpack plugin, pre-fed the instrumentation config */ -export function sentryOrchestrionWebpackPlugin(): unknown { +export function sentryOrchestrionWebpackPlugin(options: PluginOptions = {}): unknown { const mod = getOrchestrionRequire()('@apm-js-collab/code-transformer-bundler-plugins/webpack') as { default?: (options: { instrumentations: InstrumentationConfig[] }) => unknown; }; const codeTransformerWebpack = mod.default ?? (mod as unknown as NonNullable); - return codeTransformerWebpack({ instrumentations: SENTRY_INSTRUMENTATIONS }); + return codeTransformerWebpack(orchestrionTransformOptions(options)); } diff --git a/yarn.lock b/yarn.lock index 7b70dded22ba..bb0c06041615 100644 --- a/yarn.lock +++ b/yarn.lock @@ -404,10 +404,10 @@ dependencies: json-schema-to-ts "^3.1.1" -"@apm-js-collab/code-transformer-bundler-plugins@^0.6.1": - version "0.6.1" - resolved "https://registry.yarnpkg.com/@apm-js-collab/code-transformer-bundler-plugins/-/code-transformer-bundler-plugins-0.6.1.tgz#29bf79167411b8607f02db177250b8f7c16d93e1" - integrity sha512-TDvypsLUk/W202Y1JBE6I2enQalWjbYXKnxpELWEZn6GLoIcGFii69ljh948hdAzKZJ/wg0Uwivz72a/szoOBQ== +"@apm-js-collab/code-transformer-bundler-plugins@^0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@apm-js-collab/code-transformer-bundler-plugins/-/code-transformer-bundler-plugins-0.7.0.tgz#499cb4730570e4f4bc3a1e77739dc1fb17839a7a" + integrity sha512-huqdbQqE1lTUM2uud/qBY664o5qGPLrI/3ipGRNcTP37otpaVOb6omfIU/8QyR4aObhkpgnFl0ywtoAJZ+y2jw== dependencies: "@apm-js-collab/code-transformer" "^0.18.0" es-module-lexer "^2.1.0" From 1637afea843e2d6a915771efd402b69f81066848 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 16 Jul 2026 11:37:58 +0100 Subject: [PATCH 2/2] Fix --- .../src/orchestrion/bundler/options.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/server-utils/src/orchestrion/bundler/options.ts b/packages/server-utils/src/orchestrion/bundler/options.ts index f554a22ab2d4..21257daa8aff 100644 --- a/packages/server-utils/src/orchestrion/bundler/options.ts +++ b/packages/server-utils/src/orchestrion/bundler/options.ts @@ -1,6 +1,6 @@ import type { InstrumentationConfig, CustomTransform } from '@apm-js-collab/code-transformer'; import { SENTRY_INSTRUMENTATIONS } from '../config'; -import type codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/rollup'; +import type { CodeTransformerPluginOptions } from '@apm-js-collab/code-transformer-bundler-plugins/core'; export type PluginOptions = { /** @@ -19,8 +19,6 @@ export type PluginOptions = { shouldInjectDiagnostics?: boolean; }; -type OrchestrionTransformOptions = Parameters[0]; - /** * The `@apm-js-collab/code-transformer-bundler-plugins` options shared by every * orchestrion bundler plugin. @@ -30,19 +28,22 @@ type OrchestrionTransformOptions = Parameters[0]; * bundler path ran (rather than relying on a build-time flag that wouldn't be * visible to the runtime). */ -export function orchestrionTransformOptions(options: PluginOptions): Parameters[0] { - const injectDiagnostics = (diag: { transformedModules: string[]; failedModules: string[] }) => { - return `(globalThis.__SENTRY_ORCHESTRION__=globalThis.__SENTRY_ORCHESTRION__||{}).bundler=${JSON.stringify(diag.transformedModules)};`; - }; +export function orchestrionTransformOptions(options: PluginOptions): CodeTransformerPluginOptions { + const instrumentations = [...SENTRY_INSTRUMENTATIONS, ...(options.instrumentations || [])]; + const customTransforms = options.customTransforms; - const outputOptions: OrchestrionTransformOptions = { - instrumentations: [...SENTRY_INSTRUMENTATIONS, ...(options.instrumentations || [])], - customTransforms: options.customTransforms, - }; - - if (options.shouldInjectDiagnostics !== false) { - outputOptions.injectDiagnostics = injectDiagnostics; + if (options.shouldInjectDiagnostics === false) { + return { + instrumentations, + customTransforms, + }; } - return outputOptions; + return { + instrumentations, + customTransforms, + injectDiagnostics: (diag: { transformedModules: string[]; failedModules: string[] }) => { + return `(globalThis.__SENTRY_ORCHESTRION__=globalThis.__SENTRY_ORCHESTRION__||{}).bundler=${JSON.stringify(diag.transformedModules)};`; + }, + }; }