PHPackages                             webparking/laravel-sentry-throttling - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. webparking/laravel-sentry-throttling

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

webparking/laravel-sentry-throttling
====================================

Throttle exceptions before they are sent to Sentry, tagging survivors with their occurrence count.

v1.0.0(1mo ago)0349↓42.9%MITPHPPHP ^8.1CI passing

Since Jul 2Pushed 1mo agoCompare

[ Source](https://github.com/webparking/laravel-sentry-throttling)[ Packagist](https://packagist.org/packages/webparking/laravel-sentry-throttling)[ RSS](/packages/webparking-laravel-sentry-throttling/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Throttle exceptions being sent to Sentry
========================================

[](#throttle-exceptions-being-sent-to-sentry)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0b844f4b64cbc3c856a5e2fe96ed98cf13dd90c63fc488c08d0f6fd1f49bf788/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765627061726b696e672f6c61726176656c2d73656e7472792d7468726f74746c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webparking/laravel-sentry-throttling)[![Total Downloads](https://camo.githubusercontent.com/218b08611d15940b9ff367ed093f75368689037b8281804a80ba207d18d183d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765627061726b696e672f6c61726176656c2d73656e7472792d7468726f74746c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webparking/laravel-sentry-throttling)[![run-tests](https://github.com/webparking/laravel-sentry-throttling/actions/workflows/run-tests.yml/badge.svg)](https://github.com/webparking/laravel-sentry-throttling/actions/workflows/run-tests.yml)

Laravel has a built-in mechanism for throttling exceptions, but it can't define throttling rules per reportable. This package throttles exceptions **specifically before they are sent to Sentry**, so you can keep logging everything locally while avoiding repeated reports of the same exception in Sentry.

Compared to Sentry's own percentage-based `sample_rate`, this is exception-specific. On top of that, every event that survives a throttle, whether rate-limited or sampled, is tagged so you don't lose sight of how noisy it really was:

- **`throttled` = `true`**: the event passed through a throttle.
- **`throttle_occurrences` = ``**: how many matching exceptions occurred (dropped *and* sent) since the previous event of this kind was reported.

Because those tags are indexed by Sentry, you can search and alert on them (e.g. `throttled:true`, or sort by `throttle_occurrences`).

Installation
------------

[](#installation)

Install via composer:

```
composer require webparking/laravel-sentry-throttling
```

The package registers itself as `sentry.before_send` automatically, **but only if your project hasn't already configured one**, so it never silently clobbers an existing callback. You do not need to touch `config/sentry.php` unless one of the cases below applies.

### If you already have a `before_send`

[](#if-you-already-have-a-before_send)

Auto-registration backs off when `sentry.before_send` is already set. Call the throttle from within your own callback to keep both behaviors:

```
// config/sentry.php
use Webparking\SentryThrottling\SentryThrottling;

return [
    // ...existing config...
    'before_send' => function (\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event {
        $event = SentryThrottling::beforeSend($event, $hint);

        // Your own logic; $event is null when the throttle dropped the event.
        return $event;
    },
];
```

### Registering it explicitly

[](#registering-it-explicitly)

If you prefer to be explicit rather than rely on auto-registration:

```
// config/sentry.php
return [
    // ...existing config...
    'before_send' => [\Webparking\SentryThrottling\SentryThrottling::class, 'beforeSend'],
];
```

Usage
-----

[](#usage)

Implement the `ThrottlesSentryReports` interface in a class of your own. For each exception it returns a `Limit` (rate-limit), a `Lottery` (probabilistic sample), or `null` to let the exception through untouched (`Limit::none()` does the same). Both a rate-limited survivor and a sampled survivor are tagged with `throttled` and `throttle_occurrences`.

```
