定制 genai/trace 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

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) reads X-Request-Id from the request (set by an upstream gateway/service), or generates a 128-bit hex id when absent; stores it on TraceContext; and echoes it on the response.
  • TraceContext holds 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 TraceProcessor can read it without DI.
  • Downstream calls should forward the same header to continue the chain.

Use it

  1. composer require genai/tracethat's it. The TraceInterceptor is 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 gets X-Request-Id and trace_id() works.

  2. Stamp it on your logs (Monolog):

    $logger->pushProcessor(new \GenAI\Trace\Monolog\TraceProcessor());
    // every record now carries extra.trace_id
  3. 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 at traceparent if you adopt W3C Trace Context later.
  • Decoupled: monolog is a suggest — the core (context + interceptor) works without it; the processor only references plain arrays.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固