-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from iMi-digital/8-business-events
Support flow event log
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\SentryBundle\Exception; | ||
|
||
use Monolog\Level; | ||
use Throwable; | ||
|
||
class FlowEventException extends \Exception | ||
{ | ||
public function __construct(readonly string $eventName = '', ?Level $level = null, ?Throwable $previous = null, readonly mixed $context = null) | ||
{ | ||
$message = sprintf('Flow event %s level %s occurred', $this->eventName, $level?->toPsrLogLevel() ?? 'unknown'); | ||
parent::__construct($message, $level?->value ?? 0, $previous); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\SentryBundle\Subscriber; | ||
|
||
use Frosh\SentryBundle\Exception\FlowEventException; | ||
use Monolog\Level; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; | ||
use Shopware\Core\Framework\Event\FlowLogEvent; | ||
use Shopware\Core\Framework\Log\LogAware; | ||
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskCollection; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
use function Sentry\captureException; | ||
|
||
class FlowLogSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [FlowLogEvent::NAME => 'sendFlowEvent']; | ||
} | ||
|
||
public function sendFlowEvent(FlowLogEvent $event): void | ||
{ | ||
$innerEvent = $event->getEvent(); | ||
|
||
$additionalData = []; | ||
$logLevel = Level::Debug; | ||
|
||
if ($innerEvent instanceof LogAware) { | ||
$logLevel = $innerEvent->getLogLevel(); | ||
$additionalData = $innerEvent->getLogData(); | ||
} | ||
|
||
if ($logLevel->isLowerThan(Level::Warning)) { | ||
return; | ||
} | ||
|
||
$nestedException = null; | ||
if (method_exists($innerEvent, 'getThrowable')) { | ||
$nestedException = $innerEvent->getThrowable(); | ||
} | ||
|
||
captureException(new FlowEventException($innerEvent->getName(), $logLevel, $nestedException, $additionalData)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters