-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathTypo3Integration.php
More file actions
71 lines (59 loc) · 2.34 KB
/
Typo3Integration.php
File metadata and controls
71 lines (59 loc) · 2.34 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace Networkteam\SentryClient\Integration;
use Psr\Http\Message\ServerRequestInterface;
use Sentry\Event;
use Sentry\Integration\IntegrationInterface;
use Sentry\SentrySdk;
use Sentry\State\Scope;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Information\Typo3Version;
final class Typo3Integration implements IntegrationInterface
{
public function setupOnce(): void
{
Scope::addGlobalEventProcessor(function (Event $event): Event {
$currentHub = SentrySdk::getCurrentHub();
$integration = $currentHub->getIntegration(self::class);
$client = $currentHub->getClient();
// The client bound to the current hub, if any, could not have this
// integration enabled. If this is the case, bail out
if (null === $integration || null === $client) {
return $event;
}
$this->processEvent($event);
return $event;
});
}
private function processEvent(Event $event): void
{
$request = $this->getServerRequest();
if (!Environment::isCli() && $request instanceof ServerRequestInterface) {
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
$event->setTag('request_type', 'frontend');
$this->setUrl($event, $request);
} elseif (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
$event->setTag('request_type', 'backend');
$this->setUrl($event, $request);
}
} elseif (Environment::isCli()) {
$event->setTag('request_type', 'cli');
}
$requestId = $_SERVER['X-REQUEST-ID'] ?? $_SERVER['HTTP_X_REQUEST_ID'] ?? false;
if ($requestId) {
$event->setTag('request_id', $requestId);
}
$event->setTag('typo3_version', (new Typo3Version())->getVersion());
}
protected function setUrl(Event $event, ServerRequestInterface $request): void
{
$requestData = $event->getRequest();
$requestData['url'] = $request->getUri()->__toString();
$event->setRequest($requestData);
}
protected function getServerRequest(): ?ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'] ?? null;
}
}