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 5a3d5dcacb28..3499021d83a2 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.66.0", "@sentry/node": "10.66.0", "@sentry/server-utils": "10.66.0" diff --git a/packages/server-utils/package.json b/packages/server-utils/package.json index b9cc17f4f7db..d56b6dd17d1e 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..21257daa8aff 100644 --- a/packages/server-utils/src/orchestrion/bundler/options.ts +++ b/packages/server-utils/src/orchestrion/bundler/options.ts @@ -1,12 +1,22 @@ -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'; +import type { CodeTransformerPluginOptions } from '@apm-js-collab/code-transformer-bundler-plugins/core'; 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; }; /** @@ -18,9 +28,20 @@ export type PluginOptions = { * 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] { +export function orchestrionTransformOptions(options: PluginOptions): CodeTransformerPluginOptions { + const instrumentations = [...SENTRY_INSTRUMENTATIONS, ...(options.instrumentations || [])]; + const customTransforms = options.customTransforms; + + if (options.shouldInjectDiagnostics === false) { + return { + instrumentations, + customTransforms, + }; + } + return { - instrumentations: [...SENTRY_INSTRUMENTATIONS, ...(options.instrumentations || [])], + instrumentations, + customTransforms, injectDiagnostics: (diag: { transformedModules: string[]; failedModules: string[] }) => { return `(globalThis.__SENTRY_ORCHESTRION__=globalThis.__SENTRY_ORCHESTRION__||{}).bundler=${JSON.stringify(diag.transformedModules)};`; }, 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"