Sentry Integration

Hey there,

I’ve attempted to integrate sentry to Pimcore. The forum didn’t give me any results, so am asking here now.

  1. Add Sentry: composer require sentry/sentry-symfony:^3.0
  2. Register bundle in AppKernel
public function registerBundles()
    {
        $bundles = [
            // ...
            new \Sentry\SentryBundle\SentryBundle(),
        ];

        // ...
    }
  1. Add sentry to services.yml
services:
...
    sentry:
        dsn: '%env(SENTRY_DSN)%'
        options:
            excluded_exceptions:
                - Symfony\Component\Security\Core\Exception\AccessDeniedException
                - Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

    parameters:
        env(SENTRY_DSN): ''

My AppKernel looks different though, it doesn’t have registerBundles but the following:

class AppKernel extends Kernel
{
    /**
     * Adds bundles to register to the bundle collection. The collection is able
     * to handle priorities and environment specific bundles.
     *
     * @param BundleCollection $collection
     */
    public function registerBundlesToCollection(BundleCollection $collection)
    {
        if (class_exists('\\AppBundle\\AppBundle')) {
            $collection->addBundle(new \AppBundle\AppBundle);
        }

        if (class_exists('\Pimcore\Bundle\LegacyBundle\PimcoreLegacyBundle')) {
            $collection->addBundle(new \Pimcore\Bundle\LegacyBundle\PimcoreLegacyBundle);
        }

        // tried adding it like that then
        if (class_exists('\Sentry\SentryBundle\SentryBundle')) {
            $collection->addBundle(new \Sentry\SentryBundle\SentryBundle());
        }
    }
}

Could anyone help me out on this?

Also getting this error:

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The configuration key "dsn" is unsupported for definition "sentry" in "/Users/.../Documents/code/...-pimcore/src/app/config/services.yml". Allowed configuration keys are "alias", "parent", "class", "shared", "synthetic", "lazy", "public", "abstract", "deprecated", "factory", "file", "arguments", "properties", "configurator", "calls", "tags", "decorates", "decoration_inner_name", "decoration_priority", "decoration_on_invalid", "autowire", "autoconfigure", "bind". in /Users/.../Documents/code/...-pimcore/src/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php:876

sentry section should be outside services of your services.yml
Add it to root of config.yml, or even better, to a separate file.

My configuration is as follows:

config.yml:

imports:
  - { resource: parameters.yml }
  - { resource: security.yml }
  - { resource: services.yml }
  - { resource: 'local/' }
  - { resource: 'packages/'}

And packages/sentry.yml:

sentry:
    dsn: '%env(SENTRY_DSN)%'
    options:
        excluded_exceptions:
            - Symfony\Component\Security\Core\Exception\AccessDeniedException
            - Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

parameters:
  env(SENTRY_DSN): ''
1 Like

Thanks, will try that shortly. And the AppKernel then as I’ve tried, I assume?

If it’s necessary, we’re on Pimcore 6.6