-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Option to only wrap instrumented modules (#13139)
Likely closes many issues but I don't want to auto-close anything specific here. We should probably confirm the issues are closed individually. `import-in-the-middle` by default wraps every ES module with a wrapping module that later allows it exports to be modified. This has issues though because the wrapping output of `import-in-the-middle` is not compatible with all modules. To help work around this I [added a feature](nodejs/import-in-the-middle#146) to `import-in-the-middle` that allows us to only wrap modules that we specifically need to instrument. ```ts import * as Sentry from '@sentry/node'; Sentry.init({ dsn: '__DSN__', registerEsmLoaderHooks: { onlyHookedModules: true }, }); ``` So far I've only changed the express integration test to use this new mode.
- Loading branch information
Showing
6 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
dev-packages/node-integration-tests/suites/esm/import-in-the-middle/app.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
import * as iitm from 'import-in-the-middle'; | ||
|
||
new iitm.Hook((_, name) => { | ||
if (name !== 'http') { | ||
throw new Error(`'http' should be the only hooked modules but we just hooked '${name}'`); | ||
} | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
autoSessionTracking: false, | ||
transport: loggingTransport, | ||
registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true }, | ||
}); | ||
|
||
await import('./sub-module.mjs'); | ||
await import('http'); | ||
await import('os'); |
2 changes: 2 additions & 0 deletions
2
dev-packages/node-integration-tests/suites/esm/import-in-the-middle/sub-module.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line no-console | ||
console.assert(true); |
12 changes: 12 additions & 0 deletions
12
dev-packages/node-integration-tests/suites/esm/import-in-the-middle/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
conditionalTest({ min: 18 })('import-in-the-middle', () => { | ||
test('onlyIncludeInstrumentedModules', done => { | ||
createRunner(__dirname, 'app.mjs').ensureNoErrorOutput().start(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters