Skip to content

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

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

WIP: POC to use orchestrion-js for instrumentation#20900
mydea wants to merge 20 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
form-data "^4.0.5"
proxy-from-env "^2.1.0"

axios@^0.26.1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium severity vulnerability introduced by a package you're using:
Line 11806 lists a dependency (axios) with a known Medium severity vulnerability. Fixing requires upgrading or replacing the dependency.

ℹ️ Why this matters

Affected versions of axios are vulnerable to Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Request/Response Splitting') / Inconsistent Interpretation of HTTP Requests ('HTTP Request/Response Smuggling') / Server-Side Request Forgery (SSRF). Axios can be used as a gadget for header injection: if another dependency enables prototype pollution, polluted properties can be merged into Axios request headers and written without CRLF sanitization, allowing request smuggling/SSRF that can reach internal services such as AWS IMDSv2 and potentially lead to credential theft or broader compromise.

References: GHSA, CVE

To resolve this comment:
Upgrade this dependency to at least version 0.31.0 at yarn.lock.

💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

Comment thread yarn.lock
form-data "^4.0.5"
proxy-from-env "^2.1.0"

axios@^0.26.1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium severity vulnerability may affect your project—review required:
Line 11806 lists a dependency (axios) with a known Medium severity vulnerability.

ℹ️ Why this matters

Affected versions of axios are vulnerable to Server-Side Request Forgery (SSRF) / Unintended Proxy or Intermediary ('Confused Deputy'). Axios does not normalize hostnames before applying NO_PROXY, so requests to loopback or internal hosts such as localhost. or [::1] can be sent through a configured proxy instead of bypassing it. If an attacker can influence request URLs, they may force local/internal Axios traffic through an attacker-controlled proxy, undermining SSRF protections and exposing sensitive responses.

References: GHSA, CVE

To resolve this comment:
Check if you have NO_PROXY configured in your environment.

  • If you're affected, upgrade this dependency to at least version 0.31.0 at yarn.lock.
  • If you're not affected, comment /fp we don't use this [condition]
💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

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 26.92 kB - -
@sentry/browser - with treeshaking flags 25.35 kB - -
@sentry/browser (incl. Tracing) 44.91 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.16 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.91 kB - -
@sentry/browser (incl. Tracing, Replay) 84.52 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.02 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.23 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 101.84 kB - -
@sentry/browser (incl. Feedback) 44.1 kB - -
@sentry/browser (incl. sendFeedback) 31.73 kB - -
@sentry/browser (incl. FeedbackAsync) 36.84 kB - -
@sentry/browser (incl. Metrics) 28.01 kB - -
@sentry/browser (incl. Logs) 28.15 kB - -
@sentry/browser (incl. Metrics & Logs) 28.84 kB - -
@sentry/react 28.66 kB - -
@sentry/react (incl. Tracing) 47.16 kB - -
@sentry/vue 31.85 kB - -
@sentry/vue (incl. Tracing) 46.78 kB - -
@sentry/svelte 26.94 kB - -
CDN Bundle 29.34 kB - -
CDN Bundle (incl. Tracing) 47.47 kB - -
CDN Bundle (incl. Logs, Metrics) 30.71 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.59 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70 kB - -
CDN Bundle (incl. Tracing, Replay) 84.91 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.97 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 90.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.85 kB - -
CDN Bundle - uncompressed 86.46 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.93 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.66 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.4 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.31 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.63 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.08 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 278.77 kB - -
@sentry/nextjs (client) 49.66 kB - -
@sentry/sveltekit (client) 45.4 kB - -
@sentry/core/server 75.77 kB - -
@sentry/core/browser 62.54 kB - -
@sentry/node-core 62.2 kB -0.01% -1 B 🔽
@sentry/node 167.24 kB +0.03% +37 B 🔺
@sentry/node - without tracing 74.64 kB - -
@sentry/aws-serverless 109.62 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 171.49 kB - -
@sentry/cloudflare (withSentry) 429.51 kB - -

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

});
debug('module.register() called for @apm-js-collab/tracing-hooks/hook.mjs');

// ALSO patch `Module.prototype._compile` for the CJS side: when an ESM file
Copy link
Copy Markdown
Member

@isaacs isaacs May 16, 2026

Choose a reason for hiding this comment

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

This is not the case when using synchronous module.registerHooks. In that case, the same hooks cover all CJS and ESM, even internal to CJS packages.

Once apm-js-collab/tracing-hooks#27 lands, we can feature detect like:

import { initialize, resolve, load } from '@apm-js-collab/tracing-hooks/hook-sync.mjs';
import Module from 'node:module';

if (runtime) {
  // ...
} else {
  // detection to decide module loader hooks to use
  // registerHooks was present but not stable until 24.13 and 25.1
  const version = (process.versions.node ?? '0.0.0')
    .split('.')
    .map(n => parseInt(n, 10));
  const stableSyncHooks = version[0] > 25 ||
    version[0] === 25 && version[1] >= 1 ||
    version[0] === 24 && version[1] >= 13;
  
  if (typeof Module.registerHooks === 'function' && stableSyncHooks) {
    initialize({ instrumentations });
    Module.registerHooks({ resolve, load });
  } else if (typeof Module.register === 'function') {

    // what you have here already, Module.register() and the cjs patch

  } else {
    throw new Error('No available API to apply module load hooks');
  }
}

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.

updated and applied this change, seems to work well! 🎉

@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
@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
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 2 potential issues.

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 5d957bf. Configure here.

code: SPAN_STATUS_ERROR,
message: ctx.error instanceof Error ? ctx.error.message : 'unknown_error',
});
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing captureException call in error handling paths

Low Severity

The startInactiveSpan call's error paths (both the channel error handler and the streamable Query's 'error' event listener) set span status to SPAN_STATUS_ERROR but never call captureException. Per the review rules, when using any startSpan API (including startInactiveSpan), error cases need to be checked and it may make sense to call captureException. This may be intentional for DB query errors (to avoid noise), but worth flagging per the rules.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 5d957bf. Configure here.

// resolves it via Node's module resolution against the installed package.

import { createRequire } from 'node:module';
import { initialize, resolve, load } from '@apm-js-collab/tracing-hooks/hook-sync.mjs';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Static import of sync hooks prevents fallback path

Medium Severity

The top-level static import of @apm-js-collab/tracing-hooks/hook-sync.mjs executes unconditionally on every Node version, but initialize, resolve, and load are only used inside the Module.registerHooks branch (Node ≥24.13/25.1). If hook-sync.mjs internally depends on APIs absent on older Node versions, the import throws before the runtime fallback to Module.register is ever reached. A dynamic import() inside the branch would make the fallback path reliable.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5d957bf. Configure here.

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.

2 participants