Skip to content

WIP: POC to use orchestrion-js for instrumentation#20900

Draft
mydea wants to merge 26 commits into
developfrom
experiment/orchestrionjs-auto-instrumentation
Draft

WIP: POC to use orchestrion-js for instrumentation#20900
mydea wants to merge 26 commits into
developfrom
experiment/orchestrionjs-auto-instrumentation

Conversation

@mydea
Copy link
Copy Markdown
Member

@mydea mydea commented May 15, 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:

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

And then

// 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.

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

github-actions Bot commented May 15, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.32 kB - -
@sentry/browser - with treeshaking flags 25.74 kB - -
@sentry/browser (incl. Tracing) 45.31 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.55 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.3 kB - -
@sentry/browser (incl. Tracing, Replay) 84.92 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.43 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.64 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.24 kB - -
@sentry/browser (incl. Feedback) 44.51 kB - -
@sentry/browser (incl. sendFeedback) 32.13 kB - -
@sentry/browser (incl. FeedbackAsync) 37.25 kB - -
@sentry/browser (incl. Metrics) 28.41 kB - -
@sentry/browser (incl. Logs) 28.64 kB - -
@sentry/browser (incl. Metrics & Logs) 29.33 kB - -
@sentry/react 29.05 kB - -
@sentry/react (incl. Tracing) 47.55 kB - -
@sentry/vue 32.24 kB - -
@sentry/vue (incl. Tracing) 47.17 kB - -
@sentry/svelte 27.35 kB - -
CDN Bundle 29.73 kB - -
CDN Bundle (incl. Tracing) 47.84 kB - -
CDN Bundle (incl. Logs, Metrics) 31.21 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.53 kB - -
CDN Bundle (incl. Tracing, Replay) 85.34 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.37 kB - -
CDN Bundle - uncompressed 87.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.29 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 92.29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.05 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 217.02 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 263.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.5 kB - -
@sentry/nextjs (client) 50.03 kB - -
@sentry/sveltekit (client) 45.8 kB - -
@sentry/core/server 76.41 kB - -
@sentry/core/browser 63.16 kB - -
@sentry/node-core 62.59 kB +0.01% +2 B 🔺
@sentry/node 164.39 kB +0.03% +42 B 🔺
@sentry/node - without tracing 75.02 kB -0.01% -1 B 🔽
@sentry/aws-serverless 87.24 kB - -
@sentry/cloudflare (withSentry) - minified 173 kB - -
@sentry/cloudflare (withSentry) 432.17 kB - -
@sentry/node (with Orchestrion) 165.62 kB added added
@sentry/node/orchestrion (ESM hook) 70.36 kB added added
@sentry/node/light 51.43 kB added added

View base workflow run

Comment thread packages/node/src/integrations/tracing-channel/mysql.ts
Comment thread packages/node/src/integrations/tracing-channel/mysql.ts
@mydea
Copy link
Copy Markdown
Member Author

mydea commented May 15, 2026

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/node/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
@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
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/node/src/integrations/tracing-channel/mysql.ts
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs
Comment thread packages/node/src/orchestrion/detect.ts
return [bundlerMarkerPlugin(), ...codeTransformerArray];
}

function bundlerMarkerPlugin(): UnknownPlugin {
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.

None of this is required!

@@ -0,0 +1,33 @@
// EXPERIMENTAL — entry point for `node --require @sentry/node/orchestrion app.js`.
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.

We probably don't need to care about supplying a hook that works with --require

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.

ah, you mean it is good enough if everybody uses --import, even if their app is cjs?

Copy link
Copy Markdown
Collaborator

@timfish timfish May 21, 2026

Choose a reason for hiding this comment

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

Yeah, @isaacs did some testing came up with this ESM code that can register all the hooks:
https://github.com/apm-js-collab/tracing-hooks/#usage

--import and --require just tell Node which kind of file you are passing after the flag and we can hook everything from ESM.

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.

changed it to import only!

@mydea mydea force-pushed the experiment/orchestrionjs-auto-instrumentation branch from 5d957bf to 12ac21c Compare May 21, 2026 11:02
@mydea
Copy link
Copy Markdown
Member Author

mydea commented May 21, 2026

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/node/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
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-vite/src/app.ts Dismissed
Comment thread dev-packages/e2e-tests/test-applications/node-express-orchestrion/src/app.mjs Dismissed
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b089fd9. Configure here.

Comment thread packages/node/src/sdk/index.ts
Copy link
Copy Markdown
Member

@isaacs isaacs left a comment

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/node/src/integrations/tracing-channel/mysql.ts
Comment thread packages/node/src/orchestrion/runtime/import-hook.mjs
@mydea
Copy link
Copy Markdown
Member Author

mydea commented May 27, 2026

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!

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