Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry + Swarrot Processor #233

Closed
voodoo-dn opened this issue Aug 28, 2019 · 2 comments
Closed

Sentry + Swarrot Processor #233

voodoo-dn opened this issue Aug 28, 2019 · 2 comments

Comments

@voodoo-dn
Copy link

Hi to everyone. I use very nice bundle https://github.com/swarrot/SwarrotBundle for Symfony.
Because current version of this bundle does not supports newest version of sentry-symfony, I use own sentry processor.

Main problem: all errors sent when consumer is died. Realtime error tracking doesn't works.

Current configuration:

sentry:
    dsn: '%env(SENTRY_DSN)%'
    options:
        release: '%env(RELEASE_NAME)%'
        environment: '%env(SENTRY_ENV)%'
        enable_compression: false

Installation was via that documentation https://docs.sentry.io/platforms/php/symfony/#installation

<?php

declare(strict_types=1);

namespace App\Infrastructure\Swarrot\Processor;

use Sentry\State\HubInterface;
use Sentry\State\Scope;
use Swarrot\Broker\Message;
use Swarrot\Processor\ProcessorInterface;

class SentryProcessor implements ProcessorInterface
{
    /**
     * @var ProcessorInterface
     */
    private $processor;

    /**
     * @var HubInterface
     */
    private $hub;

    /**
     * SentryProcessor constructor.
     *
     * @param ProcessorInterface $processor
     * @param HubInterface       $hub
     */
    public function __construct(ProcessorInterface $processor, HubInterface $hub)
    {
        $this->processor = $processor;
        $this->hub = $hub;
    }

    /**
     * @param Message $message
     * @param array   $options
     *
     * @return bool|null
     *
     * @throws \Throwable
     */
    public function process(Message $message, array $options): ?bool
    {
        try {
            return $this->processor->process($message, $options);
        } catch (\Throwable $e) {
            $this->handleException($e, $message, $options);
        }
    }

    /**
     * @param \Throwable $e
     * @param Message    $message
     * @param array      $options
     *
     * @throws \Throwable
     */
    private function handleException(\Throwable $e, Message $message, array $options): void
    {
        $properties = $message->getProperties();

        $messageBody = $message->getBody();
        $queue = $options['queue'];
        $routingKey = $properties['routing_key'];

        $this->hub->withScope(function (Scope $scope) use ($messageBody, $queue, $routingKey, $e): void {
            $scope->setExtra('message', $messageBody);
            $scope->setExtra('queue', $queue);
            $scope->setExtra('routing_key', $routingKey);

            $this->hub->captureException($e);
        });

        throw $e;
    }
}
@voodoo-dn
Copy link
Author

Also consumer use a lot of memory when I use SentryProcessor.

@Jean85
Copy link
Collaborator

Jean85 commented Aug 29, 2019

This issue is related/duplicated of getsentry/sentry-php#811. This is not an issue with the bundle but with the base SDK.

That issue seems to be fixed now, and will be released as 2.2. You can try to use sentry/sentry:dev-master to see if that solves your issue.

@Jean85 Jean85 closed this as completed Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants