Skip to content

Commit

Permalink
Added E2E test for Laravel error reporting component
Browse files Browse the repository at this point in the history
  • Loading branch information
asgrim committed Nov 23, 2021
1 parent ba8b12a commit 676fd85
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 2 deletions.
52 changes: 52 additions & 0 deletions .github/fixtures/laravel5-6-exception-handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
$this->container->make(\Scoutapm\ScoutApmAgent::class)->recordThrowable($exception);
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
56 changes: 56 additions & 0 deletions .github/fixtures/laravel7-exception-handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
$this->container->make(\Scoutapm\ScoutApmAgent::class)->recordThrowable($exception);
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
}
41 changes: 41 additions & 0 deletions .github/fixtures/laravel8-exception-handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
$this->container->make(\Scoutapm\ScoutApmAgent::class)->recordThrowable($e);
});
}
}
22 changes: 20 additions & 2 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ jobs:
run: cd test-app && composer require scoutapp/scout-apm-php:*@dev php-http/guzzle6-adapter nyholm/psr7 composer/package-versions-deprecated
- name: "Publish the provider"
run: cd test-app && php artisan vendor:publish --provider="Scoutapm\Laravel\Providers\ScoutApmServiceProvider"
- name: "Configure error handler (Laravel 5-6)"
if: ${{ matrix.laravel-version == '5.5.*' || matrix.laravel-version == '6.*' }}
run: cd test-app && cp ../scout-apm-php/.github/fixtures/laravel5-6-exception-handler.php app/Exceptions/Handler.php
- name: "Configure error handler (Laravel 7)"
if: ${{ matrix.laravel-version == '7.*' }}
run: cd test-app && cp ../scout-apm-php/.github/fixtures/laravel7-exception-handler.php app/Exceptions/Handler.php
- name: "Configure error handler (Laravel 8)"
if: ${{ matrix.laravel-version == '8.*' }}
run: cd test-app && cp ../scout-apm-php/.github/fixtures/laravel8-exception-handler.php app/Exceptions/Handler.php
- name: "Add route to trigger error"
run: cd test-app && echo -e "Route::get('/e', function () { throw new \RuntimeException('fail'); });" >> routes/web.php
- name: "Configure Scout"
run: cd test-app && echo -e "\nSCOUT_KEY=\"\${SCOUT_APM_KEY}\"\nSCOUT_NAME=\"My Laravel App\"\nSCOUT_MONITOR=true\nSCOUT_LOG_LEVEL=\"debug\"" >> .env
run: cd test-app && echo -e "\nSCOUT_KEY=\"\${SCOUT_APM_KEY}\"\nSCOUT_NAME=\"My Laravel App\"\nSCOUT_MONITOR=true\nSCOUT_LOG_LEVEL=\"debug\"\nSCOUT_ERRORS_ENABLED=true" >> .env
- name: "Load the index page to trigger instrumentation"
run: |
cd test-app
Expand All @@ -116,11 +127,18 @@ jobs:
# Very occasionally in GH Actions, core-agent didn't quite start in time - so load the page twice
wget -O /dev/null http://localhost:8000
sleep 1
wget http://localhost:8000
# Regular page load instrumentation
wget --content-on-error -O index.html http://localhost:8000
cat index.html
# Error capture
wget --content-on-error -O error.html http://localhost:8000/e || true
cat error.html
ps -ax
- name: "Check logs for successful payload send"
run: |
cd test-app
cat storage/logs/laravel.log
echo "Checking for APM instrumentation"
grep -q "local.DEBUG: \[Scout\] Sent whole payload successfully to core agent." storage/logs/laravel.log
echo "Checking for Error Reporting"
grep -q "local.DEBUG: \[Scout\] Sent 1 error event to Scout Error Reporting" storage/logs/laravel.log

0 comments on commit 676fd85

Please sign in to comment.