Skip to content

feat(node): Implement registerModuleWrapper as alternative IITM/RITM wrapping method#20188

Draft
mydea wants to merge 2 commits intodevelopfrom
fn/custom-iitm-wrapping
Draft

feat(node): Implement registerModuleWrapper as alternative IITM/RITM wrapping method#20188
mydea wants to merge 2 commits intodevelopfrom
fn/custom-iitm-wrapping

Conversation

@mydea
Copy link
Copy Markdown
Member

@mydea mydea commented Apr 10, 2026

Part of #20171

This PR implements a new method in node-core:

registerModuleWrapper<OptionsType>({
  moduleName: 'express',
  supportedVersions: ['>=4<6'],
  options,
  patch: (moduleExports, getOptions) => {
    wrapExpressModule(moduleExports, getOptions);
  }
});

This works similarly to otel wrapping, registering the patch with IITM and RITM using the same semantics, more or less. It is a bit simplified for our requirements but should generally behave the same.

registerModuleWrapper is designed to be idempotent and to be callable multiple times. It will only actually patch once, calling it subsequently will update the options though - any options required in the patch should be resolved at runtime (!) via the passed-in getOptions. (Why, you may ask yourself? Because we rely on this for preloading OTEL instrumentation, where we run the patch in --import preload.ts or similar but do not have the options yet, which are defined later in init(), but should update the instrumentation config accordingly).

I have tentatively implemented this for the existing express instrumentation. This is def. a breaking change so nothing we can ship now but it should show how this can/should eventually look.

Note that this should not be merged as it is a breaking change and only for showcase & discussion how this can/should work.

@mydea mydea self-assigned this Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Core

  • Add enableTruncation option to OpenAI integration by andreiborza in #20167
  • Export a reusable function to add tracing headers by JPeer264 in #20076

Other

  • (deps) Bump defu from 6.1.4 to 6.1.6 by dependabot in #20104
  • (node) Implement registerModuleWrapper as alternative IITM/RITM wrapping method by mydea in #20188

Internal Changes 🔧

  • (size-limit) Bump failing size limit scenario by Lms24 in #20186

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

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 26.3 kB - -
@sentry/browser - with treeshaking flags 24.78 kB - -
@sentry/browser (incl. Tracing) 44.17 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.39 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.14 kB - -
@sentry/browser (incl. Tracing, Replay) 83.55 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.01 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 88.23 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 100.84 kB - -
@sentry/browser (incl. Feedback) 43.44 kB - -
@sentry/browser (incl. sendFeedback) 31.11 kB - -
@sentry/browser (incl. FeedbackAsync) 36.19 kB - -
@sentry/browser (incl. Metrics) 27.6 kB - -
@sentry/browser (incl. Logs) 27.73 kB - -
@sentry/browser (incl. Metrics & Logs) 28.43 kB - -
@sentry/react 28.04 kB - -
@sentry/react (incl. Tracing) 46.4 kB - -
@sentry/vue 31.18 kB - -
@sentry/vue (incl. Tracing) 46.02 kB - -
@sentry/svelte 26.32 kB - -
CDN Bundle 28.91 kB - -
CDN Bundle (incl. Tracing) 46.94 kB - -
CDN Bundle (incl. Logs, Metrics) 30.33 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.04 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.4 kB - -
CDN Bundle (incl. Tracing, Replay) 84.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.15 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 89.89 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 90.99 kB - -
CDN Bundle - uncompressed 84.88 kB - -
CDN Bundle (incl. Tracing) - uncompressed 140.44 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 89.08 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 143.9 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 212.99 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 258.24 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 261.69 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 271.94 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 275.38 kB - -
@sentry/nextjs (client) 48.9 kB - -
@sentry/sveltekit (client) 44.64 kB - -
@sentry/node-core 59.13 kB +0.03% +12 B 🔺
⛔️ @sentry/node (max: 176 kB) 180.65 kB +5.89% +10.03 kB 🔺
@sentry/node - without tracing 97.16 kB +0.01% +6 B 🔺
@sentry/aws-serverless 113.98 kB +0.03% +30 B 🔺
@sentry/cloudflare (withSentry) - minified 166.9 kB - -
@sentry/cloudflare (withSentry) 421.79 kB - -

View base workflow run

@mydea mydea force-pushed the fn/custom-iitm-wrapping branch from 6c2f752 to 9192a07 Compare April 10, 2026 08:38
Comment thread packages/node-core/src/module-wrapper/singleton.ts Outdated
/* eslint-disable no-param-reassign */

import * as path from 'node:path';
import { Hook } from 'require-in-the-middle';
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.

Presumably we'll also need a version of this for iitm, and also need to pull the relevant guts out for use in Bun, right?

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.

Oh, wait, nevermind, this is node-core, not core, so no bun stuff. But we do need IITM.

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.

nothing needed for iitm I beleive, I think this takes care of this under the hood - at least, in otel, they only have this functionality for RITM 🤔

isaacs added a commit that referenced this pull request Apr 10, 2026
Update the Express integration to accept the module export and a configuration
function, rather than a configuration object. This is needed to support lazily
calling Sentry.init *after* the module has been instrumented, without re-wrapping
the methods to get the new config.

via: @mydea in #20188
isaacs added a commit that referenced this pull request Apr 13, 2026
Update the Express integration to accept the module export and a
configuration function, rather than a configuration object. This is
needed to support lazily calling Sentry.init *after* the module has been
instrumented, without re-wrapping the methods to get the new config.

via: @mydea in #20188
isaacs added a commit that referenced this pull request Apr 13, 2026
Update the Express integration to accept the module export and a
configuration function, rather than a configuration object. This is
needed to support lazily calling Sentry.init *after* the module has been
instrumented, without re-wrapping the methods to get the new config.

via: @mydea in #20188
@mydea mydea force-pushed the fn/custom-iitm-wrapping branch from 956e1d1 to 066e637 Compare May 5, 2026 13:46
@getsentry getsentry deleted a comment from github-actions Bot May 5, 2026
@getsentry getsentry deleted a comment from github-actions Bot May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants