Skip to content

feat(node): Experimentally add orchestrion support#20900

Merged
isaacs merged 3 commits into
developfrom
experiment/orchestrionjs-auto-instrumentation
Jun 18, 2026
Merged

feat(node): Experimentally add orchestrion support#20900
isaacs merged 3 commits into
developfrom
experiment/orchestrionjs-auto-instrumentation

Conversation

@mydea

@mydea mydea commented May 15, 2026

Copy link
Copy Markdown
Member

EDIT(@isaacs): updated description to reflect where this PR landed, for more straightforward review.

Use orchestrion for instrumentation, providing the shared implementation in packages/server-utils, and the Node integration. (Deno and Bun in subsequent PRs.)

This implementation avoids exposing the "orchestrion" terminology to any user-facing API surface. Instead, the Node SDK presents a minimal API surface, with an opt-in that triggers the orchestrion instrumentations to replace their OTel counterparts. (Currently, this is just Mysql, but more will be added in the future.)

A single opt-in method now does the entire Orchestrion setup.

Sentry.experimentalUsediagnosticsChannelInjection();
Sentry.init({
  dsn: '__DSN__',
  experimentalDiagnosticsChannelInjection: true,
})

Assuming that this is run in a user's local --import module (or, failing that, before the instrumented modules are loaded), then the appropriate hooks will be synchronously added, and Orchestrion diagnostics_channel-based integrations will be used instead of the legacy OTel integrations.

The channel-injection hooks are registered synchronously (mirroring esmLoader.ts: Module.register(...) + ModulePatch on Node <24.13, Module.registerHooks on newer / Deno 2.8+), so they are in place before the app's own imports resolve.

