Skip to content

Commit 6e93aff

Browse files
committed
Use Sentry default integrations
This activates the default integrations shipped with Sentry again. This adds information about installed Composer packages, the request, frame context and environment. Through this, some "custom" tags can be dropped, as the information is included by the default integrations. Since Sentry registers an error handler, errors not handled by the exception handler will also be recorded in Sentry.
1 parent 5cd55ba commit 6e93aff

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

Classes/SentryClient.php

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use Flownative\Sentry\Context\UserContextServiceInterface;
1818
use Flownative\Sentry\Context\WithExtraDataInterface;
1919
use Flownative\Sentry\Log\CaptureResult;
20-
use GuzzleHttp\Psr7\ServerRequest;
21-
use Jenssegers\Agent\Agent;
2220
use Neos\Flow\Annotations as Flow;
2321
use Neos\Flow\Core\Bootstrap;
2422
use Neos\Flow\Error\WithReferenceCodeInterface;
@@ -31,7 +29,6 @@
3129
use Neos\Flow\Utility\Environment;
3230
use Neos\Utility\Arrays;
3331
use Psr\Log\LoggerInterface;
34-
use Psr\Log\LogLevel;
3532
use Sentry\Event;
3633
use Sentry\EventHint;
3734
use Sentry\EventId;
@@ -93,6 +90,10 @@ public function injectSettings(array $settings): void
9390

9491
public function initializeObject(): void
9592
{
93+
if (empty($this->dsn)) {
94+
return;
95+
}
96+
9697
$representationSerializer = new RepresentationSerializer(
9798
new Options([])
9899
);
@@ -102,10 +103,6 @@ public function initializeObject(): void
102103
$representationSerializer
103104
);
104105

105-
if (empty($this->dsn)) {
106-
return;
107-
}
108-
109106
\Sentry\init([
110107
'dsn' => $this->dsn,
111108
'environment' => $this->environment,
@@ -118,8 +115,7 @@ public function initializeObject(): void
118115
FLOW_PATH_ROOT . '/Packages/Framework/Neos.Flow/Classes/Log/',
119116
FLOW_PATH_ROOT . '/Packages/Libraries/neos/flow-log/'
120117
],
121-
'default_integrations' => false,
122-
'attach_stacktrace' => true
118+
'attach_stacktrace' => true,
123119
]);
124120

125121
$client = SentrySdk::getCurrentHub()->getClient();
@@ -136,38 +132,18 @@ private function setTags(): void
136132
try {
137133
$flowPackage = $this->packageManager->getPackage('Neos.Flow');
138134
$flowVersion = $flowPackage->getInstalledVersion();
139-
} catch (UnknownPackageException $e) {
135+
} catch (UnknownPackageException) {
140136
}
141137
}
142138
if (empty($flowVersion)) {
143139
$flowVersion = FLOW_VERSION_BRANCH;
144140
}
145141

146-
$currentSession = null;
147-
if ($this->sessionManager) {
148-
$currentSession = $this->sessionManager->getCurrentSession();
149-
}
142+
$currentSession = $this->sessionManager?->getCurrentSession();
150143

151144
SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use ($flowVersion, $currentSession): void {
152145
$scope->setTag('flow_version', $flowVersion);
153146
$scope->setTag('flow_context', (string)Bootstrap::$staticObjectManager->get(Environment::class)->getContext());
154-
$scope->setTag('php_version', PHP_VERSION);
155-
156-
if (PHP_SAPI !== 'cli') {
157-
$scope->setTag('uri',
158-
(string)ServerRequest::fromGlobals()->getUri());
159-
160-
$agent = new Agent();
161-
$scope->setContext('client_os', [
162-
'name' => $agent->platform(),
163-
'version' => $agent->version($agent->platform())
164-
]);
165-
166-
$scope->setContext('client_browser', [
167-
'name' => $agent->browser(),
168-
'version' => $agent->version($agent->browser())
169-
]);
170-
}
171147

172148
if ($currentSession instanceof Session && $currentSession->isStarted()) {
173149
$scope->setTag('flow_session_sha1', sha1($currentSession->getId()));
@@ -226,7 +202,7 @@ public function captureThrowable(Throwable $throwable, array $extraData = [], ar
226202
$message = 'ignored';
227203
}
228204
return new CaptureResult(
229-
true,
205+
true,
230206
$message,
231207
(string)$sentryEventId
232208
);
@@ -326,7 +302,7 @@ private function prepareStacktrace(\Throwable $throwable = null): Stacktrace
326302
$frame->getRawFunctionName(),
327303
$frame->getAbsoluteFilePath(),
328304
$frame->getVars(),
329-
strpos($classPathAndFilename, 'Packages/Framework/') === false
305+
!str_contains($classPathAndFilename, 'Packages/Framework/')
330306
);
331307
}
332308
return new Stacktrace($frames);

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"ext-json": "*",
1818
"php": "^8.1",
1919
"neos/flow": "^8.0 || ^9.0 || @dev",
20-
"sentry/sentry": "^4.0",
21-
"jenssegers/agent": "^2.6"
20+
"sentry/sentry": "^4.0"
2221
},
2322
"autoload": {
2423
"psr-4": {

0 commit comments

Comments
 (0)