Laravel Options

All configuration for Laravel is done in config/sentry.php.

The Laravel integration will create breadcrumbs for certain events occurring in the framework, the capture of this information can be configured using the following options:

config/sentry.php
Copied
'breadcrumbs' => [
    // Capture Laravel logs in breadcrumbs
    'logs' => true,

    // Capture SQL queries in breadcrumbs
    'sql_queries' => true,

    // Capture bindings on SQL queries logged in breadcrumbs
    'sql_bindings' => true,

    // Capture queue job information in breadcrumbs
    'queue_info' => true,

    // Capture command information in breadcrumbs
    'command_info' => true,
],

Performance Monitoring

To enable performance monitoring, set this to a value greater than 0.0:

config/sentry.php
Copied
// Be sure to lower this in production to prevent quota issues
'traces_sample_rate' => 1.0,

Advanced Sample Rate

If you want more control over which requests are monitored, you can use the traces_sampler option:

config/sentry.php
Copied
'traces_sampler' => function (\Sentry\Tracing\SamplingContext $context): float {
    // We always sample if the front-end indicates it was sampled to have full traces front to back
    if ($context->getParentSampled()) {
        return 1.0;
    }

    if (some_condition()) {
        // Drop this transaction, by setting its sample rate to 0
        return 0.0;
    }

    // Default sample rate for all other transactions
    return 0.25;
},

More Configuration

You can also configure what is being monitored automatically. These settings have no effect if traces_sample_rate is set to 0.0:

config/sentry.php
Copied
'tracing' => [
    // Trace queue jobs as their own transactions
    'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', false),

    // Capture queue jobs as spans when executed on the sync driver
    'queue_jobs' => true,

    // Capture SQL queries as spans
    'sql_queries' => true,

    // Try to find out where the SQL query originated from and add it to the query spans
    'sql_origin' => true,

    // Capture views as spans
    'views' => true,

    // Indicates if the tracing integrations supplied by Sentry should be loaded
    // See all default integration: https://github.com/getsentry/sentry-laravel/tree/master/src/Sentry/Laravel/Tracing/Integrations
    'default_integrations' => true,
],

Controller Base Namespace

Performance monitoring and router breadcrumbs can report the controller classname that handled the request.

These names are generally longer than needed, that's why we strip away the base namespace that is the same for all controller classes.

In Laravel this is App\Http\Controllers by default but you can override this using the controllers_base_namespace option:

config/sentry.php
Copied
'controllers_base_namespace' => env('SENTRY_CONTROLLERS_BASE_NAMESPACE', 'App\\Http\\Controllers'),

Closures and Config Caching

Sometimes the SDK requires a closure as an option value. However, this causes problems when using php artisan config:cache, resulting in the Your configuration files are not serializable error.

We can work around that by providing a callable instead of a closure. In this example we are using the traces_sampler option, but this can be used for any other option that accepts a closure:

config/sentry.php
Copied
'traces_sampler' => [App\Exceptions\Sentry::class, 'tracesSampler'],

This callable points to the App\Exceptions\Sentry class and the tracesSampler method:

app/Exceptions/Sentry.php
Copied
<?php

namespace App\Exceptions;

use Sentry\Tracing\SamplingContext;

class Sentry
{
    public static function tracesSampler(SamplingContext $context): float
    {
        // The code you would have placed in the closure...
    }
}