Skip to content

Commit

Permalink
Merge pull request #32 from flownative/task/update-sentry
Browse files Browse the repository at this point in the history
Update to Sentry SDK v4
  • Loading branch information
kdambekalns authored Nov 15, 2024
2 parents f655f0f + 861944d commit 14baab5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 84 deletions.
5 changes: 2 additions & 3 deletions Classes/Command/SentryCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
*/

use Flownative\Sentry\SentryClient;
use Flownative\Sentry\Test\JsonSerializableTestArgument;
use Flownative\Sentry\Test\SentryClientTestException;
use Flownative\Sentry\Test\StringableTestArgument;
use Flownative\Sentry\Test\ThrowingClass;
use Neos\Flow\Annotations\Inject;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Sentry\Severity;

final class SentryCommandController extends CommandController
{
/**
* @Inject
* @Flow\Inject
* @var SentryClient
*/
protected $sentryClient;
Expand Down
4 changes: 0 additions & 4 deletions Classes/Context/DefaultUserContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

class DefaultUserContextService implements UserContextServiceInterface
{
/**
* @param Context $securityContext
* @return UserContextInterface
*/
public function getUserContext(Context $securityContext): UserContextInterface
{
$userContext = new UserContext();
Expand Down
33 changes: 3 additions & 30 deletions Classes/Context/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,37 @@

class UserContext implements UserContextInterface
{
/**
* @var string
*/
private $id = '';
private string $id = '';

/**
* @var string
*/
private $username = '';
private string $username = '';

/**
* @var string
*/
private $email = '';
private string $email = '';

/**
* @return string
*/
public function getId(): string
{
return $this->id;
}

/**
* @param string $id
*/
public function setId(string $id): void
{
$this->id = $id;
}

/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}

/**
* @param string $username
*/
public function setUsername(string $username): void
{
$this->username = $username;
}

/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}

/**
* @param string $email
*/
public function setEmail(string $email): void
{
$this->email = $email;
Expand Down
11 changes: 0 additions & 11 deletions Classes/Context/UserContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,10 @@

interface UserContextInterface
{
/**
* @return string|null
*/
public function getId(): ?string;

/**
* @return string|null
*/
public function getUsername(): ?string;

/**
* @return string|null
*/
public function getEmail(): ?string;

/**
Expand All @@ -36,8 +27,6 @@ public function getEmail(): ?string;
* "id", "username", "email"
*
* The keys must exist, but the values may be empty
*
* @return array
*/
public function toArray(): array;
}
3 changes: 0 additions & 3 deletions Classes/Context/UserContextServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ interface UserContextServiceInterface
{
/**
* Returns ContextData to be added to the sentry entry
*
* @param Context $securityContext
* @return UserContextInterface
*/
public function getUserContext(Context $securityContext): UserContextInterface;
}
34 changes: 11 additions & 23 deletions Classes/Log/SentryFileBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ class SentryFileBackend extends FileBackend
{
use SentryClientTrait;

/**
* @var bool
*/
private $capturingMessage = false;
private bool $capturingMessage = false;

/**
* Appends the given message along with the additional information into the log.
*
* @param string $message The message to log
* @param int $severity One of the LOG_* constants
* @param mixed $additionalData A variable containing more information about the event to be logged
* @param string|null $packageKey Key of the package triggering the log (determined automatically if not specified)
* @param string|null $className Name of the class triggering the log (determined automatically if not specified)
* @param string|null $methodName Name of the method triggering the log (determined automatically if not specified)
* @param string|null $packageKey Key of the package triggering the log
* @param string|null $className Name of the class triggering the log
* @param string|null $methodName Name of the method triggering the log
* @return void
* @api
*/
public function append(string $message, int $severity = LOG_INFO, $additionalData = null, string $packageKey = null, string $className = null, string $methodName = null): void
public function append(string $message, int $severity = LOG_INFO, $additionalData = null, ?string $packageKey = null, ?string $className = null, ?string $methodName = null): void
{
if ($this->capturingMessage) {
return;
Expand All @@ -49,20 +45,12 @@ public function append(string $message, int $severity = LOG_INFO, $additionalDat

$sentryClient = self::getSentryClient();
if ($severity <= LOG_NOTICE && $sentryClient) {
switch ($severity) {
case LOG_WARNING:
$sentrySeverity = Severity::warning();
break;
case LOG_ERR:
$sentrySeverity = Severity::error();
break;
case LOG_CRIT:
case LOG_ALERT:
case LOG_EMERG:
$sentrySeverity = Severity::fatal();
break;
default:
$sentrySeverity = Severity::info();
$sentrySeverity = match ($severity) {
LOG_WARNING => Severity::warning(),
LOG_ERR => Severity::error(),
LOG_CRIT, LOG_ALERT, LOG_EMERG => Severity::fatal(),
default => Severity::info(),
};

}

Expand Down
3 changes: 0 additions & 3 deletions Classes/SentryClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

trait SentryClientTrait
{
/**
* @return SentryClient|null
*/
protected static function getSentryClient(): ?SentryClient
{
if (!Bootstrap::$staticObjectManager instanceof ObjectManagerInterface || Bootstrap::$staticObjectManager instanceof CompileTimeObjectManager) {
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Packagist](https://img.shields.io/packagist/v/flownative/sentry.svg)](https://packagist.org/packages/flownative/sentry)
[![Maintenance level: Love](https://img.shields.io/badge/maintenance-%E2%99%A1%E2%99%A1%E2%99%A1-ff69b4.svg)](https://www.flownative.com/en/products/open-source.html)

# Sentry integration for Flow 6.x, 7.x and Flow 8.x
# Sentry integration for Flow 8.x and 9.x

This [Flow](https://flow.neos.io) package allows you to automate
reporting of errors to [Sentry](https://www.sentry.io)
Expand Down Expand Up @@ -121,6 +121,4 @@ Test "previous" exception thrown by the SentryCommandController
Line: 78
Open Data/Logs/Exceptions/2021030308325919ecbf.txt for a full stack trace.
````
```
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
],
"require": {
"ext-json": "*",
"php": "^7.4 || ^8.0",
"neos/flow": "^6.3 || ^7.0 || ^8.0 || ^9.0 || @dev",
"sentry/sdk": "^3.0",
"php": "^8.1",
"neos/flow": "^8.0 || ^9.0 || @dev",
"sentry/sentry": "^4.0",
"jenssegers/agent": "^2.6"
},
"autoload": {
Expand Down

0 comments on commit 14baab5

Please sign in to comment.