Skip to content

Commit 5f329a4

Browse files
authored
Do not register default error and fatal listeners and let Larave… (#280)
1 parent db55dfb commit 5f329a4

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Sentry\State\HubInterface;
88
use Illuminate\Log\LogManager;
99
use Laravel\Lumen\Application as Lumen;
10-
use Sentry\Integration\IntegrationInterface;
10+
use Sentry\Integration as SdkIntegration;
1111
use Illuminate\Foundation\Application as Laravel;
1212
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1313

@@ -123,6 +123,31 @@ protected function configureAndRegisterClient(): void
123123
$clientBuilder->setSdkIdentifier(Version::SDK_IDENTIFIER);
124124
$clientBuilder->setSdkVersion(Version::SDK_VERSION);
125125

126+
$options = $clientBuilder->getOptions();
127+
128+
if ($options->hasDefaultIntegrations()) {
129+
$integrations = $options->getIntegrations();
130+
131+
// Remove the default error and fatal exception listeners to let Laravel handle those
132+
// itself. These event are still bubbling up through the documented changes in the users
133+
// `ExceptionHandler` of their application or through the log channel integration to Sentry
134+
$options->setIntegrations(array_filter($integrations, static function (SdkIntegration\IntegrationInterface $integration): bool {
135+
if ($integration instanceof SdkIntegration\ErrorListenerIntegration) {
136+
return false;
137+
}
138+
139+
if ($integration instanceof SdkIntegration\ExceptionListenerIntegration) {
140+
return false;
141+
}
142+
143+
if ($integration instanceof SdkIntegration\FatalErrorListenerIntegration) {
144+
return false;
145+
}
146+
147+
return true;
148+
}));
149+
}
150+
126151
$hub = new Hub($clientBuilder->getClient());
127152

128153
Integration::setCurrentHub($hub);
@@ -157,7 +182,7 @@ private function getIntegrations(): array
157182
$userIntegrations = $this->getUserConfig()['integrations'] ?? [];
158183

159184
foreach ($userIntegrations as $userIntegration) {
160-
if ($userIntegration instanceof IntegrationInterface) {
185+
if ($userIntegration instanceof SdkIntegration\IntegrationInterface) {
161186
$integrations[] = $userIntegration;
162187
} elseif (\is_string($userIntegration)) {
163188
$integrations[] = $this->app->make($userIntegration);

0 commit comments

Comments
 (0)