diff --git a/src/Exception/FlowEventException.php b/src/Exception/FlowEventException.php new file mode 100644 index 0000000..0330795 --- /dev/null +++ b/src/Exception/FlowEventException.php @@ -0,0 +1,18 @@ +eventName, $level?->toPsrLogLevel() ?? 'unknown'); + parent::__construct($message, $level?->value ?? 0, $previous); + } + +} diff --git a/src/ShopwareSentryBundle.php b/src/ShopwareSentryBundle.php index f620b9b..18cc3b4 100644 --- a/src/ShopwareSentryBundle.php +++ b/src/ShopwareSentryBundle.php @@ -7,6 +7,7 @@ use Frosh\SentryBundle\Integration\UseShopwareExceptionIgnores; use Frosh\SentryBundle\Listener\FixRequestUrlListener; use Frosh\SentryBundle\Listener\SalesChannelContextListener; +use Frosh\SentryBundle\Subscriber\FlowLogSubscriber; use Frosh\SentryBundle\Subscriber\ScheduledTaskSubscriber; use Shopware\Core\System\SalesChannel\Event\SalesChannelContextCreatedEvent; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -44,6 +45,10 @@ public function build(ContainerBuilder $container): void ->addArgument('%frosh_sentry.report_scheduled_tasks%') ->addTag('kernel.event_subscriber'); + $container + ->register(FlowLogSubscriber::class) + ->addTag('kernel.event_subscriber'); + $container->addCompilerPass(new CompilerPass\ExceptionConfigCompilerPass()); } diff --git a/src/Subscriber/FlowLogSubscriber.php b/src/Subscriber/FlowLogSubscriber.php new file mode 100644 index 0000000..3a3efe4 --- /dev/null +++ b/src/Subscriber/FlowLogSubscriber.php @@ -0,0 +1,48 @@ + '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)); + } + +} diff --git a/src/Subscriber/ScheduledTaskSubscriber.php b/src/Subscriber/ScheduledTaskSubscriber.php index 633190a..a7f7fb4 100644 --- a/src/Subscriber/ScheduledTaskSubscriber.php +++ b/src/Subscriber/ScheduledTaskSubscriber.php @@ -103,7 +103,7 @@ public function onScheduledTaskWritten(EntityWrittenEvent $event): void private function captureCheckIn(ScheduledTaskEntity $scheduledTask, CheckInStatus $status): void { - if($status === CheckInStatus::inProgress()) { + if ($status === CheckInStatus::inProgress()) { $scheduledTask->removeExtension('sentryCheckInId'); $checkInId = $this->getCheckInId($scheduledTask); $scheduledTask->addArrayExtension('sentryCheckInId', [$checkInId]); @@ -116,7 +116,7 @@ private function captureCheckIn(ScheduledTaskEntity $scheduledTask, CheckInStatu private function getCheckInId(ScheduledTaskEntity $scheduledTask): ?string { $extension = $scheduledTask->getExtension('sentryCheckInId'); - if($extension instanceof ArrayStruct) { + if ($extension instanceof ArrayStruct) { return \is_string($extension->get(0)) ? $extension->get(0) : null; }