99use Sentry \Client ;
1010use Sentry \ClientBuilder ;
1111use Sentry \Integration \IgnoreErrorsIntegration ;
12+ use Sentry \Integration \IntegrationInterface ;
13+ use Sentry \Integration \RequestFetcherInterface ;
14+ use Sentry \Integration \RequestIntegration ;
1215use Sentry \Monolog \Handler ;
1316use Sentry \Options ;
1417use Sentry \SentryBundle \EventListener \ErrorListener ;
@@ -98,7 +101,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
98101 }
99102
100103 if (isset ($ options ['integrations ' ])) {
101- $ options ['integrations ' ] = $ this ->configureIntegrationsOption ($ options ['integrations ' ], $ config[ ' register_error_listener ' ] );
104+ $ options ['integrations ' ] = $ this ->configureIntegrationsOption ($ options ['integrations ' ], $ config );
102105 }
103106
104107 $ container
@@ -176,17 +179,30 @@ private function registerMonologHandlerConfiguration(ContainerBuilder $container
176179
177180 /**
178181 * @param string[] $integrations
182+ * @param array<string, mixed> $config
179183 *
180184 * @return array<Reference|Definition>
181185 */
182- private function configureIntegrationsOption (array $ integrations , bool $ registerErrorListener ): array
186+ private function configureIntegrationsOption (array $ integrations , array $ config ): array
183187 {
184- $ existsIgnoreErrorsIntegration = in_array (IgnoreErrorsIntegration::class, $ integrations , true );
185188 $ integrations = array_map (static function (string $ value ): Reference {
186189 return new Reference ($ value );
187190 }, $ integrations );
188191
189- if ($ registerErrorListener && false === $ existsIgnoreErrorsIntegration ) {
192+ $ integrations = $ this ->configureErrorListenerIntegration ($ integrations , $ config ['register_error_listener ' ]);
193+ $ integrations = $ this ->configureRequestIntegration ($ integrations , $ config ['options ' ]['default_integrations ' ] ?? true );
194+
195+ return $ integrations ;
196+ }
197+
198+ /**
199+ * @param array<Reference|Definition> $integrations
200+ *
201+ * @return array<Reference|Definition>
202+ */
203+ private function configureErrorListenerIntegration (array $ integrations , bool $ registerErrorListener ): array
204+ {
205+ if ($ registerErrorListener && ! $ this ->isIntegrationEnabled (IgnoreErrorsIntegration::class, $ integrations )) {
190206 // Prepend this integration to the beginning of the array so that
191207 // we can save some performance by skipping the rest of the integrations
192208 // if the error must be ignored
@@ -195,4 +211,37 @@ private function configureIntegrationsOption(array $integrations, bool $register
195211
196212 return $ integrations ;
197213 }
214+
215+ /**
216+ * @param array<Reference|Definition> $integrations
217+ *
218+ * @return array<Reference|Definition>
219+ */
220+ private function configureRequestIntegration (array $ integrations , bool $ useDefaultIntegrations ): array
221+ {
222+ if ($ useDefaultIntegrations && ! $ this ->isIntegrationEnabled (RequestIntegration::class, $ integrations )) {
223+ $ integrations [] = new Definition (RequestIntegration::class, [new Reference (RequestFetcherInterface::class)]);
224+ }
225+
226+ return $ integrations ;
227+ }
228+
229+ /**
230+ * @param class-string<IntegrationInterface> $integrationClass
231+ * @param array<Reference|Definition> $integrations
232+ */
233+ private function isIntegrationEnabled (string $ integrationClass , array $ integrations ): bool
234+ {
235+ foreach ($ integrations as $ integration ) {
236+ if ($ integration instanceof Reference && $ integrationClass === (string ) $ integration ) {
237+ return true ;
238+ }
239+
240+ if ($ integration instanceof Definition && $ integrationClass === $ integration ->getClass ()) {
241+ return true ;
242+ }
243+ }
244+
245+ return false ;
246+ }
198247}
0 commit comments