Skip to content

Commit

Permalink
Merge pull request #427 from facade/feature/query-exception-recording
Browse files Browse the repository at this point in the history
Add support for recording raw sql queries
  • Loading branch information
rubenvanassche authored Nov 16, 2021
2 parents 23400e6 + d9c57de commit 06a34c6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/compiled/ignition.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/js/components/Tabs/ContextTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const predefinedContextItemGroups = [
'context',
'logs',
'dumps',
'exception',
];
export default {
Expand Down
1 change: 1 addition & 0 deletions src/Actions/ShareReportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ protected function getCustomContextGroups(array $contextItems): array
'context',
'logs',
'dumps',
'exception',
];

return Collection::make($contextItems)
Expand Down
2 changes: 2 additions & 0 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Facade\Ignition\LogRecorder\LogRecorder;
use Facade\Ignition\Middleware\AddDumps;
use Facade\Ignition\Middleware\AddEnvironmentInformation;
use Facade\Ignition\Middleware\AddExceptionInformation;
use Facade\Ignition\Middleware\AddGitInformation;
use Facade\Ignition\Middleware\AddJobInformation;
use Facade\Ignition\Middleware\AddLogs;
Expand Down Expand Up @@ -392,6 +393,7 @@ protected function registerBuiltInMiddleware()
$middlewares = [
SetNotifierName::class,
AddEnvironmentInformation::class,
AddExceptionInformation::class,
];

if (config('flare.reporting.report_logs')) {
Expand Down
24 changes: 24 additions & 0 deletions src/Middleware/AddExceptionInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Facade\Ignition\Middleware;

use Facade\FlareClient\Report;
use Illuminate\Database\QueryException;

class AddExceptionInformation
{
public function handle(Report $report, $next)
{
$throwable = $report->getThrowable();

if (! $throwable instanceof QueryException) {
return $next($report);
}

$report->group('exception', [
'raw_sql' => $throwable->getSql(),
]);

return $next($report);
}
}
38 changes: 38 additions & 0 deletions tests/Middleware/AddExceptionInformationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Facade\Ignition\Tests\Middleware;

use Exception;
use Facade\Ignition\Facades\Flare;
use Facade\Ignition\Tests\TestCase;
use Illuminate\Database\QueryException;

class AddExceptionInformationTest extends TestCase
{
/** @test */
public function it_will_add_query_information_with_a_query_exception()
{
$sql = 'select * from users where emai = "[email protected]"';

$report = Flare::createReport(new QueryException(
'' . $sql . '',
[],
new Exception()
));

$context = $report->toArray()['context'];

$this->assertArrayHasKey('exception', $context);
$this->assertSame($sql, $context['exception']['raw_sql']);
}

/** @test */
public function it_wont_add_query_information_without_a_query_exception()
{
$report = Flare::createReport(new Exception());

$context = $report->toArray()['context'];

$this->assertArrayNotHasKey('exception', $context);
}
}

0 comments on commit 06a34c6

Please sign in to comment.