Symfony

Bundle for Symfony 6.4+

Free on every plan, including the free one
Where to get it Packagist
Requirements Symfony 6.4+, PHP 8.2+
Package name dockcodes/dock-ray-symfony
Pricing Free

What it is for

The official DockRay package integrates Symfony applications with the monitoring platform and automatically reports exceptions, console command errors, and HTTP request processing times. Events are sent directly to the DockRay dashboard along with the information needed to quickly diagnose issues.

Error and Exception Monitoring

DockRay integrates with Symfony’s exception handling system and reports errors that occur while processing HTTP requests.

Reported events can include:

  • the exception type and message,
  • where the exception occurred and the stack trace,
  • environment and application version information,
  • context related to the request being processed.

Selected exception classes can be excluded from reporting, such as 404 errors generated by NotFoundHttpException.

Performance Monitoring

The package can monitor the processing time of main HTTP requests and send transactions to DockRay. The frequency of data collection can be controlled using a sampling rate.

Selected paths, such as the Symfony profiler, can be excluded from performance monitoring.

Console Commands

DockRay can also report errors from Symfony Console commands. Events are tagged with the command name, making it easier to diagnose issues that occur outside standard HTTP requests.

User Context and Privacy

If the application uses the Symfony Security component, DockRay can optionally include information about the authenticated user with reported events. Sending the IP address and user agent is controlled by a separate setting.

Developer Features

The DockRay Hub is available as a Symfony service and can be injected into your own classes. This allows you to manually report caught exceptions from anywhere in your application.

The integration also supports long-running processes and workers, using a single DockRay client instance throughout the lifetime of the process.

Installation

Package Installation

Install DockRay using Composer:

bash
composer require dockcodes/dock-ray-symfony

If your project uses Symfony Flex, the bundle will be registered automatically.

If your project does not use Symfony Flex, register the bundle manually in config/bundles.php:

php
<?php

return [
    // ...

    Dock\Ray\Symfony\RayBundle::class => ['all' => true],
];

Configuration

Create or update the config/packages/ray.yaml file:

ray:
    token: '%env(RAY_TOKEN)%'
    private_key: '%env(RAY_PRIVATE_KEY)%'
    traces_sample_rate: 0.2
    ignore_exceptions:
        - Symfony\Component\HttpKernel\Exception\NotFoundHttpException

Then add your DockRay project credentials to the .env file:

RAY_TOKEN=project-token
RAY_PRIVATE_KEY=project-private-key

You can find your project token and private key in the DockRay dashboard. Without these values, the bundle will load but will not send any data.

Additional settings allow you to configure the environment, application version, error and transaction sampling, user data, and exceptions and paths that should be excluded from monitoring.

How to use it

The integration reports exceptions on its own. This is for the reports you send deliberately.

php
<?php

use Dock\Ray\State\HubInterface;

final class ImportService
{
    public function __construct(private HubInterface $ray) {
    }

    public function import(): void
    {
        try {
            $this->run();
        } catch (\Throwable $exception) {
            $this->ray->captureException($exception);

            throw $exception;
        }
    }
}

Knowledge base articles

Start Monitoring

Connect your first application and get full visibility into what’s happening in production.

DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.