Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add new method to report unhandled exceptions from the Laravel error handler (#608)

## 3.0.1

- Remove incorrect checks if performance tracing should be enabled and rely on the transaction sampling decision instead (#600)
Expand Down
31 changes: 31 additions & 0 deletions src/Sentry/Laravel/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
namespace Sentry\Laravel;

use Illuminate\Routing\Route;
use Sentry\EventHint;
use Sentry\EventId;
use Sentry\ExceptionMechanism;
use Sentry\SentrySdk;
use Sentry\Tracing\TransactionSource;
use Throwable;
use function Sentry\addBreadcrumb;
use function Sentry\captureEvent;
use function Sentry\configureScope;
use Sentry\Breadcrumb;
use Sentry\Event;
Expand Down Expand Up @@ -162,4 +167,30 @@ public static function sentryBaggageMeta(): string

return sprintf('<meta name="baggage" content="%s"/>', $span->toBaggage());
}

/**
* Capture a unhandled exception and report it to Sentry.
*
* @param \Throwable $throwable
*
* @return \Sentry\EventId|null
*/
public static function captureUnhandledException(Throwable $throwable): ?EventId
{
$client = SentrySdk::getCurrentHub()->getClient();

// When Sentry is not configured, because for example no DSN
// is set the client can be null. If that is the case we cannot
// transmit the event so, exit early to prevent doing useless work
if ($client === null) {
return null;
}

$hint = EventHint::fromArray([
'exception' => $throwable,
'mechanism' => new ExceptionMechanism(ExceptionMechanism::TYPE_GENERIC, false),
]);

return $client->captureEvent(Event::createEvent(), $hint);
}
}