Library / SDK
getsentry/sentry-laravel avatar
getsentry/sentry-laravel

sentry-laravel: Installation and Setup for Laravel Error Reporting

The official Laravel SDK for Sentry (sentry.io)

1,350 stars216 forksPHPMIT

At a glance

What is it?
sentry-laravel connects Laravel and Lumen applications to Sentry for unhandled exception reporting and optional log-channel capture. The documented installation targets Laravel 11.x and 12.x, while older framework releases require version-specific SDK branches.
Who is it for?
Adopt sentry-laravel when an application runs a supported Laravel or Lumen version and needs Sentry-based exception or log reporting. Do not adopt it without checking framework and PHP compatibility, reviewing the generated config/sentry.php file, and confirming how captured logs fit your alerting and retention requirements.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Where sentry-laravel Fits in a Laravel Application

sentry-laravel is the official Laravel SDK for Sentry. It addresses a specific operational problem: collecting application errors in a central service so developers can inspect them after a request has failed. It is intended for teams operating PHP applications with Laravel, and the README also provides separate compatibility documentation for Lumen. The package can report unhandled exceptions handled by Laravel's exception integration and can capture `info` and `debug` records when configured as a Laravel log channel.

This is not a general-purpose logging replacement. Laravel logging remains part of the application, while the package adds a Sentry integration and exposes the Sentry PHP API. The documented installation path is intentionally narrow: the current getting-started instructions cover Laravel 12.x and 11.x. Applications using older Laravel releases must follow the linked guides, because the SDK branch and PHP requirements vary by framework generation.

The SDK also creates a vendor relationship with Sentry. A team choosing it is choosing a hosted error-monitoring service as well as a PHP package. Organizations that need all logs to remain in local files or another backend, or that cannot send application data to Sentry.io, should treat that service boundary as part of the adoption decision.

Composer Installation and Laravel Exception Registration

Install the package through Composer. The README gives this as the first step, and it leaves version selection to Composer's dependency resolution rather than prescribing a package version in the command.

bash
composer require sentry/sentry-laravel

After installation, Laravel 11.x and 12.x applications register the SDK's exception integration in `bootstrap/app.php`. The documented change calls `Integration::handles($exceptions)` from the framework's `withExceptions` callback. This is the connection point between Laravel's exception handling and Sentry's reporting path.

php
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Sentry\Laravel\Integration;

The callback is added to the existing application configuration rather than replacing routing or middleware behavior. Keep the rest of the Laravel bootstrap configuration intact and add the import and exception callback in the locations shown by the project documentation. The README does not claim that Composer installation alone enables reporting, which is why this bootstrap change is a separate required step for the documented setup.

Publishing the DSN into Laravel Environment Configuration

Sentry needs a DSN before it can report events to the intended Sentry project. The documented Artisan command creates `config/sentry.php` and adds the DSN to the Laravel environment file:

shell
php artisan sentry:publish --dsn=___PUBLIC_DSN___

Replace the placeholder with the public DSN supplied for the Sentry project, without committing the real value to source control. The command writes the following environment variable according to the README:

shell
SENTRY_LARAVEL_DSN=___PUBLIC_DSN___

This gives the SDK a project-specific destination while leaving the detailed integration behavior in the published PHP configuration. Because `config/sentry.php` is generated, it also becomes the first file to inspect when deciding which framework events, logs, or integrations belong in a deployment. The README does not describe a separate configuration file for each environment, nor does it document an interactive setup wizard beyond this publish command. Teams with separate development, staging, and production projects must ensure the corresponding environment values are supplied by their deployment configuration.

Reporting a Caught Exception through the PHP API

Not every failure should have to reach Laravel's unhandled exception path. The README documents direct capture with `Sentry\captureException`, which is useful when application code catches a `Throwable` and still wants to send it to Sentry. The catch block should preserve the original exception object because that is the value passed to the API.

php
use function Sentry\captureException;

try {
    $this->functionThatMayFail();
} catch (\Throwable $exception) {
    captureException($exception);
}

This example is deliberately simple. `functionThatMayFail()` stands in for application logic; the project-specific part is the call to `captureException($exception)` inside the catch block. A team can place that call around an operation whose exception it wants to report explicitly, but the README does not prescribe filtering, deduplication, sampling, or custom event processing in this usage example.

The two documented paths therefore have different roles. `Integration::handles($exceptions)` gives the SDK a place in Laravel's exception handling flow, while `captureException()` reports an exception already caught by application code. Adding both does not, by itself, prove that every possible failure will be reported once. Business-level retry policies and duplicate-report handling still belong in application review.

Laravel Log Channels for Info and Debug Events

The README offers an alternative configuration path through Sentry as a Laravel log channel. This changes the scope from exception reporting to log ingestion and specifically states that the channel can capture `info` and `debug` logs as well. It is relevant for teams that already control Laravel logging through `config/logging.php` and want selected records routed to Sentry.

The README links to the Sentry Laravel usage documentation for the channel configuration but does not include the channel snippet. This review therefore cannot confirm the exact channel class, environment keys, or syntax from the repository excerpt. Those details must be taken from the linked Sentry documentation and checked against the Laravel version being used.

