Skip to content

Commit a4f05f1

Browse files
Ensure user integrations are always executed after SDK integrations (#474)
Co-authored-by: Alex Bouma <me@alexbouma.me>
1 parent c2494c1 commit a4f05f1

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Ensure user integrations are always executed after SDK integrations (#474)
6+
57
## 2.4.2
68

79
- Avoid collision if another package has bound `sentry` in the Laravel container (#467)

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -166,43 +166,39 @@ protected function configureAndRegisterClient(): void
166166
$userIntegrations = $this->resolveIntegrationsFromUserConfig();
167167

168168
$options->setIntegrations(function (array $integrations) use ($options, $userIntegrations) {
169-
$allIntegrations = array_merge($integrations, $userIntegrations);
170-
171-
if (!$options->hasDefaultIntegrations()) {
172-
return $allIntegrations;
169+
if ($options->hasDefaultIntegrations()) {
170+
// Remove the default error and fatal exception listeners to let Laravel handle those
171+
// itself. These event are still bubbling up through the documented changes in the users
172+
// `ExceptionHandler` of their application or through the log channel integration to Sentry
173+
$integrations = array_filter($integrations, static function (SdkIntegration\IntegrationInterface $integration): bool {
174+
if ($integration instanceof SdkIntegration\ErrorListenerIntegration) {
175+
return false;
176+
}
177+
178+
if ($integration instanceof SdkIntegration\ExceptionListenerIntegration) {
179+
return false;
180+
}
181+
182+
if ($integration instanceof SdkIntegration\FatalErrorListenerIntegration) {
183+
return false;
184+
}
185+
186+
// We also remove the default request integration so it can be readded
187+
// after with a Laravel specific request fetcher. This way we can resolve
188+
// the request from Laravel instead of constructing it from the global state
189+
if ($integration instanceof SdkIntegration\RequestIntegration) {
190+
return false;
191+
}
192+
193+
return true;
194+
});
195+
196+
$integrations[] = new SdkIntegration\RequestIntegration(
197+
new LaravelRequestFetcher($this->app)
198+
);
173199
}
174200

175-
// Remove the default error and fatal exception listeners to let Laravel handle those
176-
// itself. These event are still bubbling up through the documented changes in the users
177-
// `ExceptionHandler` of their application or through the log channel integration to Sentry
178-
$allIntegrations = array_filter($allIntegrations, static function (SdkIntegration\IntegrationInterface $integration): bool {
179-
if ($integration instanceof SdkIntegration\ErrorListenerIntegration) {
180-
return false;
181-
}
182-
183-
if ($integration instanceof SdkIntegration\ExceptionListenerIntegration) {
184-
return false;
185-
}
186-
187-
if ($integration instanceof SdkIntegration\FatalErrorListenerIntegration) {
188-
return false;
189-
}
190-
191-
// We also remove the default request integration so it can be readded
192-
// after with a Laravel specific request fetcher. This way we can resolve
193-
// the request from Laravel instead of constructing it from the global state
194-
if ($integration instanceof SdkIntegration\RequestIntegration) {
195-
return false;
196-
}
197-
198-
return true;
199-
});
200-
201-
$allIntegrations[] = new SdkIntegration\RequestIntegration(
202-
new LaravelRequestFetcher($this->app)
203-
);
204-
205-
return $allIntegrations;
201+
return array_merge($integrations, $userIntegrations);
206202
});
207203

208204
$hub = new Hub($clientBuilder->getClient());

0 commit comments

Comments
 (0)