File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
dev-packages/node-integration-tests/suites/esm/modules-integration
packages/node/src/integrations Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { loggingTransport } from '@sentry-internal/node-integration-tests' ;
2
+ import * as Sentry from '@sentry/node' ;
3
+
4
+ Sentry . init ( {
5
+ dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
6
+ release : '1.0' ,
7
+ autoSessionTracking : false ,
8
+ integrations : [ Sentry . modulesIntegration ( ) ] ,
9
+ transport : loggingTransport ,
10
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { conditionalTest } from '../../../utils' ;
2
+ import { cleanupChildProcesses , createRunner } from '../../../utils/runner' ;
3
+
4
+ afterAll ( ( ) => {
5
+ cleanupChildProcesses ( ) ;
6
+ } ) ;
7
+
8
+ conditionalTest ( { min : 18 } ) ( 'modulesIntegration' , ( ) => {
9
+ test ( 'does not crash ESM setups' , done => {
10
+ createRunner ( __dirname , 'app.mjs' ) . ensureNoErrorOutput ( ) . start ( done ) ;
11
+ } ) ;
12
+ } ) ;
Original file line number Diff line number Diff line change @@ -2,12 +2,26 @@ import { existsSync, readFileSync } from 'node:fs';
2
2
import { dirname , join } from 'node:path' ;
3
3
import { defineIntegration } from '@sentry/core' ;
4
4
import type { IntegrationFn } from '@sentry/types' ;
5
+ import { logger } from '@sentry/utils' ;
6
+ import { DEBUG_BUILD } from '../debug-build' ;
7
+ import { isCjs } from '../utils/commonjs' ;
5
8
6
9
let moduleCache : { [ key : string ] : string } ;
7
10
8
11
const INTEGRATION_NAME = 'Modules' ;
9
12
10
13
const _modulesIntegration = ( ( ) => {
14
+ // This integration only works in CJS contexts
15
+ if ( ! isCjs ( ) ) {
16
+ DEBUG_BUILD &&
17
+ logger . warn (
18
+ 'modulesIntegration only works in CommonJS (CJS) environments. Remove this integration if you are using ESM.' ,
19
+ ) ;
20
+ return {
21
+ name : INTEGRATION_NAME ,
22
+ } ;
23
+ }
24
+
11
25
return {
12
26
name : INTEGRATION_NAME ,
13
27
processEvent ( event ) {
@@ -23,6 +37,8 @@ const _modulesIntegration = (() => {
23
37
24
38
/**
25
39
* Add node modules / packages to the event.
40
+ *
41
+ * Only works in CommonJS (CJS) environments.
26
42
*/
27
43
export const modulesIntegration = defineIntegration ( _modulesIntegration ) ;
28
44
You can’t perform that action at this time.
0 commit comments