@@ -3,6 +3,8 @@ import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
33import { Integration } from '@sentry/types' ;
44import { getGlobalObject } from '@sentry/utils' ;
55import * as domain from 'domain' ;
6+ import { cwd } from 'process' ;
7+ import * as readPkgUp from 'read-pkg-up' ;
68
79import { NodeOptions } from './backend' ;
810import { NodeClient } from './client' ;
@@ -88,6 +90,10 @@ export function init(options: NodeOptions = {}): void {
8890 : defaultIntegrations ;
8991 }
9092
93+ if ( options . discoverIntegrations !== false ) {
94+ options . _internal . discoveredIntegrations = discoverIntegrations ( ) ;
95+ }
96+
9197 if ( options . dsn === undefined && process . env . SENTRY_DSN ) {
9298 options . dsn = process . env . SENTRY_DSN ;
9399 }
@@ -118,6 +124,32 @@ export function init(options: NodeOptions = {}): void {
118124 initAndBind ( NodeClient , options ) ;
119125}
120126
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+
121153/**
122154 * This is the getter for lastEventId.
123155 *
0 commit comments