The @sentry/node/import loader hook script injects the channels unconditionally, as the presence of the channels is harmless when they are not being used. They are only subscribed to if the opt-in flag is set. (If tracing is disabled, then they're not enabled at all, since the integrations would not be in use. When and if we have an Orchestrion-based integration that is not spans-only, we can make this check more elaborate, but it seems like overkill for now.)

The version detection lives in a single source of truth in server-utils/orchestrion/runtime/register.ts, so that it can be initialized synchronously as part of Sentry.init(), or in the import-hook.mjs loader, and enables the appropriate module hooks for Deno 2.8.0+ and supported Node versions.

Comment thread yarn.lock Outdated
Comment thread yarn.lock Outdated
Comment thread packages/node/src/orchestrion/runtime/require-hook.cjs Outdated
@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.45 kB - -
@sentry/browser - with treeshaking flags 25.88 kB - -
@sentry/browser (incl. Tracing) 45.89 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.12 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.67 kB - -
@sentry/browser (incl. Tracing, Replay) 85.08 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.69 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.78 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.45 kB - -
@sentry/browser (incl. Feedback) 44.62 kB - -
@sentry/browser (incl. sendFeedback) 32.25 kB - -
@sentry/browser (incl. FeedbackAsync) 37.38 kB - -
@sentry/browser (incl. Metrics) 28.52 kB - -
@sentry/browser (incl. Logs) 28.76 kB - -
@sentry/browser (incl. Metrics & Logs) 29.45 kB - -
@sentry/react 29.25 kB - -
@sentry/react (incl. Tracing) 48.18 kB - -
@sentry/vue 32.56 kB - -
@sentry/vue (incl. Tracing) 47.76 kB - -
@sentry/svelte 27.48 kB - -
CDN Bundle 29.86 kB - -
CDN Bundle (incl. Tracing) 48.29 kB - -
CDN Bundle (incl. Logs, Metrics) 31.4 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.59 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.71 kB - -
CDN Bundle (incl. Tracing, Replay) 85.62 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.46 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.71 kB - -
CDN Bundle - uncompressed 88.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.08 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.5 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.06 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.33 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.95 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.91 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.65 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.6 kB - -
@sentry/nextjs (client) 50.58 kB - -
@sentry/sveltekit (client) 46.27 kB - -
@sentry/core/server 76.16 kB - -
@sentry/core/browser 63.31 kB - -
@sentry/node-core 61.87 kB -0.01% -1 B 🔽
@sentry/node 127.71 kB +0.02% +21 B 🔺
@sentry/node - without tracing 74.23 kB -0.05% -30 B 🔽
@sentry/aws-serverless 85.34 kB -0.01% -2 B 🔽
@sentry/cloudflare (withSentry) - minified 174.48 kB - -
@sentry/cloudflare (withSentry) 436.52 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.05 kB added added
@sentry/node/light 50.92 kB added added

View base workflow run

Comment thread packages/server-utils/src/integrations/tracing-channel/mysql.ts
Comment thread packages/server-utils/src/integrations/tracing-channel/mysql.ts
@mydea

mydea commented May 15, 2026

Copy link
Copy Markdown
Member Author

Note: dependency warning stuff should be addressed when this is merged/released: apm-js-collab/code-transformer-bundler-plugins#2

Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs Outdated
@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from b1b6ed6 to 9e8b070 Compare May 18, 2026 07:29
Comment thread packages/server-utils/src/integrations/tracing-channel/mysql.ts
Comment thread dev-packages/node-integration-tests/suites/tracing/mysql/scenario-orchestrion.mjs Outdated
@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 9e8b070 to 26ccdf4 Compare May 18, 2026 09:03
Comment thread packages/node/src/orchestrion/setup.ts Outdated
@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 26ccdf4 to c8be420 Compare May 18, 2026 13:34
Comment thread packages/node/src/orchestrion/setup.ts Outdated
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs Outdated
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs Outdated
@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from a38481b to c095626 Compare May 19, 2026 07:20
Comment thread packages/node/src/orchestrion/setup.ts Outdated
Comment thread packages/server-utils/src/integrations/tracing-channel/mysql.ts
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs Outdated
Comment thread packages/server-utils/src/orchestrion/detect.ts
Comment thread packages/node/src/orchestrion/bundler/vite.ts
Comment thread packages/node/src/orchestrion/runtime/require-hook.cjs Outdated
@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 5d957bf to 12ac21c Compare May 21, 2026 11:02
@mydea

mydea commented May 21, 2026

Copy link
Copy Markdown
Member Author

I also added an e2e test app using the vite plugin, however this is failing, will need to wait on v0.2.0 of the plugins as this updates to the latest version of the code transformer, which we need here.

Comment thread packages/server-utils/src/orchestrion/detect.ts
@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 7d6f1f7 to 3de78da Compare May 26, 2026 09:40
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs Outdated
Comment thread dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/src/app.js Dismissed
Comment thread dev-packages/e2e-tests/test-applications/node-express-orchestrion/src/app.mjs Dismissed
Comment thread packages/node/src/sdk/index.ts

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very good!

My only concern/suggestion is that it should really not be node-specific. Deno and Bun are both supported by orchestrion now, so it'd be good to move this logic into a shared location so they can all benefit from it as we add instrumentations.

I'm not sure if it's best to (a) land this first, and then refactor this and the other @sentry/core/server stuff into @sentry-internal/server-utils, or (b) if we should bite that bullet first and then move this implementation on top of it. If we go with (a), then the move would be to land this now, and do server-utils as a second step. If (b), then it'd be good to get that done, and port this on top of it.

Comment thread packages/server-utils/src/integrations/tracing-channel/mysql.ts
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs Outdated
@mydea

mydea commented May 27, 2026

Copy link
Copy Markdown
Member Author

This is looking very good!

My only concern/suggestion is that it should really not be node-specific. Deno and Bun are both supported by orchestrion now, so it'd be good to move this logic into a shared location so they can all benefit from it as we add instrumentations.

I'm not sure if it's best to (a) land this first, and then refactor this and the other @sentry/core/server stuff into @sentry-internal/server-utils, or (b) if we should bite that bullet first and then move this implementation on top of it. If we go with (a), then the move would be to land this now, and do server-utils as a second step. If (b), then it'd be good to get that done, and port this on top of it.

jup, eventually this should go into a new server-utils package or similar I guess - we can move this up any time!

isaacs added a commit that referenced this pull request Jun 18, 2026
Finish the the orchestrion.js-based auto-instrumentation so the Node SDK
presents a minimal API that does not expose the internal "orchestrion"
term.

A single opt-in method now does the entire Orchestrion setup.

```ts
Sentry.experimentalUseDiagnosticsChannelInjection();

// orchestrion integrations loaded and ready to go
Sentry.init({
  dsn: '__DSN__'
  tracesSampleRate: 1,
})
```

Assuming that this is run in a user's local `--import` module (or,
failing that, before init is called and instrumented modules are
loaded), then the appropriate hooks will be synchronously added, and
Orchestrion diagnostics_channel-based integrations will be used instead
of the legacy OTel integrations.

