Symfony

Symfony is a set of reusable PHP components and a PHP framework to build web applications and services. Learn how to set it up with Sentry.

  • You need a Sentry account and project
  • Your Symfony application needs to run on PHP 7.2 or later

Install the sentry/sentry-symfony bundle:

Copied
composer require sentry/sentry-symfony

If you're already using Monolog, see the Monolog integration docs for Monolog-related configuration.

Add your DSN to your .env file:

.env
Copied
###> sentry/sentry-symfony ###
SENTRY_DSN="___PUBLIC_DSN___"
###< sentry/sentry-symfony ###

When using Symfony Flex, the Sentry bundle is configured to be enabled in the prod environment only by default. You can change this behaviour in your config/packages/sentry.yaml and config/bundles.php files.

To test that Sentry is capturing unhandled exceptions, you can create the following controller:

Copied
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Attribute\Route;

class SentryTestController extends AbstractController
{
    #[Route('/_sentry-test', name: 'sentry_test')]
    public function testException()
    {
        throw new \RuntimeException('Example exception.');
    }
}

After you visit the /_sentry-test page, you can view and resolve the recorded error by logging into sentry.io and opening your project.

  • Explore practical guides on what to monitor, log, track, and investigate after setup
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").