Start free trial
Start free trial Log in

14-day free trial. No credit card.

How to Track Exceptions in Laravel Production

From the built-in Log facade to fingerprinted tracking with context and alerting.

  • Guide
  • 3 min read

How do I track exceptions in a Laravel app?

Send exceptions to a tracker that fingerprints them by class and the stack frame where they were thrown, then groups repeated occurrences into a single issue with counts, first/last-seen timestamps, and trend graphs. Laravel's Log facade is a baseline. Production apps need a dedicated tracker like NightOwl (BYOD), Nightwatch Cloud, Flare, Sentry, or Bugsnag with alert channels routed to Slack or Discord.

Updated

Every Laravel app catches exceptions. The question is whether anyone finds out about them. Unhandled errors land in a log file by default, which means they're technically recorded and practically invisible. Nobody reads laravel.log until something is already on fire. The whole job of exception tracking is to close the gap between "an error happened" and "a human knows," and to do it without burying the one new bug that matters under ten thousand copies of an old one. That second part (grouping) is what separates a tracker from a log file.

Baseline: the Log facade

By default, Laravel's exception handler writes unhandled exceptions to the configured log channel. Look in storage/logs/laravel.log or your configured driver (daily, papertrail, syslog, custom).

config/logging.phpphp
'stack' => [
    'driver' => 'stack',
    'channels' => ['daily', 'errorlog'],
    'ignore_exceptions' => false,
],

'daily' => [
    'driver' => 'daily',
    'path' => storage_path('logs/laravel.log'),
    'level' => 'error',
    'days' => 14,
],

This catches everything. Missing: grouping, trending, and anything that looks like a UI. Good enough for a side project, not for production.

Fan out with the Exceptions handler

In Laravel 11+, register reporters in bootstrap/app.php:

bootstrap/app.phpphp
use App\Exceptions\CouponExpiredException;
use App\Exceptions\CustomBusinessException;
use Illuminate\Foundation\Configuration\Exceptions;

->withExceptions(function (Exceptions $exceptions) {
    // Add deploy version to every logged exception
    $exceptions->context(fn () => [
        'release' => config('app.release_sha'),
        'node' => gethostname(),
    ]);

    // Skip exceptions you don't care about
    $exceptions->dontReport([
        CouponExpiredException::class,
    ]);

    // Route custom exceptions to your tracker
    $exceptions->report(function (CustomBusinessException $e) {
        app('tracker')->capture($e, [
            'order_id' => $e->orderId,
            'severity' => 'business',
        ]);
    });
})

Enrich exceptions with user context

An exception stack without the user who hit it is half-useful. Nightwatch, which NightOwl reads, attaches the authenticated user to every exception it captures during a request, with no middleware needed. It stores the user's ID, name and username (by default the name and email columns). To choose what fills name and username, register a resolver once in AppServiceProvider::boot():

app/Providers/AppServiceProvider.phpphp
use Laravel\Nightwatch\Facades\Nightwatch;

public function boot(): void
{
    Nightwatch::user(fn ($user) => [
        'name' => $user->name,
        'username' => $user->email,
    ]);
}

Fingerprint and group

A busy production app can throw thousands of exceptions a day, and most are repeats of a few bugs. Fingerprinting rolls the repeats into one issue each.

A good fingerprint uses:

  • Exception class (QueryException)
  • The top app-level stack frame (skip vendor frames)
  • In some trackers, a normalized message (dynamic values like IDs, emails and timestamps stripped)

Every production-grade tracker (NightOwl, Nightwatch Cloud, Sentry, Bugsnag, Flare, Rollbar) does this automatically; with raw logs you're grouping by hand with grep. NightOwl hashes the class, the exception code, and the file and line of the first non-vendor frame, separately per environment. The message isn't part of the fingerprint, so IDs or emails in it never split a group.

Silence the noise at the source

Laravel already keeps the most common noise out of reports. Its internal don't-report list covers HttpException (so 404s and 405s), ValidationException, AuthenticationException, AuthorizationException, TokenMismatchException (CSRF), ModelNotFoundException and HttpResponseException. What's left to suppress before it hits your tracker (to avoid billing costs and UI clutter) is your own expected exceptions:

