Merge pull request #900 from jonnybarnes/899-use-flare-for-errors

feat: Add Flare support
This commit is contained in:
Jonny Barnes 2023-06-09 14:12:11 +01:00 committed by GitHub
commit 3f78d5118a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 337 additions and 383 deletions

View file

@ -83,6 +83,7 @@ APP_LOG=daily
SESSION_SECURE_COOKIE=true
LOG_SLACK_WEBHOOK_URL=
FLARE_KEY=
FONT_LINK=

View file

@ -63,5 +63,8 @@ APP_LOG=daily
SECURE_SESSION_COOKIE=true
LOG_SLACK_WEBHOOK_URL=
FLARE_KEY=
FONT_LINK=
BRIDGY_MASTODON_TOKEN=

View file

@ -2,90 +2,29 @@
namespace App\Exceptions;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
/**
* @codeCoverageIgnore
*/
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, class-string<\Throwable>>
* @var array<int, string>
*/
protected $dontReport = [
NotFoundHttpException::class,
ModelNotFoundException::class,
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @throws Exception
* @throws Throwable
* Register the exception handling callbacks for the application.
*/
public function report(Throwable $e): void
public function register(): void
{
parent::report($e);
if (config('logging.slack') && $this->shouldReport($e)) {
$guzzle = new Client([
'headers' => [
'Content-Type' => 'application/json',
],
]);
$exceptionName = get_class($e) ?? 'Unknown Exception';
$title = $exceptionName . ': ' . $e->getMessage();
$guzzle->post(
config('logging.slack'),
[
'body' => json_encode([
'attachments' => [[
'fallback' => 'There was an exception.',
'pretext' => 'There was an exception.',
'color' => '#d00000',
'author_name' => app()->environment(),
'author_link' => config('app.url'),
'fields' => [[
'title' => $title,
'value' => request()->method() . ' ' . request()->fullUrl(),
]],
'ts' => time(),
]],
]),
]
);
}
}
/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @return Response
*
* @throws Throwable
*/
public function render($request, Throwable $throwable)
{
if ($throwable instanceof TokenMismatchException) {
Route::getRoutes()->match($request);
}
return parent::render($request, $throwable);
$this->reportable(function (Throwable $e) {
//
});
}
}

View file

@ -30,6 +30,7 @@
"league/flysystem-aws-s3-v3": "^3.0",
"mf2/mf2": "~0.3",
"spatie/commonmark-highlighter": "^3.0",
"spatie/laravel-ignition": "^2.1",
"symfony/html-sanitizer": "^6.1"
},
"require-dev": {
@ -44,7 +45,6 @@
"nunomaduro/collision": "^7.0",
"phpunit/php-code-coverage": "^10.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0",
"spatie/laravel-ray": "^1.12",
"vimeo/psalm": "^5.0"
},

