Observability and operations – Sentry configuration

This section explains how the Prep Network platform integrates Sentry for error monitoring, performance tracing, and operational reporting. The Laravel SDK is configured to capture logs, SQL queries (with bindings), queue jobs, and Artisan commands. Privacy-sensitive data is protected by disabling default PII, and tracing is sampling-controlled via environment variables.

Configuration file (config/sentry.php)

The config/sentry.php file defines Sentry’s core settings: DSN, environment, breadcrumb capture, PII handling, and tracing rate .

<?php

return [

    // Data Source Name (DSN) for Sentry ingestion
    'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),

    // Application environment (overrides app.env if set)
    'environment' => env('SENTRY_ENVIRONMENT'),

    // Breadcrumb settings: which events to attach as breadcrumbs
    'breadcrumbs' => [
        'logs'         => true,  // Capture Laravel logs
        'sql_queries'  => true,  // Capture SQL queries
        'sql_bindings' => true,  // Include query bindings
        'queue_info'   => true,  // Capture queue job info
        'command_info' => true,  // Capture Artisan command info
    ],

    // Do NOT send default PII (user IP, usernames, etc.)
    'send_default_pii'    => false,

    // Performance tracing sample rate (0.0 to 1.0)
    'traces_sample_rate'  => floatval(env('SENTRY_TRACES_SAMPLE_RATE', 0.0)),
];

The SDK attaches breadcrumbs—a trail of events leading up to an error—to each issue. You can enable or disable these captures via boolean flags:

Option Default Description
logs true Capture application log entries
sql_queries true Log SQL statements executed
sql_bindings true Attach parameter bindings for SQL queries
queue_info true Record queue job dispatch/processing details
command_info true Track Artisan command executions

PII and tracing

  • send_default_pii false disables automatic sending of user-identifiable data.
  • traces_sample_rate controls performance monitoring. A value of 0.0 disables tracing; increase to e.g. 0.1 to sample 10% of requests.
SENTRY_LARAVEL_DSN=https://[email protected]/0
SENTRY_ENVIRONMENT=production
SENTRY_TRACES_SAMPLE_RATE=0.05

Bootstrapping Sentry in Laravel

The Sentry SDK is registered during application bootstrap in bootstrap/app.php. It hooks into the exception handler to ensure all uncaught exceptions are reported .

use Sentry\Laravel\Integration;
use Illuminate\Foundation\Configuration\Exceptions;

// ...

return Application::configure(basePath: dirname(__DIR__))
    // ...
    ->withExceptions(function (Exceptions $exceptions) {
        Integration::handles($exceptions);
    })
    ->create();

Exception handling (app/Exceptions/Handler.php)

The global exception handler reports errors to Sentry in two places :

  • report(): captures exceptions explicitly when app('sentry') is bound.
  • register(): uses Integration::captureUnhandledException() for any unreported throwables.
public function report(Throwable $exception)
{
    if (app()->bound('sentry') && $this->shouldReport($exception)) {
        app('sentry')->captureException($exception);
    }
    parent::report($exception);
}

public function register(): void
{
    $this->reportable(function (Throwable $e) {
        Integration::captureUnhandledException($e);
    });
}

Operational commands 🛠️

sentry:generate-report

A one-off Artisan command generates a CSV of recent Sentry issues for operational review . It uses an API key configured in config/services.php .

// config/services.php
'sentry' => [
    'api_key' => env('SENTRY_API_KEY'),
],
# Generate a 30-day Sentry issues report in CSV format
php artisan sentry:generate-report
  • Output: sentry-report.csv with columns ID, Link, Title, Culprit, Last Seen, Count.
  • Prerequisite: set SENTRY_API_KEY in .env.
{
    "title": "Tip",
    "content": "Ensure SENTRY_API_KEY is set to access Sentry’s HTTP API for reporting."
}

By centralizing Sentry configuration and integration, we maintain consistent error reporting, control privacy-sensitive data, and enable flexible performance monitoring across all environments.