esign/laravel-sentry-throttling
Composer 安装命令:
composer require esign/laravel-sentry-throttling
包简介
Throttle exceptions being sent to Sentry
关键字:
README 文档
README
Laravel includes a built-in mechanism for throttling exceptions, but it doesn’t support defining throttling rules for individual reportables. This package adds the ability to throttle exceptions specifically before they are sent to Sentry. It's especially useful if you want to continue logging all exceptions locally while avoiding repeated reports of the same exception being sent to Sentry. While Sentry does offer its own sampling via the sample_rate setting, that approach is percentage-based and less granular than exception-specific throttling.
Installation
You can install the package via composer:
composer require esign/laravel-sentry-throttling
You must configure the before_send option in your config/sentry.php file so that Sentry uses the throttling logic.
Add the following to your Sentry config:
// config/sentry.php return [ // ...existing config... 'before_send' => [\Esign\SentryThrottling\SentryThrottling::class, 'beforeSend'], ];
Usage
Implementing throttling
For Laravel 11+ (slim skeleton)
For newer Laravel applications that don't ship with a default exception handler, create a dedicated class that implements the ThrottlesSentryReports interface:
<?php namespace App\Exceptions; use Esign\SentryThrottling\Contracts\ThrottlesSentryReports; use Illuminate\Broadcasting\BroadcastException; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Support\Lottery; use Throwable; class SentryThrottleHandler implements ThrottlesSentryReports { public function throttleSentry(Throwable $exception): Lottery | Limit | null { return match (true) { $exception instanceof BroadcastException => Limit::perMinute(300), default => Limit::none(), }; } }
For Laravel 10 and earlier
If your application has a default exception handler (typically App\Exceptions\Handler), you can implement the ThrottlesSentryReports interface directly on it:
use App\Exceptions\ApiMonitoringException; use Illuminate\Broadcasting\BroadcastException; use Esign\SentryThrottling\Contracts\ThrottlesSentryReports; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Support\Lottery; use Throwable; class Handler extends ExceptionHandler implements ThrottlesSentryReports { public function throttleSentry(Throwable $exception): Lottery | Limit | null { return match (true) { $exception instanceof BroadcastException => Limit::perMinute(300), $exception instanceof ApiMonitoringException => Lottery::odds(1, 1000), default => Limit::none(), }; } }
Binding the interface
You must bind your implementation of ThrottlesSentryReports in the Laravel container so the package can resolve it. This is typically done in a service provider, such as App\Providers\AppServiceProvider:
For Laravel 11+ (using dedicated class):
use Esign\SentryThrottling\Contracts\ThrottlesSentryReports; use App\Exceptions\SentryThrottleHandler; class AppServiceProvider extends ServiceProvider { public function register(): void { $this->app->bind(ThrottlesSentryReports::class, SentryThrottleHandler::class); } }
For Laravel 10 and earlier (using exception handler):
use Esign\SentryThrottling\Contracts\ThrottlesSentryReports; use App\Exceptions\Handler; class AppServiceProvider extends ServiceProvider { public function register(): void { $this->app->bind(ThrottlesSentryReports::class, Handler::class); } }
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
esign/laravel-sentry-throttling 适用场景与选型建议
esign/laravel-sentry-throttling 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.18k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「esign」 「sentry-throttling」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 esign/laravel-sentry-throttling 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 esign/laravel-sentry-throttling 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 esign/laravel-sentry-throttling 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A laravel package to make your eloquent models translatable.
Manage SEO tags within your Laravel application
Load translations from the database or other sources.
Associate files with your Laravel Models
Generate slugs when saving UnderscoreTranslatable models
A Laravel SDK for the Plytix API
统计信息
- 总下载量: 6.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-14