Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 67a2659

Browse files
committed
WIP
1 parent cbdefd5 commit 67a2659

14 files changed

Lines changed: 97 additions & 74 deletions

Classes/Handler/ContentObjectProductionExceptionHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Exception;
88
use Pluswerk\Sentry\Service\ConfigService;
9-
use Symfony\Component\DependencyInjection\Attribute\Autowire;
109
use Throwable;
1110
use TYPO3\CMS\Frontend\ContentObject\Exception\ExceptionHandlerInterface;
1211
use TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler;

Classes/Handler/DebugExceptionHandler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
namespace Pluswerk\Sentry\Handler;
66

7+
use Pluswerk\Sentry\Service\Sentry;
78
use Pluswerk\Sentry\Traits\ExceptionHandlerTrait;
89

910
class DebugExceptionHandler extends \TYPO3\CMS\Core\Error\DebugExceptionHandler
1011
{
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
// dump(__CLASS__);
16+
// Sentry::getInstance(); // TODO only use \Sentry\init(...);
17+
}
18+
1119
use ExceptionHandlerTrait;
1220
}

Classes/Handler/ProductionExceptionHandler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
namespace Pluswerk\Sentry\Handler;
66

7+
use Pluswerk\Sentry\Service\Sentry;
78
use Pluswerk\Sentry\Traits\ExceptionHandlerTrait;
9+
use function dump;
810

