zing / laravel-sentry
提供 Sentry 上下文中间件。
3.3.0
2024-03-18 15:03 UTC
Requires
- php: ^8.0
- illuminate/container: ^8.0 || ^9.0 || ^10.0 || ^11.0
- sentry/sentry-laravel: ^2.3.1 || ^3.0.0 || ^4.0.0
Requires (Dev)
- mockery/mockery: ~1.3.3 || ^1.4.2
- nunomaduro/larastan: ^1.0 || ^2.0
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpstan/phpstan-mockery: ^1.0
- phpunit/phpunit: ^9.3.3 || ^10.0
- zing/coding-standard: ^6.4 || ^7.0
README
要求
使用 Composer 安装 Laravel Sentry Composer
composer require zing/laravel-sentry
用法
添加用户上下文
use Zing\LaravelSentry\Middleware\SentryContext; use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { protected $middleware = [ // ... SentryContext::class, ]; // ... }
自定义用户上下文
use Zing\LaravelSentry\Middleware\SentryContext; class CustomSentryContext extends SentryContext { /** * @param \Zing\LaravelSentry\Tests\User $user * * @return array<string, mixed>|mixed[] */ protected function resolveUserContext(string $guard, \Illuminate\Contracts\Auth\Authenticatable $user): array { if ($guard === 'api') { return [ 'id' => $user->getAuthIdentifier(), 'username' => $user->username, ]; } return parent::resolveUserContext($guard, $user); } }
许可协议
Laravel Sentry 是一个开源软件,遵循 MIT 许可协议。