Skip to content

Ensure user integrations are always executed after SDK integrations #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Ensure user integrations are always executed after SDK integrations (#474)

## 2.4.2

- Avoid collision if another package has bound `sentry` in the Laravel container (#467)
Expand Down
66 changes: 31 additions & 35 deletions src/Sentry/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,39 @@ protected function configureAndRegisterClient(): void
$userIntegrations = $this->resolveIntegrationsFromUserConfig();

$options->setIntegrations(function (array $integrations) use ($options, $userIntegrations) {
$allIntegrations = array_merge($integrations, $userIntegrations);

if (!$options->hasDefaultIntegrations()) {
return $allIntegrations;
if ($options->hasDefaultIntegrations()) {
// Remove the default error and fatal exception listeners to let Laravel handle those
// itself. These event are still bubbling up through the documented changes in the users
// `ExceptionHandler` of their application or through the log channel integration to Sentry
$integrations = array_filter($integrations, static function (SdkIntegration\IntegrationInterface $integration): bool {
if ($integration instanceof SdkIntegration\ErrorListenerIntegration) {
return false;
}

if ($integration instanceof SdkIntegration\ExceptionListenerIntegration) {
return false;
}

if ($integration instanceof SdkIntegration\FatalErrorListenerIntegration) {
return false;
}

// We also remove the default request integration so it can be readded
// after with a Laravel specific request fetcher. This way we can resolve
// the request from Laravel instead of constructing it from the global state
if ($integration instanceof SdkIntegration\RequestIntegration) {
return false;
}

return true;
});

$integrations[] = new SdkIntegration\RequestIntegration(
new LaravelRequestFetcher($this->app)
);
}

// Remove the default error and fatal exception listeners to let Laravel handle those
// itself. These event are still bubbling up through the documented changes in the users
// `ExceptionHandler` of their application or through the log channel integration to Sentry
$allIntegrations = array_filter($allIntegrations, static function (SdkIntegration\IntegrationInterface $integration): bool {
if ($integration instanceof SdkIntegration\ErrorListenerIntegration) {
return false;
}

if ($integration instanceof SdkIntegration\ExceptionListenerIntegration) {
return false;
}

if ($integration instanceof SdkIntegration\FatalErrorListenerIntegration) {
return false;
}

// We also remove the default request integration so it can be readded
// after with a Laravel specific request fetcher. This way we can resolve
// the request from Laravel instead of constructing it from the global state
if ($integration instanceof SdkIntegration\RequestIntegration) {
return false;
}

return true;
});

$allIntegrations[] = new SdkIntegration\RequestIntegration(
new LaravelRequestFetcher($this->app)
);

return $allIntegrations;
return array_merge($integrations, $userIntegrations);
});

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