PHPackages                             genai/trace - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. genai/trace

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

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.

v1.0.1(1mo ago)0163↓14.6%Apache-2.0PHPPHP &gt;=5.3.0CI passing

Since Jul 3Pushed 1mo agoCompare

[ Source](https://github.com/GenAIIO/php-trace)[ Packagist](https://packagist.org/packages/genai/trace)[ RSS](/packages/genai-trace/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

genai/trace
===========

[](#genaitrace)

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
------------

[](#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
------

[](#use-it)

1. `composer require genai/trace` — **that'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
-----

[](#notes)

- **Propagation**: when calling other services, forward the header (`X-Request-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.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

2

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25e5bd31b5dd70d47cbdc738bded06dbabfba3d584acce63c2c4b4fb7847f39d?d=identicon)[jinnguyen](/maintainers/jinnguyen)

---

Top Contributors

[![linhnnmt](https://avatars.githubusercontent.com/u/162856460?v=4)](https://github.com/linhnnmt "linhnnmt (7 commits)")

### Embed Badge

![Health badge](/badges/genai-trace/health.svg)

```
[![Health](https://phpackages.com/badges/genai-trace/health.svg)](https://phpackages.com/packages/genai-trace)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B12.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

2144.7M354](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2430.8M445](/packages/open-telemetry-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
