noartem/laravel-wide-events 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

noartem/laravel-wide-events

最新稳定版本:v0.0.1

Composer 安装命令:

composer require noartem/laravel-wide-events

包简介

Wide Events for Laravel.

README 文档

README

This package implements wide events: build one structured event per request, enrich it throughout the request lifecycle, then emit once at the end with tail sampling.

More about wide events and why traditional logging suck you can find out at loggingsucks.com.

Quick start

  1. Install package
composer require noartem/laravel-wide-events
php artisan vendor:publish --tag=wide-events-config
  1. Register middleware (early in the stack)
// bootstrap/app.php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(\Noartem\LaravelWideEvents\Http\Middleware\InitWideEvent::class);
        // ... other middlewares
    })
    ->create();

If you are still using app/Http/Kernel.php, add the middleware to $middleware there instead.

  1. Enrich anywhere in code
use Illuminate\Support\Facades\Log;

Log::wideEvent('user.id', auth()->id());
Log::wideEvent('cart.total_cents', 12345);
  1. Customize sampling
// config/wide-events.php
'sampler' => App\Logging\CustomWideEventSampler::class,

Your class must implement WideEventSampler. Or extend default implementation: DefaultWideEventSampler. More examples of samplers in examples/.

Custom collectors

Register extra collectors in config:

// config/wide-events.php
'collectors' => [
    App\Logging\CheckoutCollector::class,
],

A collector should extend the base class and map events to handlers:

use Noartem\LaravelWideEvents\Collectors\BaseCollector;
use Illuminate\Routing\Events\RouteMatched;

final class CheckoutCollector extends BaseCollector
{
    public function events(): array
    {
        return [RouteMatched::class => 'onRoute'];
    }

    public function onRoute(RouteMatched $event): void
    {
        $this->put('route.name', $event->route->getName());
    }
}

Default sampling behavior

By default the sampler keeps:

  • all requests with exceptions or 5xx
  • requests slower than the configured percentile of recent durations
  • a deterministic sample of the rest

Sanitization

Redaction is applied by key and value patterns. Update wide-events.redaction in the config to add your own key names or regexes for sensitive values (Stripe, GitHub, JWT, etc).

Output format

A single log record:

  • message: wide_event (configurable)
  • context: the wide event payload (array)

Use a JSON formatter on the chosen channel for best results.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-31