/
NetteHttpIntegration.php
50 lines (36 loc) 路 1.03 KB
/
NetteHttpIntegration.php
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
47
48
49
50
<?php declare(strict_types = 1);
namespace Contributte\Sentry\Integration;
use Nette\DI\Container;
use Nette\Http\IRequest;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\State\HubInterface;
class NetteHttpIntegration extends BaseIntegration
{
public function __construct(protected Container $context)
{
}
public function setup(HubInterface $hub, Event $event, EventHint $hint): ?Event
{
$httpRequest = $this->context->getByType(IRequest::class, false);
// There is no http request
if (!$httpRequest instanceof IRequest) {
return $event;
}
$data = [
'url' => $httpRequest->getUrl()->__toString(),
'method' => $httpRequest->getMethod(),
];
if ($httpRequest->getUrl()->getQuery() !== '') {
$data['query_string'] = $httpRequest->getUrl()->getQuery();
}
$data['cookies'] = $httpRequest->getCookies();
$data['headers'] = $httpRequest->getHeaders();
$body = $httpRequest->getRawBody();
if ($body !== null && $body !== '') {
$data['data'] = $body;
}
$event->setRequest($data);
return $event;
}
}