The previous three-step setup (`_experimentalUseOrchestrion` flag,
`--import @sentry/node/orchestrion`, plus a separate
`_experimentalSetupOrchestrion()` method call) is removed.

The channel-injection hooks are registered synchronously (mirroring
`esmLoader.ts`: `Module.register(...)` + `ModulePatch` on Node <24.13,
`Module.registerHooks` on newer / Deno 2.8+), so they are in place
before the app's own `import`s resolve. (A dynamic `import()` would have
raced module loading.)

The `@sentry/node/import` loader hook script injects the channels
**unconditionally**, as the presence of the channels is harmless when
they are not being used. They are only *subscribed* to if the opt-in
flag is set.

The version detection is moved to a single source of truth in
`server-utils/orchestrion/runtime/register.ts`, so that it can be
initialized synchronously as part of `Sentry.init()`, or in the
`import-hook.mjs` loader.

All references to `orchestrion` are removed from the public API surface.
The term remains in `server-utils`, of course, as this is an internal
package designed to house shared implementation details across
server-side JS platforms.

The `@sentry/node/orchestrion/vite` subpath export is removed, as that
really isn't used by anything, and was just a pass-through for
`@sentry/server-utils/orchestrion/vite` anyway. The Bun and Edge
computing SDKs will use this directly to instrument using Orchestrion.

Also, only install diagnostics channel injection when tracing enabled.
Every Orchestrion integration we're currently adding (ie, Mysql) or
likely to in the very near future, replaces an OTel integration that is
gated on span creation. So, there's no need to do this work if spans are
not enabled.

An e2e test is added to ensure that the orchestrion functionality is
*not* added in bundlers that do not explicitly opt into it.
@isaacs isaacs force-pushed the experiment/orchestrionjs-auto-instrumentation branch from fc56193 to 7d1f62e Compare June 18, 2026 04:40
isaacs added a commit that referenced this pull request Jun 18, 2026
Finish the the orchestrion.js-based auto-instrumentation so the Node SDK
presents a minimal API that does not expose the internal "orchestrion"
term.

A single opt-in method now does the entire Orchestrion setup.

```ts
Sentry.experimentalUseDiagnosticsChannelInjection();

// orchestrion integrations loaded and ready to go
Sentry.init({
  dsn: '__DSN__'
  tracesSampleRate: 1,
})
```

Assuming that this is run in a user's local `--import` module (or,
failing that, before init is called and instrumented modules are
loaded), then the appropriate hooks will be synchronously added, and
Orchestrion diagnostics_channel-based integrations will be used instead
of the legacy OTel integrations.

The previous three-step setup (`_experimentalUseOrchestrion` flag,
`--import @sentry/node/orchestrion`, plus a separate
`_experimentalSetupOrchestrion()` method call) is removed.

The channel-injection hooks are registered synchronously (mirroring
`esmLoader.ts`: `Module.register(...)` + `ModulePatch` on Node <24.13,
`Module.registerHooks` on newer / Deno 2.8+), so they are in place
before the app's own `import`s resolve. (A dynamic `import()` would have
raced module loading.)

The `@sentry/node/import` loader hook script injects the channels
**unconditionally**, as the presence of the channels is harmless when
they are not being used. They are only *subscribed* to if the opt-in
flag is set.

The version detection is moved to a single source of truth in
`server-utils/orchestrion/runtime/register.ts`, so that it can be
initialized synchronously as part of `Sentry.init()`, or in the
`import-hook.mjs` loader.

All references to `orchestrion` are removed from the public API surface.
The term remains in `server-utils`, of course, as this is an internal
package designed to house shared implementation details across
server-side JS platforms.

The `@sentry/node/orchestrion/vite` subpath export is removed, as that
really isn't used by anything, and was just a pass-through for
`@sentry/server-utils/orchestrion/vite` anyway. The Bun and Edge
computing SDKs will use this directly to instrument using Orchestrion.

Also, only install diagnostics channel injection when tracing enabled.
Every Orchestrion integration we're currently adding (ie, Mysql) or
likely to in the very near future, replaces an OTel integration that is
gated on span creation. So, there's no need to do this work if spans are
not enabled.

An e2e test is added to ensure that the orchestrion functionality is
*not* added in bundlers that do not explicitly opt into it.
@isaacs isaacs force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 7d1f62e to 7323f1a Compare June 18, 2026 04:50
@isaacs isaacs requested a review from timfish June 18, 2026 04:51
@isaacs

isaacs commented Jun 18, 2026

Copy link
Copy Markdown
Member

