1717use Flownative \Sentry \Context \UserContextServiceInterface ;
1818use Flownative \Sentry \Context \WithExtraDataInterface ;
1919use Flownative \Sentry \Log \CaptureResult ;
20- use GuzzleHttp \Psr7 \ServerRequest ;
21- use Jenssegers \Agent \Agent ;
2220use Neos \Flow \Annotations as Flow ;
2321use Neos \Flow \Core \Bootstrap ;
2422use Neos \Flow \Error \WithReferenceCodeInterface ;
3129use Neos \Flow \Utility \Environment ;
3230use Neos \Utility \Arrays ;
3331use Psr \Log \LoggerInterface ;
34- use Psr \Log \LogLevel ;
3532use Sentry \Event ;
3633use Sentry \EventHint ;
3734use 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 ()));
@@ -213,6 +189,7 @@ public function captureThrowable(Throwable $throwable, array $extraData = [], ar
213189
214190 $ captureException = (!in_array (get_class ($ throwable ), $ this ->excludeExceptionTypes , true ));
215191 if ($ captureException ) {
192+ $ this ->setTags ();
216193 $ this ->configureScope ($ extraData , $ tags );
217194 if ($ throwable instanceof Exception && $ throwable ->getStatusCode () === 404 ) {
218195 SentrySdk::getCurrentHub ()->configureScope (static function (Scope $ scope ): void {
@@ -226,7 +203,7 @@ public function captureThrowable(Throwable $throwable, array $extraData = [], ar
226203 $ message = 'ignored ' ;
227204 }
228205 return new CaptureResult (
229- true ,
206+ true ,
230207 $ message ,
231208 (string )$ sentryEventId
232209 );
@@ -249,6 +226,7 @@ public function captureMessage(string $message, Severity $severity, array $extra
249226 $ eventHint = EventHint::fromArray ([
250227 'stacktrace ' => $ this ->prepareStacktrace ()
251228 ]);
229+ $ this ->setTags ();
252230 $ sentryEventId = \Sentry \captureMessage ($ message , $ severity , $ eventHint );
253231
254232 if ($ this ->logger ) {
@@ -326,7 +304,7 @@ private function prepareStacktrace(\Throwable $throwable = null): Stacktrace
326304 $ frame ->getRawFunctionName (),
327305 $ frame ->getAbsoluteFilePath (),
328306 $ frame ->getVars (),
329- strpos ($ classPathAndFilename , 'Packages/Framework/ ' ) === false
307+ ! str_contains ($ classPathAndFilename , 'Packages/Framework/ ' )
330308 );
331309 }
332310 return new Stacktrace ($ frames );
0 commit comments