11import codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/bun' ;
2- import { INSTRUMENTED_MODULE_NAMES , withoutInstrumentedExternals } from '../config' ;
2+ import { instrumentedModuleNames , withoutInstrumentedExternals } from '../config' ;
33import { ORCHESTRION_BUNDLER_MARKER_BANNER } from './moduleInjectedTransform' ;
44import type { PluginOptions } from './options' ;
55import { orchestrionTransformOptions } from './options' ;
@@ -48,6 +48,10 @@ export function sentryOrchestrionPlugin(options: PluginOptions = {}): UnknownPlu
4848 setup : ( build : BunPluginBuilder ) => void ;
4949 } ;
5050
51+ // Custom `instrumentations` must be bundled too, otherwise those packages can stay externalized
52+ // and their transform never runs, so fold them into the names we un-externalize and warn about.
53+ const moduleNames = instrumentedModuleNames ( options . instrumentations ) ;
54+
5155 return {
5256 name : 'sentry-orchestrion' ,
5357 setup ( build : BunPluginBuilder ) : void {
@@ -64,7 +68,7 @@ export function sentryOrchestrionPlugin(options: PluginOptions = {}): UnknownPlu
6468 // `node_modules` at runtime and never passes through the transform's `onLoad`, so its
6569 // diagnostics_channel calls would be silently never injected. Bun has no runtime fallback
6670 // here, so bundling is the only injection path.
67- build . config . external = withoutInstrumentedExternals ( build . config . external ) ;
71+ build . config . external = withoutInstrumentedExternals ( build . config . external , moduleNames ) ;
6872
6973 // A blanket externalization strategy like `packages: 'external'` or `'*'` in `external`
7074 // externalizes instrumented packages too, and `withoutInstrumentedExternals` only strips
@@ -84,7 +88,7 @@ export function sentryOrchestrionPlugin(options: PluginOptions = {}): UnknownPlu
8488 console . warn (
8589 `[Sentry] This Bun build externalizes all dependencies (${ blanketExternal } ), so Sentry ` +
8690 'cannot instrument bundled libraries. Instrumentation will be missing for any of ' +
87- `these packages your app uses: ${ INSTRUMENTED_MODULE_NAMES . join ( ', ' ) } . To instrument them, ` +
91+ `these packages your app uses: ${ moduleNames . join ( ', ' ) } . To instrument them, ` +
8892 'externalize only the specific packages you need external instead of all of them.' ,
8993 ) ;
9094 }
0 commit comments