@@ -3,6 +3,8 @@ import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
3
3
import { Integration } from '@sentry/types' ;
4
4
import { getGlobalObject } from '@sentry/utils' ;
5
5
import * as domain from 'domain' ;
6
+ import { cwd } from 'process' ;
7
+ import * as readPkgUp from 'read-pkg-up' ;
6
8
7
9
import { NodeOptions } from './backend' ;
8
10
import { NodeClient } from './client' ;
@@ -88,6 +90,10 @@ export function init(options: NodeOptions = {}): void {
88
90
: defaultIntegrations ;
89
91
}
90
92
93
+ if ( options . discoverIntegrations !== false ) {
94
+ options . _internal . discoveredIntegrations = discoverIntegrations ( ) ;
95
+ }
96
+
91
97
if ( options . dsn === undefined && process . env . SENTRY_DSN ) {
92
98
options . dsn = process . env . SENTRY_DSN ;
93
99
}
@@ -118,6 +124,32 @@ export function init(options: NodeOptions = {}): void {
118
124
initAndBind ( NodeClient , options ) ;
119
125
}
120
126
127
+ /**
128
+ * Auto-discover integrations based on package.json entries
129
+ */
130
+ function discoverIntegrations ( ) : Integration [ ] {
131
+ const pkg = readPkgUp . sync ( ) ;
132
+
133
+ if ( ! pkg ) {
134
+ return [ ] ;
135
+ }
136
+
137
+ return Object . keys ( {
138
+ ...pkg . packageJson . dependencies ,
139
+ ...pkg . packageJson . devDependencies ,
140
+ } )
141
+ . filter ( name => {
142
+ return / ^ @ s e n t r y \/ i n t e g r a t i o n - ( c o m m o n | n o d e ) - [ a - z ] / . test ( name ) ;
143
+ } )
144
+ . map ( name => {
145
+ const mod = require ( require . resolve ( name , { paths : [ cwd ( ) ] } ) ) ;
146
+ return Object . values ( mod ) as { new ( ) : Integration } [ ] ;
147
+ } )
148
+ . reduce ( ( acc , integrations ) => {
149
+ return acc . concat ( integrations . map ( Integration => new Integration ( ) ) ) ;
150
+ } , [ ] as Integration [ ] ) ;
151
+ }
152
+
121
153
/**
122
154
* This is the getter for lastEventId.
123
155
*
0 commit comments