@timfish Updated this with the fixes that we discussed. PTAL when you get a chance! :)

Comment thread packages/server-utils/src/integrations/tracing-channel/mysql.ts
Comment thread packages/node/src/sdk/index.ts Outdated
Comment thread packages/server-utils/tsconfig.types.json Outdated
Comment thread yarn.lock Outdated
dependencies:
json-schema-to-ts "^3.1.1"

"@apm-js-collab/code-transformer-bundler-plugins@^0.3.0":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we bump to 0.4.0 right away, while we're at it?

Comment thread yarn.lock Outdated
Comment thread yarn.lock Outdated
@mydea mydea changed the title WIP: POC to use orchestrion-js for instrumentation feat(node): Experimentally add orchestrion support Jun 18, 2026
@mydea

mydea commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

Can't submit a review because it is my PR lol xD but this is good to go from my POV, left some small nits but nothing important, maybe the only thing would be to bump the orchestrion dependencies to latest while we're at it.

// esbuild and friends rewrite `import.meta.url` to `{}` for CJS output,
// which would make `createRequire(undefined)` throw.
// Only use `import.meta.url` in true ESM, where there's no `require`
const nodeRequire = typeof require === 'function' ? require : createRequire(import.meta.url);

@timfish timfish Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated specifically to this PR but I think we should move towards a bundler plugin with magic comments like we have here for dev/prod. This way we can write "pure" ESM/CJS and have the bundler keep the correct one.

Something like:

  /*! rollup-include-cjs-only */
  const nodeRequire = require;
  /*! rollup-include-csj-only-end */
  /*! rollup-include-esm-only */
  const nodeRequire = createRequire(import.meta.url);
  /*! rollup-include-esm-only-end */

@timfish timfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for this to be merged but I don't think we should be using orchestrion in the named exports. Something less... internal detail not relevent to customers?

mydea and others added 2 commits June 18, 2026 07:17
This is a WIP POC trying out usage of orchestrion-js for node SDK
instrumentation.

1. Built a general plan document outlining how this can/should work
2. Implemented the generic utilities and building blocks needed
3. Implemented a example integration for mysql package using the new
   pieces

Honestly it seems pretty straightforward... Usage for this POC is:

```bash
node --import @sentry/node/orchestrion app.mjs
```

And then

```js
// app.mjs
import * as Sentry from '@sentry/node';

const client = Sentry.init({
 // regular setup...
  _experimentalUseOrchestrion: true,
});

// Split this way for better tree shaking
Sentry._experimentalSetupOrchestrion(client);
```

This will disable the otel instrumentation that is already converted to
orchestrion (in this PR, only Mysql) and add the respective
orchestrion-based integrations instead. The exact API here is WIP and
really just geared towards experimentation, so could change, and it's
easy to see how this would be easier in v11 with this being the default.

Some general benefits of this approach:

1. preload becomes unnecessary as this approach generally behaves like
   preload - the `--import` script only registers the mappings for
   orchestrion, all actual code registering stuff etc. happens in
   `Sentry.init()`. This makes a bunch of things easier...
2. Not tested here, but this should generally work exactly the same if
   you add the respective vite (and others in the future) plugin,
   allowing you to skip the `--import`. This also works when deploying
   to e.g. cloudflare etc. as long as one of the bundler plugins is
   used.
3. The whole approach is much easier to reconcile with dual-system
   approaches where newer versions have native DC/TC support - just need
   to register different channel names mostly to get stuff working.
Also, fix the `import ... from 'node:module'` in the import-hook.mjs,
which was broken.
isaacs added a commit that referenced this pull request Jun 18, 2026
Finish the the orchestrion.js-based auto-instrumentation so the Node SDK
presents a minimal API that does not expose the internal "orchestrion"
term.

A single opt-in method now does the entire Orchestrion setup.

```ts
Sentry.experimentalUseDiagnosticsChannelInjection();

// orchestrion integrations loaded and ready to go
Sentry.init({
  dsn: '__DSN__'
  tracesSampleRate: 1,
})
```

Assuming that this is run in a user's local `--import` module (or,
failing that, before init is called and instrumented modules are
loaded), then the appropriate hooks will be synchronously added, and
Orchestrion diagnostics_channel-based integrations will be used instead
of the legacy OTel integrations.

The previous three-step setup (`_experimentalUseOrchestrion` flag,
`--import @sentry/node/orchestrion`, plus a separate
`_experimentalSetupOrchestrion()` method call) is removed.

