genai/trace
Composer 安装命令:
composer require genai/trace
包简介
Request correlation IDs for centralized logging. A TraceInterceptor reads X-Request-Id (or generates one), exposes it via a TraceContext bean + a global trace_id(), echoes it on the response, and a Monolog processor stamps it on every log line. PHP 5.3-safe at runtime.
README 文档
README
Request correlation IDs for centralized logging. Each request gets a trace id (read from the inbound header or generated), threaded through the request and stamped on every log line — so you can grep one id and see the whole request's journey across services. PHP 5.3.29-safe at runtime.
How it works
TraceInterceptor(outermost) readsX-Request-Idfrom the request (set by an upstream gateway/service), or generates a 128-bit hex id when absent; stores it onTraceContext; and echoes it on the response.TraceContextholds the id for the request (a container singleton) and is also exposed statically, so:- the global
trace_id()helper works in templates/error pages, and - the Monolog
TraceProcessorcan read it without DI.
- the global
- Downstream calls should forward the same header to continue the chain.
Use it
-
composer require genai/trace— that's it. TheTraceInterceptoris self-enabling: it carries#[Intercept(order: -30)]and lives in a scanned bundle namespace, so installing the package turns it on (no app wiring). Every response now getsX-Request-Idandtrace_id()works. -
Stamp it on your logs (Monolog):
$logger->pushProcessor(new \GenAI\Trace\Monolog\TraceProcessor()); // every record now carries extra.trace_id
-
Optional config (
app.ini):[trace] header = X-Request-Id ; the correlation header (default)
Now every response has X-Request-Id, every log line has extra.trace_id, and
trace_id() is available anywhere (e.g. show it on a 500 page as a support ref).
Notes
- Propagation: when calling other services, forward the header
(
X-Request-Id: <trace_id()>) so they log under the same id. - Header: defaults to
X-Request-Id(simple correlation). Point it attraceparentif you adopt W3C Trace Context later. - Decoupled:
monologis asuggest— the core (context + interceptor) works without it; the processor only references plain arrays.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-07-10