Laravel Options

Most configuration for Laravel is done in your .env file. You can also add additonal config options to your config/sentry.php file.

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

config/sentry.php
Copied
'breadcrumbs' => [
    // Capture Laravel logs as breadcrumbs
    'logs' => env('SENTRY_BREADCRUMBS_LOGS_ENABLED', true),

    // Capture Laravel cache events (hits, writes etc.) as breadcrumbs
    'cache' => env('SENTRY_BREADCRUMBS_CACHE_ENABLED', true),

    // Capture Livewire components like routes as breadcrumbs
    'livewire' => env('SENTRY_BREADCRUMBS_LIVEWIRE_ENABLED', true),

    // Capture SQL queries as breadcrumbs
    'sql_queries' => env('SENTRY_BREADCRUMBS_SQL_QUERIES_ENABLED', true),

    // Capture SQL query bindings (parameters) in SQL query breadcrumbs
    'sql_bindings' => env('SENTRY_BREADCRUMBS_SQL_BINDINGS_ENABLED', false),

    // Capture queue job information as breadcrumbs
    'queue_info' => env('SENTRY_BREADCRUMBS_QUEUE_INFO_ENABLED', true),

    // Capture command information as breadcrumbs
    'command_info' => env('SENTRY_BREADCRUMBS_COMMAND_JOBS_ENABLED', true),

    // Capture HTTP client request information as breadcrumbs
    'http_client_requests' => env('SENTRY_BREADCRUMBS_HTTP_CLIENT_REQUESTS_ENABLED', true),
],

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

.env
Copied
# You may need to adjust this value in your production environment to prevent quota issues
SENTRY_TRACES_SAMPLE_RATE=1.0

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;
},

You can also configure which parts of your application are traced automatically. These settings have no effect if SENTRY_TRACES_SAMPLE_RATE is set to 0.0 or if the environment variable is not set:

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

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

    // Capture SQL queries as spans
    'sql_queries' => env('SENTRY_TRACE_SQL_QUERIES_ENABLED', true),

    // Capture SQL query bindings (parameters) in SQL query spans
    'sql_bindings' => env('SENTRY_TRACE_SQL_BINDINGS_ENABLED', false),

    // Capture where the SQL query originated from on the SQL query spans
    'sql_origin' => env('SENTRY_TRACE_SQL_ORIGIN_ENABLED', true),

    // Capture views rendered as spans
    'views' => env('SENTRY_TRACE_VIEWS_ENABLED', true),

    // Capture Livewire components as spans
    'livewire' => env('SENTRY_TRACE_LIVEWIRE_ENABLED', true),

    // Capture HTTP client requests as spans
    'http_client_requests' => env('SENTRY_TRACE_HTTP_CLIENT_REQUESTS_ENABLED', true),

    // Capture Redis operations as spans (this enables Redis events in Laravel)
    'redis_commands' => env('SENTRY_TRACE_REDIS_COMMANDS', false),

    // Capture where the Redis command originated from on the Redis command spans
    'redis_origin' => env('SENTRY_TRACE_REDIS_ORIGIN_ENABLED', true),

    // Enable tracing for requests without a matching route (404's)
    'missing_routes' => env('SENTRY_TRACE_MISSING_ROUTES_ENABLED', false),

    // Configures if the performance trace should continue after the response has been sent to the user until the application terminates
    // This is required to capture any spans that are created after the response has been sent like queue jobs dispatched using `dispatch(...)->afterResponse()` for example
    'continue_after_response' => env('SENTRY_TRACE_CONTINUE_AFTER_RESPONSE', true),

    // Enable the tracing integrations supplied by Sentry (recommended)
    'default_integrations' => env('SENTRY_TRACE_DEFAULT_INTEGRATIONS_ENABLED', true),
],

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...
    }
}
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").