@@ -101,10 +101,12 @@ protected function configureAndRegisterClient(): void
101101 $ basePath = base_path ();
102102 $ userConfig = $ this ->getUserConfig ();
103103
104- // We do not want this setting to hit our main client because it's Laravel specific
105104 unset(
105+ // We do not want this setting to hit our main client because it's Laravel specific
106106 $ userConfig ['breadcrumbs ' ],
107- // this is kept for backwards compatibilty and can be dropped in a breaking release
107+ // We resolve the integrations through the container later, so we initially do not pass it to the SDK yet
108+ $ userConfig ['integrations ' ],
109+ // This is kept for backwards compatibilty and can be dropped in a future breaking release
108110 $ userConfig ['breadcrumbs.sql_bindings ' ]
109111 );
110112
@@ -114,10 +116,7 @@ protected function configureAndRegisterClient(): void
114116 'prefixes ' => [$ basePath ],
115117 'in_app_exclude ' => ["{$ basePath }/vendor " ],
116118 ],
117- $ userConfig ,
118- [
119- 'integrations ' => $ this ->getIntegrations (),
120- ]
119+ $ userConfig
121120 );
122121
123122 $ clientBuilder = ClientBuilder::create ($ options );
@@ -135,13 +134,19 @@ protected function configureAndRegisterClient(): void
135134
136135 $ options = $ clientBuilder ->getOptions ();
137136
138- if ($ options ->hasDefaultIntegrations ()) {
139- $ integrations = $ options ->getIntegrations ();
137+ $ userIntegrations = $ this ->resolveIntegrationsFromUserConfig ();
138+
139+ $ options ->setIntegrations (static function (array $ integrations ) use ($ options , $ userIntegrations ) {
140+ $ allIntegrations = array_merge ($ integrations , $ userIntegrations );
141+
142+ if (!$ options ->hasDefaultIntegrations ()) {
143+ return $ allIntegrations ;
144+ }
140145
141146 // Remove the default error and fatal exception listeners to let Laravel handle those
142147 // itself. These event are still bubbling up through the documented changes in the users
143148 // `ExceptionHandler` of their application or through the log channel integration to Sentry
144- $ options -> setIntegrations ( array_filter ($ integrations , static function (SdkIntegration \IntegrationInterface $ integration ): bool {
149+ return array_filter ($ allIntegrations , static function (SdkIntegration \IntegrationInterface $ integration ): bool {
145150 if ($ integration instanceof SdkIntegration \ErrorListenerIntegration) {
146151 return false ;
147152 }
@@ -155,8 +160,8 @@ protected function configureAndRegisterClient(): void
155160 }
156161
157162 return true ;
158- })) ;
159- }
163+ });
164+ });
160165
161166 $ hub = new Hub ($ clientBuilder ->getClient ());
162167
@@ -185,7 +190,7 @@ protected function hasDsnSet(): bool
185190 *
186191 * @return array
187192 */
188- private function getIntegrations (): array
193+ private function resolveIntegrationsFromUserConfig (): array
189194 {
190195 $ integrations = [new Integration ];
191196
@@ -195,7 +200,13 @@ private function getIntegrations(): array
195200 if ($ userIntegration instanceof SdkIntegration \IntegrationInterface) {
196201 $ integrations [] = $ userIntegration ;
197202 } elseif (\is_string ($ userIntegration )) {
198- $ integrations [] = $ this ->app ->make ($ userIntegration );
203+ $ resolvedIntegration = $ this ->app ->make ($ userIntegration );
204+
205+ if (!($ resolvedIntegration instanceof SdkIntegration \IntegrationInterface)) {
206+ throw new \RuntimeException ('Sentry integrations should a instance of `\Sentry\Integration\IntegrationInterface`. ' );
207+ }
208+
209+ $ integrations [] = $ resolvedIntegration ;
199210 } else {
200211 throw new \RuntimeException ('Sentry integrations should either be a container reference or a instance of `\Sentry\Integration\IntegrationInterface`. ' );
201212 }
0 commit comments