The channel-injection hooks are registered synchronously (mirroring
`esmLoader.ts`: `Module.register(...)` + `ModulePatch` on Node <24.13,
`Module.registerHooks` on newer / Deno 2.8+), so they are in place
before the app's own `import`s resolve. (A dynamic `import()` would have
raced module loading.)

The `@sentry/node/import` loader hook script injects the channels
**unconditionally**, as the presence of the channels is harmless when
they are not being used. They are only *subscribed* to if the opt-in
flag is set.

The version detection is moved to a single source of truth in
`server-utils/orchestrion/runtime/register.ts`, so that it can be
initialized synchronously as part of `Sentry.init()`, or in the
`import-hook.mjs` loader.

All references to `orchestrion` are removed from the public API surface.
The term remains in `server-utils`, of course, as this is an internal
package designed to house shared implementation details across
server-side JS platforms.

The `@sentry/node/orchestrion/vite` subpath export is removed, as that
really isn't used by anything, and was just a pass-through for
`@sentry/server-utils/orchestrion/vite` anyway. The Bun and Edge
computing SDKs will use this directly to instrument using Orchestrion.

Also, only install diagnostics channel injection when tracing enabled.
Every Orchestrion integration we're currently adding (ie, Mysql) or
likely to in the very near future, replaces an OTel integration that is
gated on span creation. So, there's no need to do this work if spans are
not enabled.

An e2e test is added to ensure that the orchestrion functionality is
*not* added in bundlers that do not explicitly opt into it.
@isaacs isaacs force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 7323f1a to 92b508d Compare June 18, 2026 14:20
@isaacs

isaacs commented Jun 18, 2026

Copy link
Copy Markdown
Member

Happy for this to be merged but I don't think we should be using orchestrion in the named exports. Something less... internal detail not relevent to customers?

I think we only do that for server-utils and other "implementation detail" type things. Is there a piece that I missed? I assume that most users will just use the Node/Bun/Deno SDK surfaces, which only refer to this as diagnostics channel injection and such.

isaacs added a commit that referenced this pull request Jun 18, 2026
Finish the the orchestrion.js-based auto-instrumentation so the Node SDK
presents a minimal API that does not expose the internal "orchestrion"
term.

A single opt-in method now does the entire Orchestrion setup.

```ts
Sentry.experimentalUseDiagnosticsChannelInjection();

// orchestrion integrations loaded and ready to go
Sentry.init({
  dsn: '__DSN__'
  tracesSampleRate: 1,
})
```

Assuming that this is run in a user's local `--import` module (or,
failing that, before init is called and instrumented modules are
loaded), then the appropriate hooks will be synchronously added, and
Orchestrion diagnostics_channel-based integrations will be used instead
of the legacy OTel integrations.

The previous three-step setup (`_experimentalUseOrchestrion` flag,
`--import @sentry/node/orchestrion`, plus a separate
`_experimentalSetupOrchestrion()` method call) is removed.

The channel-injection hooks are registered synchronously (mirroring
`esmLoader.ts`: `Module.register(...)` + `ModulePatch` on Node <24.13,
`Module.registerHooks` on newer / Deno 2.8+), so they are in place
before the app's own `import`s resolve. (A dynamic `import()` would have
raced module loading.)

The `@sentry/node/import` loader hook script injects the channels
**unconditionally**, as the presence of the channels is harmless when
they are not being used. They are only *subscribed* to if the opt-in
flag is set.

The version detection is moved to a single source of truth in
`server-utils/orchestrion/runtime/register.ts`, so that it can be
initialized synchronously as part of `Sentry.init()`, or in the
`import-hook.mjs` loader.

All references to `orchestrion` are removed from the public API surface.
The term remains in `server-utils`, of course, as this is an internal
package designed to house shared implementation details across
server-side JS platforms.

The `@sentry/node/orchestrion/vite` subpath export is removed, as that
really isn't used by anything, and was just a pass-through for
`@sentry/server-utils/orchestrion/vite` anyway. The Bun and Edge
computing SDKs will use this directly to instrument using Orchestrion.

Also, only install diagnostics channel injection when tracing enabled.
Every Orchestrion integration we're currently adding (ie, Mysql) or
likely to in the very near future, replaces an OTel integration that is
gated on span creation. So, there's no need to do this work if spans are
not enabled.

