Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,48 @@
"require": {
"default": "./build/cjs/preload.js"
}
},
"./bundler-plugins/vite": {
"import": {
"types": "./build/types/bundler-plugins/vite.d.ts",
"default": "./build/esm/bundler-plugins/vite.js"
}
},
"./bundler-plugins/rollup": {
"import": {
"types": "./build/types/bundler-plugins/rollup.d.ts",
"default": "./build/esm/bundler-plugins/rollup.js"
}
},
"./bundler-plugins/webpack": {
"import": {
"types": "./build/types/bundler-plugins/webpack.d.ts",
"default": "./build/esm/bundler-plugins/webpack.js"
}
},
"./bundler-plugins/esbuild": {
"import": {
"types": "./build/types/bundler-plugins/esbuild.d.ts",
"default": "./build/esm/bundler-plugins/esbuild.js"
}
}
},
"typesVersions": {
"<5.0": {
"build/types/index.d.ts": [
"build/types-ts3.8/index.d.ts"
],
"bundler-plugins/vite": [
"build/types-ts3.8/bundler-plugins/vite.d.ts"
],
"bundler-plugins/rollup": [
"build/types-ts3.8/bundler-plugins/rollup.d.ts"
],
"bundler-plugins/webpack": [
"build/types-ts3.8/bundler-plugins/webpack.d.ts"
],
"bundler-plugins/esbuild": [
"build/types-ts3.8/bundler-plugins/esbuild.d.ts"
]
}
},
Expand All @@ -68,6 +104,7 @@
"@opentelemetry/api": "^1.9.1",
"@opentelemetry/instrumentation": "^0.220.0",
"@opentelemetry/sdk-trace-base": "^2.9.0",
"@sentry/bundler-plugins": "10.64.0",
"@sentry/conventions": "^0.15.1",
"@sentry/core": "10.65.0",
"@sentry/node-core": "10.65.0",
Expand Down
13 changes: 12 additions & 1 deletion packages/node/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ export default [
...makeOtelLoaders('./build', 'otel', { injectDiagnosticsChannel: true }),
...makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.ts', 'src/init.ts', 'src/preload.ts'],
entrypoints: [
'src/index.ts',
'src/init.ts',
'src/preload.ts',
// Combined Sentry bundler plugins + orchestrion code transform, exposed
// ESM-only via the `@sentry/node/bundler-plugins/*` subpath exports
// (they import the ESM-only `@sentry/server-utils/orchestrion/*` plugins).
'src/bundler-plugins/vite.ts',
'src/bundler-plugins/rollup.ts',
'src/bundler-plugins/webpack.ts',
'src/bundler-plugins/esbuild.ts',
],
packageSpecificConfig: {
external: [/^@sentry\/opentelemetry/],
output: {
Expand Down
43 changes: 43 additions & 0 deletions packages/node/src/bundler-plugins/esbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { sentryEsbuildPlugin as sentryEsbuildBundlerPlugin } from '@sentry/bundler-plugins/esbuild';
import type { SentryEsbuildPluginOptions as SentryEsbuildPluginOptionsBase } from '@sentry/bundler-plugins/esbuild';
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/esbuild';

export type SentryEsbuildPluginOptions = SentryEsbuildPluginOptionsBase & {
/**
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
*/
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
};

type EsbuildPlugin = ReturnType<typeof sentryOrchestrionPlugin>;

/**
* esbuild plugin that bundles the Sentry esbuild bundler plugin (source maps,
* release injection, …) together with the orchestrion code transform
* (build-time `diagnostics_channel` instrumentation for Node libraries).
*
* It is a drop-in replacement for `@sentry/bundler-plugins/esbuild` and accepts
* the same options.
*
* esbuild does not flatten nested `plugins` arrays, so this returns a single
* plugin that runs both plugins' `setup` against the same build.
*
* @example
* ```ts
* // build.mjs
* import { sentryEsbuildPlugin } from '@sentry/node/bundler-plugins/esbuild';
* await esbuild.build({ plugins: [sentryEsbuildPlugin({ org: '…', project: '…' })] });
* ```
*/
export function sentryEsbuildPlugin(options?: SentryEsbuildPluginOptions): EsbuildPlugin {
const bundlerPlugin = sentryEsbuildBundlerPlugin(options);
const orchestrionPlugin = sentryOrchestrionPlugin(options);

return {
name: 'sentry-node-esbuild',
setup(build): void {
bundlerPlugin.setup(build);
orchestrionPlugin.setup(build);
},
};
}
35 changes: 35 additions & 0 deletions packages/node/src/bundler-plugins/rollup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { sentryRollupPlugin as sentryRollupBundlerPlugin } from '@sentry/bundler-plugins/rollup';
import type { SentryRollupPluginOptions as SentryRollupPluginOptionsBase } from '@sentry/bundler-plugins/rollup';
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/rollup';

export type SentryRollupPluginOptions = SentryRollupPluginOptionsBase & {
/**
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
*/
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
};

type RollupPlugin = ReturnType<typeof sentryOrchestrionPlugin>;

/**
* Rollup plugin that bundles the Sentry Rollup bundler plugin (source maps,
* release injection, bundle size optimizations, …) together with the
* orchestrion code transform (build-time `diagnostics_channel` instrumentation
* for Node libraries).
*
* It is a drop-in replacement for `@sentry/bundler-plugins/rollup` and accepts
* the same options.
*
* Rollup flattens nested `plugins` arrays, so `plugins: [sentryRollupPlugin(opts)]`
* works directly.
*
* @example
* ```ts
* // rollup.config.js
* import { sentryRollupPlugin } from '@sentry/node/bundler-plugins/rollup';
* export default { plugins: [sentryRollupPlugin({ org: '…', project: '…' })] };
* ```
*/
export function sentryRollupPlugin(options?: SentryRollupPluginOptions): RollupPlugin[] {
return [sentryRollupBundlerPlugin(options), sentryOrchestrionPlugin(options)];
}
35 changes: 35 additions & 0 deletions packages/node/src/bundler-plugins/vite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { sentryVitePlugin as sentryViteBundlerPlugin } from '@sentry/bundler-plugins/vite';
import type { SentryVitePluginOptions as SentryVitePluginOptionsBase } from '@sentry/bundler-plugins/vite';
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/vite';

export type SentryVitePluginOptions = SentryVitePluginOptionsBase & {
/**
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
*/
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
};

type VitePlugin = ReturnType<typeof sentryOrchestrionPlugin>;

/**
* Vite plugin that bundles the Sentry Vite bundler plugin (source maps, release
* injection, bundle size optimizations, …) together with the orchestrion code
* transform (build-time `diagnostics_channel` instrumentation for Node
* libraries).
*
* It is a drop-in replacement for `@sentry/bundler-plugins/vite` and accepts the
* same options.
*
* Vite flattens nested `plugins` arrays, so `plugins: [sentryVitePlugin(opts)]`
* works directly.
*
* @example
* ```ts
* // vite.config.ts
* import { sentryVitePlugin } from '@sentry/node/bundler-plugins/vite';
* export default { plugins: [sentryVitePlugin({ org: '…', project: '…' })] };
* ```
*/
export function sentryVitePlugin(options?: SentryVitePluginOptions): VitePlugin[] {
return [...sentryViteBundlerPlugin(options), sentryOrchestrionPlugin(options)];
}
44 changes: 44 additions & 0 deletions packages/node/src/bundler-plugins/webpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { sentryWebpackPlugin as sentryWebpackBundlerPlugin } from '@sentry/bundler-plugins/webpack';
import type { SentryWebpackPluginOptions as SentryWebpackPluginOptionsBase } from '@sentry/bundler-plugins/webpack';
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/webpack';

export type SentryWebpackPluginOptions = SentryWebpackPluginOptionsBase & {
/**
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
*/
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
};

type WebpackCompiler = Parameters<ReturnType<typeof sentryOrchestrionPlugin>['apply']>[0];

/**
* webpack plugin that bundles the Sentry webpack bundler plugin (source maps,
* release injection, …) together with the orchestrion code transform
* (build-time `diagnostics_channel` instrumentation for Node libraries).
*
* It is a drop-in replacement for `@sentry/bundler-plugins/webpack` and accepts
* the same options.
*
* webpack does not flatten nested `plugins` arrays, so this returns a single
* plugin that runs both plugins' `apply` against the same compiler.
*
* @example
* ```ts
* // webpack.config.mjs
* import { sentryWebpackPlugin } from '@sentry/node/bundler-plugins/webpack';
* export default { plugins: [sentryWebpackPlugin({ org: '…', project: '…' })] };
* ```
*/
export function sentryWebpackPlugin(options?: SentryWebpackPluginOptions): {
apply: (compiler: WebpackCompiler) => void;
} {
const bundlerPlugin = sentryWebpackBundlerPlugin(options);
const orchestrionPlugin = sentryOrchestrionPlugin(options);

return {
apply(compiler: WebpackCompiler): void {
bundlerPlugin.apply(compiler);
orchestrionPlugin.apply(compiler);
},
};
}
22 changes: 21 additions & 1 deletion packages/server-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@
"types": "./build/types/orchestrion/bundler/vite.d.ts",
"import": "./build/esm/orchestrion/bundler/vite.js"
},
"./orchestrion/rollup": {
"types": "./build/types/orchestrion/bundler/rollup.d.ts",
"import": "./build/esm/orchestrion/bundler/rollup.js"
},
"./orchestrion/webpack": {
"types": "./build/types/orchestrion/bundler/webpack.d.ts",
"import": "./build/esm/orchestrion/bundler/webpack.js",
"require": "./build/cjs/orchestrion/bundler/webpack.js"
},
"./orchestrion/esbuild": {
"types": "./build/types/orchestrion/bundler/esbuild.d.ts",
"import": "./build/esm/orchestrion/bundler/esbuild.js"
},
"./orchestrion/import-hook": {
"import": "./build/orchestrion/import-hook.mjs"
}
Expand All @@ -67,8 +75,14 @@
"orchestrion/vite": [
"build/types-ts3.8/orchestrion/bundler/vite.d.ts"
],
"orchestrion/rollup": [
"build/types-ts3.8/orchestrion/bundler/rollup.d.ts"
],
"orchestrion/webpack": [
"build/types-ts3.8/orchestrion/bundler/webpack.d.ts"
],
"orchestrion/esbuild": [
"build/types-ts3.8/orchestrion/bundler/esbuild.d.ts"
]
},
"*": {
Expand All @@ -84,8 +98,14 @@
"orchestrion/vite": [
"build/types/orchestrion/bundler/vite.d.ts"
],
"orchestrion/rollup": [
"build/types/orchestrion/bundler/rollup.d.ts"
],
"orchestrion/webpack": [
"build/types/orchestrion/bundler/webpack.d.ts"
],
"orchestrion/esbuild": [
"build/types/orchestrion/bundler/esbuild.d.ts"
]
}
},
Expand All @@ -94,13 +114,13 @@
},
"dependencies": {
"@apm-js-collab/code-transformer-bundler-plugins": "^0.5.0",
"@apm-js-collab/code-transformer": "^0.15.0",
"@apm-js-collab/tracing-hooks": "^0.10.1",
"@sentry/conventions": "^0.15.1",
"@sentry/core": "10.65.0",
"magic-string": "~0.30.0"
},
"devDependencies": {
"@apm-js-collab/code-transformer": "^0.15.0",
"@types/node": "^18.19.1",
"vite": "^6.4.3"
},
Expand Down
10 changes: 6 additions & 4 deletions packages/server-utils/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export default [
...orchestrionRuntimeHooks,
...makeNPMConfigVariants(
makeBaseNPMConfig({
// `src/orchestrion/config/index.ts` and `src/orchestrion/bundler/vite.ts` are
// loaded via dedicated subpath exports (`.../orchestrion/config`,
// `.../orchestrion/vite`) — neither is reachable from `src/index.ts`, so we
// list them as separate entrypoints to guarantee they end up in build/esm
// `src/orchestrion/config/index.ts` and the `src/orchestrion/bundler/*.ts`
// plugins are loaded via dedicated subpath exports (`.../orchestrion/config`,
// `.../orchestrion/vite`, etc.) — none are reachable from `src/index.ts`, so
// we list them as separate entrypoints to guarantee they end up in build/esm
// and build/cjs. `src/orchestrion/index.ts` backs the `./orchestrion`
// subpath export.
entrypoints: [
Expand All @@ -34,7 +34,9 @@ export default [
// `Sentry.init()` to install the channel-injection hooks.
'src/orchestrion/runtime/register.ts',
'src/orchestrion/bundler/vite.ts',
'src/orchestrion/bundler/rollup.ts',
'src/orchestrion/bundler/webpack.ts',
'src/orchestrion/bundler/esbuild.ts',
],
packageSpecificConfig: {
output: {
Expand Down
42 changes: 42 additions & 0 deletions packages/server-utils/src/orchestrion/bundler/esbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/esbuild';
import { instrumentedModuleNames, withoutInstrumentedExternals } from '../config';
import type { PluginOptions } from './options';
import { orchestrionTransformOptions } from './options';

/**
* esbuild plugin that runs the orchestrion code transform on the bundled output.
*
* Use when bundling a Node app with esbuild. For unbundled Node processes use the
* runtime hook instead (`node --import @sentry/node/orchestrion app.js`).
*
* esbuild does not flatten nested `plugins` arrays, so this returns a single
* plugin that strips instrumented packages from an `external` denylist before
* delegating to the upstream transform.
*
* @example
* ```ts
* // build.mjs
* import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/esbuild';
* await esbuild.build({ plugins: [sentryOrchestrionPlugin()] });
* ```
*/
export function sentryOrchestrionPlugin(options: PluginOptions = {}): ReturnType<typeof codeTransformer> {
const transformer = codeTransformer(orchestrionTransformOptions(options));

return {
name: 'sentry-orchestrion',
async setup(build): Promise<void> {
// Strip instrumented packages from an `external` denylist so esbuild
// bundles them and the transform's `onLoad` actually sees their source;
// an externalized dependency is resolved from `node_modules` at runtime
// and never gets the diagnostics_channel calls injected. Mutating
// `initialOptions` inside `setup` is respected by esbuild — the upstream
// plugin sets `initialOptions.metafile` the same way.
build.initialOptions.external = withoutInstrumentedExternals(
build.initialOptions.external,
instrumentedModuleNames(options.instrumentations),
);
await transformer.setup(build);
},
};
}
28 changes: 28 additions & 0 deletions packages/server-utils/src/orchestrion/bundler/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { InstrumentationConfig } from '@apm-js-collab/code-transformer';
import { SENTRY_INSTRUMENTATIONS } from '../config';
import type codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/rollup';

export type PluginOptions = {
/**
* Additional instrumentations to include with the default instrumentation.
*/
instrumentations?: InstrumentationConfig[];
};

/**
* The `@apm-js-collab/code-transformer-bundler-plugins` options shared by every
* orchestrion bundler plugin.
*
* `injectDiagnostics` sets `globalThis.__SENTRY_ORCHESTRION__.bundler = true` at
* app boot so the `_experimentalSetupOrchestrion()` detector can confirm the
* 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<typeof codeTransformer>[0] {
return {
instrumentations: [...SENTRY_INSTRUMENTATIONS, ...(options.instrumentations || [])],
injectDiagnostics: () => {
return '(globalThis.__SENTRY_ORCHESTRION__=globalThis.__SENTRY_ORCHESTRION__||{}).bundler=true;';
},
};
}
Loading
Loading