# Symfony | Sentry for Symfony

## [Prerequisites](https://docs.sentry.io/platforms/php/guides/symfony.md#prerequisites)

* You need a [Sentry account](https://sentry.io/signup/) and project
* Your Symfony application needs to run on PHP 7.2 or later

## [Install](https://docs.sentry.io/platforms/php/guides/symfony.md#install)

Install the `sentry/sentry-symfony` bundle:

```bash
composer require sentry/sentry-symfony
```

If you are using [Monolog](https://github.com/Seldaek/monolog) to report events instead of the typical error listener approach, you need this [additional configuration](https://docs.sentry.io/platforms/php/guides/symfony/integrations/monolog.md) to log the errors correctly.

## [Configure](https://docs.sentry.io/platforms/php/guides/symfony.md#configure)

Add your DSN to your `.env` file:

`.env`

```plain
###> 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.

In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini

## [Verify](https://docs.sentry.io/platforms/php/guides/symfony.md#verify)

To test that both logger error and exception are correctly sent to sentry.io, you can create the following controller:

```php
<?php

namespace App\Controller;

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

class SentryTestController extends AbstractController
{
    public function __construct(private LoggerInterface $logger)
    {
    }

    #[Route('/_sentry-test', name: 'sentry_test')]
    public function testLog()
    {
        // the following code will test if monolog integration logs to sentry
        $this->logger->error('My custom logged error.', ['some' => 'Context Data']);

        // the following code will test if an uncaught exception logs to sentry
        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](https://sentry.io) and opening your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

## Pages in this section

- [configuration](https://docs.sentry.io/platforms/php/guides/symfony/configuration.md)
- [crons](https://docs.sentry.io/platforms/php/guides/symfony/crons.md)
- [data-management](https://docs.sentry.io/platforms/php/guides/symfony/data-management.md)
- [enriching-events](https://docs.sentry.io/platforms/php/guides/symfony/enriching-events.md)
- [feature-flags](https://docs.sentry.io/platforms/php/guides/symfony/feature-flags.md)
- [integrations](https://docs.sentry.io/platforms/php/guides/symfony/integrations.md)
- [logs](https://docs.sentry.io/platforms/php/guides/symfony/logs.md)
- [metrics](https://docs.sentry.io/platforms/php/guides/symfony/metrics.md)
- [profiling](https://docs.sentry.io/platforms/php/guides/symfony/profiling.md)
- [security-policy-reporting](https://docs.sentry.io/platforms/php/guides/symfony/security-policy-reporting.md)
- [tracing](https://docs.sentry.io/platforms/php/guides/symfony/tracing.md)
- [troubleshooting](https://docs.sentry.io/platforms/php/guides/symfony/troubleshooting.md)
- [usage](https://docs.sentry.io/platforms/php/guides/symfony/usage.md)
- [user-feedback](https://docs.sentry.io/platforms/php/guides/symfony/user-feedback.md)