php
use App\Exceptions\CouponExpiredException;
use App\Exceptions\PaymentDeclinedException;

$exceptions->dontReport([
    CouponExpiredException::class,   // expected, already shown to the user
]);

$exceptions->dontReportWhen(
    fn (Throwable $e) => $e instanceof PaymentDeclinedException && $e->declinedByBank
);

Alert on signal, not noise

Page on grouped signal, not per-occurrence. The alert matrix that works for most teams:

  • First seen: any new fingerprint appearing in the last hour
  • Spike: existing fingerprint's rate jumps 10x over baseline
  • Threshold: more than N of fingerprint X in 15 minutes, where X is in a critical path
  • Regression: fingerprint that was resolved reappears after a deploy

NightOwl covers first seen and regression: issue.new fires for a new fingerprint, and issue.reopened fires when a resolved issue occurs again.

Send all alerts to a Slack or Discord channel. Email is fine as a low-urgency fallback; never page on email.

Every exception grouped into an issue you can triage

NightOwl fingerprints each reported exception, unhandled or passed to report(), and groups repeats into one issue with its stack trace and the request, job or command it came from. Give it a status, priority and assignee, and get an alert when a new issue appears or a resolved one returns.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

How do I track exceptions in a Laravel app?

Three options from cheapest to best: (1) Laravel's built-in log channel captures stack traces to disk or an external log aggregator, (2) report() callbacks in bootstrap/app.php let you fan out to multiple destinations, (3) an exception tracker or APM (NightOwl, Nightwatch Cloud, Flare, Sentry, Bugsnag, Inspector) that groups exceptions by fingerprint with trends and alerting.

What's exception fingerprinting?

Fingerprinting turns an exception into a stable identifier based on its class and the most relevant stack frames. Some trackers also use a normalized message; NightOwl (through Nightwatch) hashes the class, the exception code, and the file and line of the first non-vendor frame, and ignores the message. Ten thousand occurrences of QueryException: Deadlock on orders table share one fingerprint and roll up into a single issue with a count and first/last-seen timestamps, instead of ten thousand separate notifications.

Should I use Laravel's Log facade or a dedicated exception tracker?

Logs are a baseline, not a monitoring system. Writing exceptions to a log file solves nothing if nobody reads the file. Keep the logs, and add a tracker that groups exceptions, shows their trend and alerts you.

How do I suppress noisy exceptions in Laravel?

In bootstrap/app.php, use $exceptions->dontReport([YourExpectedException::class]) for whole classes or $exceptions->dontReportWhen(fn ($e) => ...) for a condition. Laravel already skips HTTP exceptions (including 404 and 405), validation, authentication and authorization failures, CSRF token mismatches and HttpResponseException, so you don't need to list those. Suppress at the source. Filtering noise in the tracker costs more (per-event billing) and clutters the UI.

How do I add user context to Laravel exceptions?

Use $exceptions->context() in bootstrap/app.php to attach global context (app version, deploy SHA), or give your own exception class a context() method for per-exception data. For user context, most trackers offer a setUser() call. With Nightwatch (which NightOwl reads) the authenticated user is attached automatically, and Nightwatch::user() in AppServiceProvider::boot() chooses the name and username stored with the ID.

What exceptions should I alert on?

Not individual exceptions, but grouped ones. Configure per-class thresholds: spike detection (suddenly 100x more of a fingerprint), first-seen (new fingerprint in the last hour), and priority (exceptions in critical paths like payments). Throttle alerts so a high-volume exception doesn't page you 10,000 times. NightOwl alerts on first-seen fingerprints and on resolved issues that come back; spike and count thresholds need a separate rate check.

Can I keep exception data in my own database?

Yes. Sentry (under its FSL license) can run on your own servers, but it is heavy (about 50 containers, or 28 in errors-only mode, and 16GB+ RAM). Laravel Telescope is free and stores entries in your app's database, but it is not production-grade. NightOwl uses a BYOD model: your PostgreSQL stores the exception data, the NightOwl agent on your server groups exceptions and sends new-issue alerts, and NightOwl hosts the dashboard.

Related

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial