Skip to content

Commit 54e696b

Browse files
committed
Add Sentry support
1 parent 2a6927c commit 54e696b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Exceptions/ExceptionHandler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public function report(Exception $e)
4141
}
4242

4343
$this->logger->error($e->getMessage(), $context);
44+
45+
$this->addSentrySupport($e);
46+
}
47+
48+
private function addSentrySupport(Exception $e)
49+
{
50+
if (app()->bound('sentry') && $this->shouldReport($e)) {
51+
app('sentry')->captureException($e);
52+
}
4453
}
4554

4655
private function registerShutdownFunction()

tests/Exceptions/ExceptionHandlerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public function it_logs_an_error_for_all_occurred_application_notices_warnings_e
2727
]));
2828
}
2929

30+
/** @test */
31+
public function it_supports_sentry()
32+
{
33+
app()->instance('sentry', $sentry = spy());
34+
$exception = new Exception('Test exception', 111);
35+
36+
$handler = app(ExceptionHandler::class);
37+
$handler->setLogger(spy(LoggerInterface::class));
38+
$handler->report($exception);
39+
40+
$sentry->shouldHaveReceived('captureException', [$exception]);
41+
}
42+
3043
/** @test */
3144
public function it_supports_custom_runtime_exception_which_has_ability_to_set_optional_context()
3245
{

0 commit comments

Comments
 (0)