-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExceptionContextIntegration.php
More file actions
46 lines (37 loc) · 1.22 KB
/
ExceptionContextIntegration.php
File metadata and controls
46 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
* @contact [email protected]
*/
namespace FriendsOfHyperf\Sentry\Integration;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\Integration\IntegrationInterface;
use Sentry\SentrySdk;
use Sentry\State\Scope;
class ExceptionContextIntegration implements IntegrationInterface
{
public function setupOnce(): void
{
Scope::addGlobalEventProcessor(static function (Event $event, ?EventHint $hint = null): Event {
$self = SentrySdk::getCurrentHub()->getIntegration(self::class);
if (! $self instanceof self) {
return $event;
}
if ($hint === null || $hint->exception === null) {
return $event;
}
if (method_exists($hint->exception, 'context')) {
$context = $hint->exception->context();
if (is_array($context)) {
$event->setExtra(['exception_context' => $context]);
}
}
return $event;
});
}
}