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
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export function constructWebpackConfigFunction({

// Orchestrion code-transform loader — Node server runtime only, never the edge compilation
if (runtime === 'server' && userSentryOptions._experimental?.useDiagnosticsChannelInjection) {
newConfig.plugins.push(sentryOrchestrionWebpackPlugin() as WebpackPluginInstance);
newConfig.plugins.push(sentryOrchestrionWebpackPlugin() as unknown as WebpackPluginInstance);
}

return newConfig;
Expand Down
5 changes: 2 additions & 3 deletions packages/server-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@
},
"./orchestrion/vite": {
"types": "./build/types/orchestrion/bundler/vite.d.ts",
"import": "./build/esm/orchestrion/bundler/vite.js"
"default": "./build/esm/orchestrion/bundler/vite.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"
"default": "./build/esm/orchestrion/bundler/webpack.js"
},
"./orchestrion/import-hook": {
"import": "./build/orchestrion/import-hook.mjs"
Expand Down
9 changes: 3 additions & 6 deletions packages/server-utils/src/orchestrion/bundler/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/webpack';

// Both branches use `createRequire` (never alias the CJS `require`) so bundlers consuming this
// module don't emit a "Critical dependency" warning.
Expand Down Expand Up @@ -46,10 +47,6 @@ export function getSentryInstrumentations(): InstrumentationConfig[] {
* does NOT inject the `__SENTRY_ORCHESTRION__.bundler` marker — that would disable the runtime
* module hook, which externalized packages still need (hybrid setup).
*/
export function sentryOrchestrionWebpackPlugin(): 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<typeof mod.default>);
return codeTransformerWebpack({ instrumentations: SENTRY_INSTRUMENTATIONS });
export function sentryOrchestrionWebpackPlugin(): ReturnType<typeof codeTransformer> {
return codeTransformer({ instrumentations: SENTRY_INSTRUMENTATIONS });
}
14 changes: 2 additions & 12 deletions packages/server-utils/src/orchestrion/runtime/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ export function registerDiagnosticsChannelInjection(options?: RegisterDiagnostic
nodeRequire = createRequire(import.meta.url);
/*! rollup-include-esm-only-end */

const tracingHooksDir = options?.tracingHooksDir;
const requireFromHooksDir = tracingHooksDir ? createRequire(thisModuleUrl) : undefined;

// `Module.registerHooks` / `Module.register` are newer than the @types/node
// we build against, hence the cast.
const mod = Module as unknown as {
Expand All @@ -105,11 +102,7 @@ export function registerDiagnosticsChannelInjection(options?: RegisterDiagnostic
// We require() the module here so that we can synchronously load it,
// including from a CommonJS Sentry build, without bundlers pulling in.
// All versions in stableSyncHooks support this.
const { initialize, resolve, load } = (
requireFromHooksDir
? requireFromHooksDir(`${tracingHooksDir}/hook-sync.mjs`)
: nodeRequire('@apm-js-collab/tracing-hooks/hook-sync.mjs')
) as {
const { initialize, resolve, load } = nodeRequire('@apm-js-collab/tracing-hooks/hook-sync.mjs') as {
initialize: (opts: { instrumentations: unknown }) => void;
resolve: unknown;
load: unknown;
Expand All @@ -124,10 +117,7 @@ export function registerDiagnosticsChannelInjection(options?: RegisterDiagnostic
// `Module.register` resolves ESM-style: a bare package specifier is resolved against
// `parentURL`, but a filesystem path (the `tracingHooksDir` override) is not a valid ESM
// specifier and must be passed as a file:// URL.
const hookSpecifier = tracingHooksDir
? pathToFileURL(`${tracingHooksDir}/hook.mjs`).href
: '@apm-js-collab/tracing-hooks/hook.mjs';
mod.register(hookSpecifier, {
mod.register('@apm-js-collab/tracing-hooks/hook.mjs', {
parentURL: thisModuleUrl,
data: { instrumentations: SENTRY_INSTRUMENTATIONS },
});
Expand Down
Loading