PHPackages                             mxnwire/laravel-request-id - 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. mxnwire/laravel-request-id

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

mxnwire/laravel-request-id
==========================

Propagate request, session and correlation IDs across requests, responses and log records

1.2.0(1mo ago)01MITPHPPHP ^8.1

Since Jun 14Pushed 1mo agoCompare

[ Source](https://github.com/mhxnahid/laravel-request-id)[ Packagist](https://packagist.org/packages/mxnwire/laravel-request-id)[ RSS](/packages/mxnwire-laravel-request-id/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Laravel Request ID
==================

[](#laravel-request-id)

Propagate request, session and correlation IDs across the request lifecycle: read them from incoming headers, echo them on the response, and attach them (plus the authenticated user) to every log record.

- `X-Request-Id` — taken from the incoming header or generated as a UUID v4.
- `X-Session-Id` / `X-Correlation-Id` — propagated from upstream only; left null when absent.

Only valid UUID v4 values are accepted from upstream; anything else is treated as absent (and regenerated for `request_id`).

Installation
------------

[](#installation)

```
composer require mxnwire/laravel-request-id
```

The service provider is auto-discovered. By default the middleware is prepended to the global HTTP stack, so every request is covered with no further setup.

Configuration
-------------

[](#configuration)

Publish the config to customise behaviour:

```
php artisan vendor:publish --tag=request-id-config
```

Key options in `config/request-id.php`:

- `enabled` — master switch; when false the middleware passes requests through untouched.
- `register_global_middleware` — when false, register manually with the `request-id` alias instead of the global stack.
- `headers` — the incoming/outgoing header name for each ID.
- `generate` — which IDs are generated as a UUID v4 when missing (default: `request_id` only).
- `attributes` — the `$request->attributes` keys the IDs are stored under.
- `log` — master switch for attaching the IDs (and user) to log records; when false they are still resolved and echoed on the response, but nothing is pushed to the log.
- `log_destination` — where the fields are placed on each record: `'context'` (default) or `'extra'`. See [Logging](#logging).
- `log_channels` — extra log channels to attach the processor to (the default driver is always covered).
- `log_user` / `user_fields` — attach authenticated-user fields to each log record; each field is a model attribute name or a callable receiving the user.

### Manual middleware registration

[](#manual-middleware-registration)

Set `register_global_middleware` to `false`, then apply the alias where needed:

```
Route::middleware('request-id')->group(function () {
    // ...
});
```

Reading the IDs
---------------

[](#reading-the-ids)

```
$requestId = $request->attributes->get('x_request_id');
```

Logging
-------

[](#logging)

When `log` is enabled the IDs (and, when `log_user` is on, the authenticated-user fields) are attached to every log record by a Monolog processor. The processor is always pushed to the default log driver, plus any channels listed in `log_channels`.

Where the fields land on the record is controlled by `log_destination`:

- `'context'` (default) — merged flat into the record's context. Reads best with the `LineFormatter`, where it produces a single `{...}` block, and collapses onto any matching keys already in context (e.g. `user_id`).
- `'extra'` — kept in Monolog's `extra` bucket. With the `LineFormatter` this shows as a second trailing `{...}` block, but with a JSON formatter it becomes a clean, separate `extra` object.

### JSON log channel (preferred)

[](#json-log-channel-preferred)

For anything beyond local debugging, **a JSON-formatted channel paired with `log_destination => 'extra'` is the recommended setup.** It keeps the tracing metadata in its own namespace, cleanly separated from the request payload and trivially queryable by your log aggregator:

```
{
  "message": "http_request",
  "context": { "method": "GET", "url": "...", "status": 200 },
  "extra":   { "request_id": "d0cee2c7-...", "session_id": null, "user_id": 1 }
}
```

Point a channel at Monolog's `JsonFormatter` in `config/logging.php`:

```
use Monolog\Formatter\JsonFormatter;

'requests' => [
    'driver'    => 'daily',
    'path'      => storage_path('logs/requests.log'),
    'formatter' => JsonFormatter::class,
    'days'      => 14,
],
```

then set `log_destination => 'extra'` and add the channel to `log_channels` so the processor is attached to it.

With a plain `LineFormatter` (e.g. the stock `single`/`daily` channels), leave `log_destination` as `'context'` so the IDs read as part of the main entry.

Testing
-------

[](#testing)

```
composer install
composer test
```

License
-------

[](#license)

MIT

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

46d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/45322767?v=4)[mhxnahid](/maintainers/mhxnahid)[@mhxnahid](https://github.com/mhxnahid)

---

Top Contributors

[![mhxnahid](https://avatars.githubusercontent.com/u/45322767?v=4)](https://github.com/mhxnahid "mhxnahid (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mxnwire-laravel-request-id/health.svg)

```
[![Health](https://phpackages.com/badges/mxnwire-laravel-request-id/health.svg)](https://phpackages.com/packages/mxnwire-laravel-request-id)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M348](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)

PHPackages © 2026

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