An e2e test is added to ensure that the orchestrion functionality is
*not* added in bundlers that do not explicitly opt into it.
@isaacs isaacs force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 92b508d to a1fba56 Compare June 18, 2026 15:56
Finish the the orchestrion.js-based auto-instrumentation so the Node SDK
presents a minimal API that does not expose the internal "orchestrion"
term.

A single opt-in method now does the entire Orchestrion setup.

```ts
Sentry.experimentalUseDiagnosticsChannelInjection();

// orchestrion integrations loaded and ready to go
Sentry.init({
  dsn: '__DSN__'
  tracesSampleRate: 1,
})
```

Assuming that this is run in a user's local `--import` module (or,
failing that, before init is called and instrumented modules are
loaded), then the appropriate hooks will be synchronously added, and
Orchestrion diagnostics_channel-based integrations will be used instead
of the legacy OTel integrations.

The previous three-step setup (`_experimentalUseOrchestrion` flag,
`--import @sentry/node/orchestrion`, plus a separate
`_experimentalSetupOrchestrion()` method call) is removed.

The channel-injection hooks are registered synchronously (mirroring
`esmLoader.ts`: `Module.register(...)` + `ModulePatch` on Node <24.13,
`Module.registerHooks` on newer / Deno 2.8+), so they are in place
before the app's own `import`s resolve. (A dynamic `import()` would have
raced module loading.)

The `@sentry/node/import` loader hook script injects the channels
**unconditionally**, as the presence of the channels is harmless when
they are not being used. They are only *subscribed* to if the opt-in
flag is set.

The version detection is moved to a single source of truth in
`server-utils/orchestrion/runtime/register.ts`, so that it can be
initialized synchronously as part of `Sentry.init()`, or in the
`import-hook.mjs` loader.

All references to `orchestrion` are removed from the public API surface.
The term remains in `server-utils`, of course, as this is an internal
package designed to house shared implementation details across
server-side JS platforms.

The `@sentry/node/orchestrion/vite` subpath export is removed, as that
really isn't used by anything, and was just a pass-through for
`@sentry/server-utils/orchestrion/vite` anyway. The Bun and Edge
computing SDKs will use this directly to instrument using Orchestrion.

Also, only install diagnostics channel injection when tracing enabled.
Every Orchestrion integration we're currently adding (ie, Mysql) or
likely to in the very near future, replaces an OTel integration that is
gated on span creation. So, there's no need to do this work if spans are
not enabled.

An e2e test is added to ensure that the orchestrion functionality is
*not* added in bundlers that do not explicitly opt into it.
@isaacs isaacs force-pushed the experiment/orchestrionjs-auto-instrumentation branch from a1fba56 to ce95b7a Compare June 18, 2026 16:25
@isaacs isaacs merged commit 9518574 into develop Jun 18, 2026
527 of 540 checks passed
@isaacs isaacs deleted the experiment/orchestrionjs-auto-instrumentation branch June 18, 2026 17:38
isaacs pushed a commit that referenced this pull request Jun 18, 2026
This is a WIP POC trying out usage of orchestrion-js for node SDK
instrumentation.

1. Built a general plan document outlining how this can/should work
2. Implemented the generic utilities and building blocks needed
3. Implemented a example integration for mysql package using the new
   pieces

Honestly it seems pretty straightforward... Usage for this POC is:

```bash
node --import @sentry/node/orchestrion app.mjs
```

And then

```js
// app.mjs
import * as Sentry from '@sentry/node';

const client = Sentry.init({
 // regular setup...
  _experimentalUseOrchestrion: true,
});

// Split this way for better tree shaking
Sentry._experimentalSetupOrchestrion(client);
```

This will disable the otel instrumentation that is already converted to
orchestrion (in this PR, only Mysql) and add the respective
orchestrion-based integrations instead. The exact API here is WIP and
really just geared towards experimentation, so could change, and it's
easy to see how this would be easier in v11 with this being the default.

Some general benefits of this approach:

1. preload becomes unnecessary as this approach generally behaves like
   preload - the `--import` script only registers the mappings for
   orchestrion, all actual code registering stuff etc. happens in
   `Sentry.init()`. This makes a bunch of things easier...
2. Not tested here, but this should generally work exactly the same if
   you add the respective vite (and others in the future) plugin,
   allowing you to skip the `--import`. This also works when deploying
   to e.g. cloudflare etc. as long as one of the bundler plugins is
   used.
3. The whole approach is much easier to reconcile with dual-system
   approaches where newer versions have native DC/TC support - just need
   to register different channel names mostly to get stuff working.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants