Skip to content

Commit 19e3da6

Browse files
cleptricstayallive
andauthored
Add support for Laravel 11 (#845)
Co-authored-by: Alex Bouma <[email protected]>
1 parent 1b7fc23 commit 19e3da6

File tree

7 files changed

+57
-30
lines changed

7 files changed

+57
-30
lines changed

.github/workflows/ci.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ jobs:
3030
# All versions below only support PHP ^8.1 (Laravel requirement)
3131
- { laravel: ^10.0, testbench: ^8.0, phpunit: 9.6.* }
3232

33+
# All versions below only support PHP ^8.2 (Laravel requirement)
34+
- { laravel: ^11.0, testbench: ^9.0, phpunit: 10.5.* }
35+
exclude:
36+
- php: "8.1"
37+
packages: { laravel: ^11.0, testbench: ^9.0, phpunit: 10.5.* }
38+
3339
name: phpunit (PHP:${{ matrix.php }}, Laravel:${{ matrix.packages.laravel }})
3440

3541
steps:
@@ -60,7 +66,7 @@ jobs:
6066
composer install --no-interaction --prefer-dist --no-progress
6167
6268
- name: Run phpunit
63-
run: vendor/bin/phpunit --coverage-clover=coverage.xml
69+
run: vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-filter=src/Sentry
6470

6571
- name: Upload code coverage
6672
uses: codecov/codecov-action@v3
@@ -150,7 +156,7 @@ jobs:
150156
composer install --no-interaction --prefer-dist --no-progress
151157
152158
- name: Run phpunit
153-
run: vendor/bin/phpunit --coverage-clover=coverage.xml
159+
run: vendor/bin/phpunit --coverage-clover=coverage.xml --whitelist=src/Sentry
154160

155161
- name: Upload code coverage
156162
uses: codecov/codecov-action@v3

README.md

+23-10
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ This is the official Laravel SDK for [Sentry](https://sentry.io).
1919

2020
## Getting Started
2121

22-
The installation steps below work on versions 8.x, 9.x and 10.x of the Laravel framework.
22+
The installation steps below work on version 11.x of the Laravel framework.
2323

2424
For older Laravel versions and Lumen see:
2525

26-
- [Laravel 8.x & 9.x & 10.x](https://docs.sentry.io/platforms/php/guides/laravel/)
26+
- [Laravel 11.x](https://docs.sentry.io/platforms/php/guides/laravel/)
27+
- [Laravel 8.x & 9.x & 10.x](https://docs.sentry.io/platforms/php/guides/other-versions/laravel8-10)
2728
- [Laravel 6.x & 7.x](https://docs.sentry.io/platforms/php/guides/laravel/other-versions/laravel6-7/)
2829
- [Laravel 5.x](https://docs.sentry.io/platforms/php/guides/laravel/other-versions/laravel5/)
2930
- [Laravel 4.x](https://docs.sentry.io/platforms/php/guides/laravel/other-versions/laravel4/)
@@ -37,17 +38,28 @@ Install the `sentry/sentry-laravel` package:
3738
composer require sentry/sentry-laravel
3839
```
3940

40-
Enable capturing unhandled exception to report to Sentry by making the following change to your `app/Exceptions/Handler.php`:
41+
Enable capturing unhandled exception to report to Sentry by making the following change to your `bootstrap/app.php`:
4142

42-
```php {filename:app/Exceptions/Handler.php}
43+
```php {filename:bootstrap/app.php}
44+
<?php
45+
46+
use Illuminate\Foundation\Application;
47+
use Illuminate\Foundation\Configuration\Exceptions;
48+
use Illuminate\Foundation\Configuration\Middleware;
4349
use Sentry\Laravel\Integration;
4450

45-
public function register(): void
46-
{
47-
$this->reportable(function (Throwable $e) {
48-
Integration::captureUnhandledException($e);
49-
});
50-
}
51+
return Application::configure(basePath: dirname(__DIR__))
52+
->withRouting(
53+
web: __DIR__.'/../routes/web.php',
54+
commands: __DIR__.'/../routes/console.php',
55+
health: '/up',
56+
)
57+
->withMiddleware(function (Middleware $middleware) {
58+
//
59+
})
60+
->withExceptions(function (Exceptions $exceptions) {
61+
Integration::handles($exceptions);
62+
})->create();
5163
```
5264

5365
> Alternatively, you can configure Sentry as a [Laravel Log Channel](https://docs.sentry.io/platforms/php/guides/laravel/usage/#log-channels), allowing you to capture `info` and `debug` logs as well.
@@ -84,6 +96,7 @@ To learn more about how to use the SDK [refer to our docs](https://docs.sentry.i
8496

8597
The Laravel and Lumen versions listed below are all currently supported:
8698

99+
- Laravel `>= 11.x.x` on PHP `>= 8.2` is supported starting from `4.3.0`
87100
- Laravel `>= 10.x.x` on PHP `>= 8.1` is supported starting from `3.2.0`
88101
- Laravel `>= 9.x.x` on PHP `>= 8.0` is supported starting from `2.11.0`
89102
- Laravel `>= 8.x.x` on PHP `>= 7.3` is supported starting from `1.9.0`

composer.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
],
2525
"require": {
2626
"php": "^7.2 | ^8.0",
27-
"illuminate/support": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
27+
"illuminate/support": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0",
2828
"sentry/sentry": "^4.5",
2929
"symfony/psr-http-message-bridge": "^1.0 | ^2.0 | ^6.0 | ^7.0",
3030
"nyholm/psr7": "^1.0"
@@ -36,13 +36,13 @@
3636
},
3737
"require-dev": {
3838
"phpunit/phpunit": "^8.4 | ^9.3 | ^10.4",
39-
"laravel/framework": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
39+
"laravel/framework": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0",
4040
"livewire/livewire": "^2.0 | ^3.0",
41-
"orchestra/testbench": "^4.7 | ^5.1 | ^6.0 | ^7.0 | ^8.0",
41+
"orchestra/testbench": "^4.7 | ^5.1 | ^6.0 | ^7.0 | ^8.0 | ^9.0",
4242
"friendsofphp/php-cs-fixer": "^3.11",
4343
"mockery/mockery": "^1.3",
4444
"phpstan/phpstan": "^1.10",
45-
"laravel/folio": "^1.0",
45+
"laravel/folio": "^1.1",
4646
"guzzlehttp/guzzle": "^7.2"
4747
},
4848
"autoload-dev": {
@@ -75,5 +75,6 @@
7575
"config": {
7676
"sort-packages": true
7777
},
78-
"prefer-stable": true
78+
"prefer-stable": true,
79+
"minimum-stability": "dev"
7980
}

config/sentry.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
// 'ignore_exceptions' => [],
3434

3535
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#ignore-transactions
36-
// 'ignore_transactions' => [],
36+
'ignore_transactions' => [
37+
// Ignore Laravel's default health URL
38+
'/up',
39+
],
3740

3841
// Breadcrumb specific configuration
3942
'breadcrumbs' => [

phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ parameters:
100100
count: 1
101101
path: src/Sentry/Laravel/Features/Storage/Integration.php
102102

103+
-
104+
message: "#^Parameter \\$exceptions of method Sentry\\\\Laravel\\\\Integration\\:\\:handles\\(\\) has invalid type Illuminate\\\\Foundation\\\\Configuration\\\\Exceptions\\.$#"
105+
count: 1
106+
path: src/Sentry/Laravel/Integration.php
107+
103108
-
104109
message: "#^Class Laravel\\\\Lumen\\\\Application not found\\.$#"
105110
count: 3

phpunit.xml

-12
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,4 @@
1212
<directory>./test/Sentry/</directory>
1313
</testsuite>
1414
</testsuites>
15-
16-
<coverage>
17-
<include>
18-
<directory suffix=".php">./src/Sentry/</directory>
19-
</include>
20-
</coverage>
21-
22-
<filter>
23-
<whitelist>
24-
<directory suffix=".php">src</directory>
25-
</whitelist>
26-
</filter>
2715
</phpunit>

src/Sentry/Laravel/Integration.php

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\LazyLoadingViolationException;
7+
use Illuminate\Foundation\Configuration\Exceptions;
78
use Illuminate\Routing\Route;
89
use Sentry\EventHint;
910
use Sentry\EventId;
@@ -52,6 +53,16 @@ public function setupOnce(): void
5253
});
5354
}
5455

56+
/**
57+
* Convienence method to register the exception handler with Laravel 11.0 and up.
58+
*/
59+
public static function handles(Exceptions $exceptions): void
60+
{
61+
$exceptions->reportable(static function (Throwable $exception) {
62+
self::captureUnhandledException($exception);
63+
});
64+
}
65+
5566
/**
5667
* Adds a breadcrumb if the integration is enabled for Laravel.
5768
*

0 commit comments

Comments
 (0)