911
class ProductionExceptionHandler extends \TYPO3\CMS\Core\Error\ProductionExceptionHandler
1012
{
13+
public function __construct()
14+
{
15+
parent::__construct();
16+
// dump(__CLASS__);
17+
// Sentry::getInstance(); // TODO only use \Sentry\init(...);
18+
}
19+
1120
use ExceptionHandlerTrait;
1221
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Pluswerk\Sentry\Integration;
6+
7+
use Sentry\Event;
8+
use Sentry\Integration\IntegrationInterface;
9+
use Sentry\State\Scope;
10+
11+
final readonly class ExtSentryIntegration implements IntegrationInterface{
12+
13+
public function setupOnce(): void
14+
{
15+
dd('ExtSentryIntegration::setupOnce() called');
16+
Scope::addGlobalEventProcessor(static function (Event $event): Event {
17+
$extra = $event->getExtra();
18+
$extra['php_version'] ??= PHP_VERSION;
19+
$event->setExtra($extra);
20+
return $event;
21+
});
22+
}
23+
}

Classes/Logger/BreadcrumbLogger.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@
1414
use TYPO3\CMS\Core\Log\Writer\WriterInterface;
1515
use TYPO3\CMS\Core\SingletonInterface;
1616
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
17+
use function sprintf;
1718

1819
class BreadcrumbLogger extends AbstractWriter implements SingletonInterface
1920
{
2021
public function writeLog(LogRecord $record): WriterInterface
2122
{
22-
$hub = Sentry::getInstance()->getHub();
23+
if (!ExtensionManagementUtility::isLoaded('sentry')) {
24+
return $this;
25+
}
26+
27+
$hub = Sentry::getInstance()->getHub(); // TODO remove this if we always call \Sentry\init();
2328
if (!$hub instanceof HubInterface) {
2429
return $this;
2530
}
2631

27-
if (!ExtensionManagementUtility::isLoaded('sentry')) {
32+
if ($record->getComponent() === 'TYPO3.CMS.Frontend.ContentObject.Exception.ProductionExceptionHandler') {
2833
return $this;
2934
}
3035

31-
//send breadcrumb to sentry
32-
$hub->addBreadcrumb(
36+
\Sentry\addBreadcrumb(
3337
new Breadcrumb(
3438
match ($record->getLevel()) {
3539
LogLevel::EMERGENCY => Breadcrumb::LEVEL_FATAL,

Classes/Logger/SentryLogger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ class SentryLogger extends AbstractWriter implements SingletonInterface
2121
{
2222
public function writeLog(LogRecord $record): WriterInterface
2323
{
24-
$client = Sentry::getInstance()->getClient();
25-
if (!$client instanceof ClientInterface) {
24+
if (!ExtensionManagementUtility::isLoaded('sentry')) {
2625
return $this;
2726
}
2827

2928
if ($record->getComponent() === 'TYPO3.CMS.Frontend.ContentObject.Exception.ProductionExceptionHandler') {
3029
return $this;
3130
}
3231

33-
if (!ExtensionManagementUtility::isLoaded('sentry')) {
32+
$client = Sentry::getInstance()->getClient();
33+
if (!$client instanceof ClientInterface) {
3434
return $this;
3535
}
3636

Classes/Service/Sentry.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
namespace Pluswerk\Sentry\Service;
66

77
use InvalidArgumentException;
8-
use Pluswerk\Sentry\Transport\MockTransportFactory;
8+
use Pluswerk\Sentry\Integration\ExtSentryIntegration;
9+
use Pluswerk\Sentry\Tests\Helper\MockTransportFactory;
910
use Pluswerk\Sentry\Transport\QueueTransportFactory;
1011
use Sentry\ClientBuilder;
1112
use Sentry\ClientInterface;
@@ -18,8 +19,6 @@
1819
use TYPO3\CMS\Core\Core\Environment;
1920
use TYPO3\CMS\Core\SingletonInterface;
2021
use TYPO3\CMS\Core\Utility\GeneralUtility;
21-
22-
use function dd;
2322
use function getenv;
2423
use function Sentry\captureException;
2524
use function Sentry\configureScope;
@@ -31,8 +30,27 @@ public function __construct(
3130
protected ScopeConfig $scopeConfig,
3231
protected ConfigService $config,
3332
) {
34-
dd();
35-
$this->setup();
33+
// $this->setup();
34+
}
35+
36+
public function staticSetup()
37+
{
38+
// $config = GeneralUtility::makeInstance(
39+
// ConfigService::class,
40+
// GeneralUtility::makeInstance(ExtensionConfiguration::class),
41+
// );
42+
43+
\Sentry\init([
44+
// 'environment' => preg_replace('#[\/\s]#', '', (string)Environment::getContext()),
45+
'dsn' => 'https://sentry.example.com/123456', // $config->getDsn(),
46+
// 'attach_stacktrace' => true,
47+
// 'error_types' => $config->getErrorsToReport(),
48+
// 'prefixes' => [Environment::getProjectPath()],
49+
// 'release' => $config->isWithGitReleases() ? shell_exec('git rev-parse HEAD') : null,
50+
'integrations' => [
51+
new ExtSentryIntegration(),
52+
]
53+
]);
3654
}
3755

3856
public function isDisabled(): bool
@@ -60,7 +78,8 @@ protected function setup(): void
6078

6179
$builder = ClientBuilder::create(array_filter($options));
6280
if ($this->config->isQueueEnabled()) {
63-
$builder->setTransportFactory(new QueueTransportFactory());
81+
$transport = (new QueueTransportFactory())->create($builder->getOptions());
82+
$builder->setTransport($transport);
6483
}
6584

6685
$this->addMockIfNeeded($builder);
@@ -121,6 +140,7 @@ private function addMockIfNeeded(ClientBuilder $builder): void
121140
if (!$mockSeed) {
122141
return;
123142
}
124-
$builder->setTransportFactory(new MockTransportFactory($mockSeed));
143+
$transport = (new MockTransportFactory($mockSeed))->register($builder->getOptions());
144+
$builder->setTransport($transport);
125145
}
126146
}

Classes/Transport/MockTransportFactory.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

Classes/Transport/QueueTransport.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Sentry\Response;
1717
use Sentry\ResponseStatus;
1818
use Sentry\Serializer\PayloadSerializerInterface;
19+
use Sentry\Transport\Result;
1920
use Sentry\Transport\TransportInterface;
2021

2122
class QueueTransport implements TransportInterface
@@ -24,7 +25,7 @@ public function __construct(private Options $options, private PayloadSerializerI
2425
{
2526
}
2627

27-
public function send(Event $event): PromiseInterface
28+
public function send(Event $event): Result
2829
{
2930
$dsn = $this->options->getDsn();
3031

@@ -46,7 +47,7 @@ public function send(Event $event): PromiseInterface
4647
return new FulfilledPromise($sendResponse);
4748
}
4849

49-
public function close(?int $timeout = null): PromiseInterface
50+
public function close(?int $timeout = null): Result
5051
{
5152
return new FulfilledPromise(true);
5253
}

Classes/Transport/QueueTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Sentry\Transport\TransportInterface;
1313
use TYPO3\CMS\Core\Utility\GeneralUtility;
1414

15-
class QueueTransportFactory implements TransportFactoryInterface
15+
class QueueTransportFactory
1616
{
1717
public function create(Options $options): TransportInterface
1818
{

0 commit comments

Comments
 (0)