614
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "617504ea1be00f742145197dbe3b5792",
"content-hash": "9886cdbfb5e6a5d454345c91d160466e",
"packages": [
{
"name": "aws/aws-crt-php",
@ -4659,6 +4659,68 @@
],
"time": "2022-12-17T21:53:22+00:00"
},
{
"name": "spatie/backtrace",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/backtrace.git",
"reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/backtrace/zipball/ec4dd16476b802dbdc6b4467f84032837e316b8c",
"reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c",
"shasum": ""
},
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"ext-json": "*",
"phpunit/phpunit": "^9.3",
"spatie/phpunit-snapshot-assertions": "^4.2",
"symfony/var-dumper": "^5.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\Backtrace\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van de Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "A better backtrace",
"homepage": "https://github.com/spatie/backtrace",
"keywords": [
"Backtrace",
"spatie"
],
"support": {
"source": "https://github.com/spatie/backtrace/tree/1.4.0"
},
"funding": [
{
"url": "https://github.com/sponsors/spatie",
"type": "github"
},
{
"url": "https://spatie.be/open-source/support-us",
"type": "other"
}
],
"time": "2023-03-04T08:57:24+00:00"
},
{
"name": "spatie/commonmark-highlighter",
"version": "3.0.0",
@ -4713,6 +4775,250 @@
},
"time": "2021-08-04T18:03:57+00:00"
},
{
"name": "spatie/flare-client-php",
"version": "1.3.6",
"source": {
"type": "git",
"url": "https://github.com/spatie/flare-client-php.git",
"reference": "530ac81255af79f114344286e4275f8869c671e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/flare-client-php/zipball/530ac81255af79f114344286e4275f8869c671e2",
"reference": "530ac81255af79f114344286e4275f8869c671e2",
"shasum": ""
},
"require": {
"illuminate/pipeline": "^8.0|^9.0|^10.0",
"php": "^8.0",
"spatie/backtrace": "^1.2",
"symfony/http-foundation": "^5.0|^6.0",
"symfony/mime": "^5.2|^6.0",
"symfony/process": "^5.2|^6.0",
"symfony/var-dumper": "^5.2|^6.0"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.3.0",
"pestphp/pest": "^1.20",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"spatie/phpunit-snapshot-assertions": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.1.x-dev"
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Spatie\\FlareClient\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Send PHP errors to Flare",
"homepage": "https://github.com/spatie/flare-client-php",
"keywords": [
"exception",
"flare",
"reporting",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/flare-client-php/issues",
"source": "https://github.com/spatie/flare-client-php/tree/1.3.6"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-04-12T07:57:12+00:00"
},
{
"name": "spatie/ignition",
"version": "1.8.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/ignition.git",
"reference": "ad13a6792992411e05d3d3b293e26bdf9f9a7321"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/ignition/zipball/ad13a6792992411e05d3d3b293e26bdf9f9a7321",
"reference": "ad13a6792992411e05d3d3b293e26bdf9f9a7321",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": "^8.0",
"spatie/backtrace": "^1.4",
"spatie/flare-client-php": "^1.1",
"symfony/console": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0"
},
"require-dev": {
"illuminate/cache": "^9.52",
"mockery/mockery": "^1.4",
"pestphp/pest": "^1.20",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"psr/simple-cache-implementation": "*",
"symfony/cache": "^6.2",
"symfony/process": "^5.4|^6.0",
"vlucas/phpdotenv": "^5.5"
},
"suggest": {
"openai-php/client": "Require get solutions from OpenAI",
"simple-cache-implementation": "To cache solutions from OpenAI"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.5.x-dev"
}
},
"autoload": {
"psr-4": {
"Spatie\\Ignition\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Spatie",
"email": "info@spatie.be",
"role": "Developer"
}
],
"description": "A beautiful error page for PHP applications.",
"homepage": "https://flareapp.io/ignition",
"keywords": [
"error",
"flare",
"laravel",
"page"
],
"support": {
"docs": "https://flareapp.io/docs/ignition-for-laravel/introduction",
"forum": "https://twitter.com/flareappio",
"issues": "https://github.com/spatie/ignition/issues",
"source": "https://github.com/spatie/ignition"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-05-25T10:19:32+00:00"
},
{
"name": "spatie/laravel-ignition",
"version": "2.1.3",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-ignition.git",
"reference": "35711943d4725aa80f8033e4f1cb3a6775530b25"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/35711943d4725aa80f8033e4f1cb3a6775530b25",
"reference": "35711943d4725aa80f8033e4f1cb3a6775530b25",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"illuminate/support": "^10.0",
"php": "^8.1",
"spatie/flare-client-php": "^1.3.5",
"spatie/ignition": "^1.5.0",
"symfony/console": "^6.2.3",
"symfony/var-dumper": "^6.2.3"
},
"require-dev": {
"livewire/livewire": "^2.11",
"mockery/mockery": "^1.5.1",
"openai-php/client": "^0.3.4",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^1.22.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1.1",
"phpstan/phpstan-phpunit": "^1.3.3",
"vlucas/phpdotenv": "^5.5"
},
"suggest": {
"openai-php/client": "Require get solutions from OpenAI",
"psr/simple-cache-implementation": "Needed to cache solutions from OpenAI"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\LaravelIgnition\\IgnitionServiceProvider"
],
"aliases": {
"Flare": "Spatie\\LaravelIgnition\\Facades\\Flare"
}
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Spatie\\LaravelIgnition\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Spatie",
"email": "info@spatie.be",
"role": "Developer"
}
],
"description": "A beautiful error page for Laravel applications.",
"homepage": "https://flareapp.io/ignition",
"keywords": [
"error",
"flare",
"laravel",
"page"
],
"support": {
"docs": "https://flareapp.io/docs/ignition-for-laravel/introduction",
"forum": "https://twitter.com/flareappio",
"issues": "https://github.com/spatie/laravel-ignition/issues",
"source": "https://github.com/spatie/laravel-ignition"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-05-25T11:30:27+00:00"
},
{
"name": "symfony/console",
"version": "v6.3.0",
@ -11223,312 +11529,6 @@
],
"time": "2023-05-11T14:04:07+00:00"
},
{
"name": "spatie/backtrace",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/backtrace.git",
"reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/backtrace/zipball/ec4dd16476b802dbdc6b4467f84032837e316b8c",
"reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c",
"shasum": ""
},
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"ext-json": "*",
"phpunit/phpunit": "^9.3",
"spatie/phpunit-snapshot-assertions": "^4.2",
"symfony/var-dumper": "^5.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\Backtrace\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van de Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "A better backtrace",
"homepage": "https://github.com/spatie/backtrace",
"keywords": [
"Backtrace",
"spatie"
],
"support": {
"source": "https://github.com/spatie/backtrace/tree/1.4.0"
},
"funding": [
{
"url": "https://github.com/sponsors/spatie",
"type": "github"
},
{
"url": "https://spatie.be/open-source/support-us",
"type": "other"
}
],
"time": "2023-03-04T08:57:24+00:00"
},
{
"name": "spatie/flare-client-php",
"version": "1.3.6",
"source": {
"type": "git",
"url": "https://github.com/spatie/flare-client-php.git",
"reference": "530ac81255af79f114344286e4275f8869c671e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/flare-client-php/zipball/530ac81255af79f114344286e4275f8869c671e2",
"reference": "530ac81255af79f114344286e4275f8869c671e2",
"shasum": ""
},
"require": {
"illuminate/pipeline": "^8.0|^9.0|^10.0",
"php": "^8.0",
"spatie/backtrace": "^1.2",
"symfony/http-foundation": "^5.0|^6.0",
"symfony/mime": "^5.2|^6.0",
"symfony/process": "^5.2|^6.0",
"symfony/var-dumper": "^5.2|^6.0"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.3.0",
"pestphp/pest": "^1.20",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"spatie/phpunit-snapshot-assertions": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.1.x-dev"
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Spatie\\FlareClient\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Send PHP errors to Flare",
"homepage": "https://github.com/spatie/flare-client-php",
"keywords": [
"exception",
"flare",
"reporting",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/flare-client-php/issues",
"source": "https://github.com/spatie/flare-client-php/tree/1.3.6"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-04-12T07:57:12+00:00"
},
{
"name": "spatie/ignition",
"version": "1.8.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/ignition.git",
"reference": "ad13a6792992411e05d3d3b293e26bdf9f9a7321"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/ignition/zipball/ad13a6792992411e05d3d3b293e26bdf9f9a7321",
"reference": "ad13a6792992411e05d3d3b293e26bdf9f9a7321",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": "^8.0",
"spatie/backtrace": "^1.4",
"spatie/flare-client-php": "^1.1",
"symfony/console": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0"
},
"require-dev": {
"illuminate/cache": "^9.52",
"mockery/mockery": "^1.4",
"pestphp/pest": "^1.20",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"psr/simple-cache-implementation": "*",
"symfony/cache": "^6.2",
"symfony/process": "^5.4|^6.0",
"vlucas/phpdotenv": "^5.5"
},
"suggest": {
"openai-php/client": "Require get solutions from OpenAI",
"simple-cache-implementation": "To cache solutions from OpenAI"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.5.x-dev"
}
},
"autoload": {
"psr-4": {
"Spatie\\Ignition\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Spatie",
"email": "info@spatie.be",
"role": "Developer"
}
],
"description": "A beautiful error page for PHP applications.",
"homepage": "https://flareapp.io/ignition",
"keywords": [
"error",
"flare",
"laravel",
"page"
],
"support": {
"docs": "https://flareapp.io/docs/ignition-for-laravel/introduction",
"forum": "https://twitter.com/flareappio",
"issues": "https://github.com/spatie/ignition/issues",
"source": "https://github.com/spatie/ignition"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-05-25T10:19:32+00:00"
},
{
"name": "spatie/laravel-ignition",
"version": "2.1.3",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-ignition.git",
"reference": "35711943d4725aa80f8033e4f1cb3a6775530b25"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/35711943d4725aa80f8033e4f1cb3a6775530b25",
"reference": "35711943d4725aa80f8033e4f1cb3a6775530b25",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"illuminate/support": "^10.0",
"php": "^8.1",
"spatie/flare-client-php": "^1.3.5",
"spatie/ignition": "^1.5.0",
"symfony/console": "^6.2.3",
"symfony/var-dumper": "^6.2.3"
},
"require-dev": {
"livewire/livewire": "^2.11",
"mockery/mockery": "^1.5.1",
"openai-php/client": "^0.3.4",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^1.22.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1.1",
"phpstan/phpstan-phpunit": "^1.3.3",
"vlucas/phpdotenv": "^5.5"
},
"suggest": {
"openai-php/client": "Require get solutions from OpenAI",
"psr/simple-cache-implementation": "Needed to cache solutions from OpenAI"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\LaravelIgnition\\IgnitionServiceProvider"
],
"aliases": {
"Flare": "Spatie\\LaravelIgnition\\Facades\\Flare"
}
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Spatie\\LaravelIgnition\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Spatie",
"email": "info@spatie.be",
"role": "Developer"
}
],
"description": "A beautiful error page for Laravel applications.",
"homepage": "https://flareapp.io/ignition",
"keywords": [
"error",
"flare",
"laravel",
"page"
],
"support": {
"docs": "https://flareapp.io/docs/ignition-for-laravel/introduction",
"forum": "https://twitter.com/flareappio",
"issues": "https://github.com/spatie/laravel-ignition/issues",
"source": "https://github.com/spatie/laravel-ignition"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2023-05-25T11:30:27+00:00"
},
{
"name": "spatie/laravel-ray",
"version": "1.32.4",

View file

@ -3,6 +3,7 @@
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
use Monolog\Processor\PsrLogMessageProcessor;
return [
@ -53,7 +54,7 @@ return [
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'channels' => ['daily', 'flare'],
'ignore_exceptions' => false,
],
@ -61,6 +62,7 @@ return [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],
'daily' => [
@ -68,6 +70,7 @@ return [
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
'replace_placeholders' => true,
],
'slack' => [
@ -76,6 +79,7 @@ return [
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => env('LOG_LEVEL', 'critical'),
'replace_placeholders' => true,
],
'papertrail' => [
@ -87,6 +91,7 @@ return [
'port' => env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
],
'processors' => [PsrLogMessageProcessor::class],
],
'stderr' => [
@ -97,16 +102,20 @@ return [
'with' => [
'stream' => 'php://stderr',
],
'processors' => [PsrLogMessageProcessor::class],
],
'syslog' => [
'driver' => 'syslog',
'level' => env('LOG_LEVEL', 'debug'),
'facility' => LOG_USER,
'replace_placeholders' => true,
],
'errorlog' => [
'driver' => 'errorlog',
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],
'null' => [
@ -117,8 +126,10 @@ return [
'emergency' => [
'path' => storage_path('logs/laravel.log'),
],
'flare' => [
'driver' => 'flare',
],
],
'slack' => env('LOG_SLACK_WEBHOOK_URL'),
];