This route also creates a data-volume decision. The README mentions `info` and `debug` specifically, but it does not state their retention, sampling, filtering, or pricing behavior. Sending verbose debug records can increase event volume compared with reporting exceptions alone. Since the repository does not define those controls, application owners should first confirm which log levels they want to forward and how they want noisy or sensitive records filtered.

Framework and PHP Compatibility Boundaries

Compatibility is the main constraint for this package. The README says the getting-started steps target Laravel 12.x and 11.x. Its compatibility table gives several supported ranges, including Laravel `>= 11.x.x` on PHP `>= 8.2` starting with SDK version `4.3.0`, and Laravel `>= 10.x.x` on PHP `>= 8.1` starting with version `3.2.0`. The table also lists support ranges for Laravel 9.x through 6.x with their corresponding PHP requirements.

For an application on Laravel 10.x, the project points to a separate guide rather than suggesting that the newest documented bootstrap file can be copied unchanged. Laravel 9.x through 4.x and Lumen each have their own documentation paths. The SDK also states that version `>= 2.0.0` requires PHP `>= 7.2` because it uses the new Sentry PHP SDK underneath.

This makes the package a poor fit for an unmaintained application whose framework or runtime version cannot be mapped to the compatibility table. It is also worth distinguishing framework support from operational requirements. The repository is not archived, and its last push was on 2026-10-08. Recent releases include `4.29.0` on 2026-10-08, `4.28.0` on 2026-09-23, and `4.27.0` on 2026-07-15. That history supports evaluating current releases, but it does not remove the need to check the SDK version selected by Composer.

MIT Licensing and Repository-Level Upgrade Work

The project is licensed under the MIT license, and the repository includes a `LICENSE` file. That license information identifies the package's stated licensing model, but it does not by itself describe Sentry service pricing, data-processing terms, privacy obligations, or every dependency's license. Those are separate concerns when adopting a hosted monitoring integration.

The repository layout includes `composer.json`, `composer.lock`, `config/`, `src/`, `test/`, static-analysis configuration, and a `Makefile`. The Makefile exposes development and validation commands through Composer, including `composer phpcs`, `composer phpstan` through the `phpstan` target, and `composer tests` through the `tests` target. These are repository maintenance commands, not commands shown as an application installation tutorial.

Upgrading a consuming application will normally require Composer to resolve a new package release, followed by review of the Laravel bootstrap integration and generated Sentry configuration. The README does not document a rollback procedure or a framework-specific migration checklist. For that reason, an upgrade should be assessed against `CHANGELOG.md`, the selected SDK release, and the compatibility table rather than treated as a version-number-only change.

When sentry-laravel Is the Wrong Integration

sentry-laravel is a poor choice when the application does not use a supported Laravel or Lumen environment. It is also the wrong tool for a team that only needs a local PHP error log or wants to avoid sending data to Sentry.io. The package is an integration for Sentry, not a framework-independent error collector for arbitrary PHP applications.

A Laravel log channel is an alternative path within the same SDK, but it is not a replacement for Sentry when the requirement is broad log search, retention management, or incident workflows outside the package's documented scope. Likewise, direct calls to `captureException()` require application code to catch the relevant `Throwable`. They do not cover failures in code paths that never reach that catch block, and the README gives no guarantee about deduplication between manually captured and unhandled events.

The concrete adoption check is therefore narrow but important: confirm the framework and PHP versions first, then decide whether Sentry is the approved destination for exception data and any selected log levels. If either condition fails, choose an integration aligned with the actual runtime and data policy rather than forcing this Laravel package into the deployment.

Editorial conclusion

Adopt sentry-laravel when an application runs a supported Laravel or Lumen version and needs Sentry-based exception or log reporting. Do not adopt it without checking framework and PHP compatibility, reviewing the generated config/sentry.php file, and confirming how captured logs fit your alerting and retention requirements. For Laravel 11.x and 12.x with PHP 8.2 or newer, version 4.3.0 or later is the documented compatibility line, and the repository's most recent release was 4.29.0 on 2026-10-08.

Frequently asked questions

Which Laravel versions does sentry-laravel support?

The current getting-started instructions cover Laravel 12.x and 11.x. The compatibility table also lists supported ranges for Laravel 10.x through 6.x, each with corresponding PHP and starting SDK version requirements.

How do I install sentry-laravel in a Laravel application?

Run `composer require sentry/sentry-laravel`, then register `Integration::handles($exceptions)` in `bootstrap/app.php` for the documented Laravel 11.x and 12.x setup. Configure the DSN with `php artisan sentry:publish --dsn=___PUBLIC_DSN___`.

Can sentry-laravel capture Laravel logs?

Yes. The README says Sentry can be configured as a Laravel log channel, allowing `info` and `debug` logs to be captured as well as exceptions.

What license does sentry-laravel use?

The repository README identifies the package as licensed under the MIT license and points to the repository's `LICENSE` file.

Official sources

  1. getsentry/sentry-laravel on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/getsentry-sentry-laravel.svg)](https://hysenlabs.com/projects/getsentry-sentry-laravel)

Was this useful?