d076/laravel-tracing 问题修复 & 功能扩展

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

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

d076/laravel-tracing

最新稳定版本:v0.2.4

Composer 安装命令:

composer require d076/laravel-tracing

包简介

Tracing module for laravel

README 文档

README

Tests PHP Laravel License

A Laravel package for tracing inbound and outbound HTTP requests. Each inbound request gets a unique X-Trace-Id (UUID7); every outbound request made via the Http facade, plus any jobs and events dispatched from that request, automatically inherit the same trace_id.

Optionally ships a web UI at /tracing for browsing recorded requests.

Requirements

  • PHP 8.3+
  • Laravel 11 / 12 / 13
  • Database: PostgreSQL / MySQL / SQLite

Installation

composer require d076/laravel-tracing

Register the service provider in bootstrap/providers.php:

return [
    App\Providers\AppServiceProvider::class,
    D076\Tracing\Providers\TracingServiceProvider::class,
];

Run migrations:

php artisan migrate

Publish the config (optional):

php artisan vendor:publish --tag=tracing-config

Quick start

Works out of the box with sensible defaults:

  • synchronous recording of inbound and outbound requests to the database;
  • masking for common secrets (password, token, authorization, access_token, etc.);
  • X-Trace-Id header on every response;
  • UI at /tracing, accessible only in the local environment by default;
  • API rate limit of 120 req/min.

Key switches:

Variable Default Purpose
TRACING_ENABLED true Record inbound requests
TRACING_OUTGOING_ENABLED true Record outbound requests
TRACING_DRIVER database database (sync) or queue (async via Horizon)
TRACING_UI_ENABLED true Web UI
TRACING_RETENTION_DAYS 30 Retention in days; cleaned via php artisan model:prune

See docs/configuration.md for the full reference.

UI authorization

By default /tracing is accessible only in the local environment. In production, override the gate in AppServiceProvider::boot():

use Illuminate\Support\Facades\Gate;

Gate::define('viewTracing', fn ($user) => $user?->isAdmin() ?? false);

Using trace_id in your code

use D076\Tracing\Context\TraceId;

Log::info('processing order', ['trace_id' => app(TraceId::class)->get()]);

Queued jobs require no setup — trace_id is automatically inherited from the parent HTTP request (see docs/configuration.md → trace_id propagation to jobs).

Performance overhead

Measured with phpbench on a minimal testbench app, SQLite in-memory, no opcache (Docker, PHP 8.4):

Mode Overhead per request
Baseline (tracing disabled)
TRACING_DRIVER=database ~+0.17 ms
TRACING_DRIVER=database + TRACING_STORE_RESPONSE_BODY=true ~+0.21 ms
TRACING_DRIVER=queue (sync driver, worst case) ~+0.31 ms

With a real async queue (Redis + Horizon), the main-request overhead for TRACING_DRIVER=queue drops to near zero — only job dispatch cost, while the actual DB write happens in the worker.

Use TRACING_DRIVER=queue if latency matters; use a separate database connection if I/O isolation matters.

Documentation

  • Architecture — package components, lifecycle of inbound and outbound requests.
  • Configuration — full env reference, masking, rate limiting, async mode, route exclusions, trace_id propagation to jobs, UI authorization.
  • Database — what is stored, table schemas, example SQL queries.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固