PHPackages                             tourze/request-id-bundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/request-id-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/request-id-bundle
========================

Request ID Generator for Symfony

1.0.1(5mo ago)123.8k1MITPHPCI passing

Since Apr 10Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/request-id-bundle)[ Packagist](https://packagist.org/packages/tourze/request-id-bundle)[ RSS](/packages/tourze-request-id-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (23)Versions (6)Used By (1)

RequestIdBundle
===============

[](#requestidbundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/e285c503a3717464a2653decb2fa8c8ebac1fcd90b26615a9a7dd982cd54f369/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f726571756573742d69642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/request-id-bundle)[![PHP Version](https://camo.githubusercontent.com/c8362b6e68fd6e4e3954bef02bebe00aa91d151e71effd8c18d7d8b1a6464da2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f726571756573742d69642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/request-id-bundle)[![License](https://camo.githubusercontent.com/070c37bc0efb16edb575850f56d795605597201eee63848964a57e1961eb33df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f726571756573742d69642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/request-id-bundle)[![Build Status](https://camo.githubusercontent.com/871613cbe7543dc597990648ad7a05220ded030cbdf7277985972363430c1c20/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f75727a652f726571756573742d69642d62756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tourze/request-id-bundle)[![Quality Score](https://camo.githubusercontent.com/99391e5876e077546c427fcf57adb47b6114cc6a127ab110bc16a18f912436b1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f726571756573742d69642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/request-id-bundle)[![Code Coverage](https://camo.githubusercontent.com/63266a78acc7e09a92b41b6d510d3fef3971b2e4bc4e3edcdb9782260eb114a4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f726571756573742d69642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/request-id-bundle/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/0d45aa406fa98839e479e9420ca0c22bd4b68c44a5b2562440bfbc688417663e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f726571756573742d69642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/request-id-bundle)

A Symfony bundle for request ID management, enabling tracking and correlation of requests across your application. Supports HTTP, message queue, and CLI commands for comprehensive request tracing in distributed systems.

Features
--------

[](#features)

- Generate unique request IDs using UUID with Base58 encoding (shorter than standard UUID format)
- Coroutine-safe request ID storage with automatic reset mechanism to prevent memory leaks
- Automatically add request ID to HTTP request/response headers
- Propagate request ID in message queues via Symfony Messenger middleware
- Generate request ID for CLI commands with special "CLI" prefix
- Integrate request ID into logs automatically via Monolog processor
- Support distributed system tracing across different services

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

[](#installation)

```
composer require tourze/request-id-bundle
```

**Requirements:**

- PHP &gt;= 8.1
- Symfony &gt;= 6.4
- Symfony components: HTTP Kernel, Messenger, Console, Uid
- Monolog &gt;= 3.1
- See composer.json for complete dependencies

Quick Start
-----------

[](#quick-start)

### 1. HTTP Integration

[](#1-http-integration)

The bundle automatically:

- Checks for request ID in incoming HTTP headers
- Generates new ID if none exists or not trusted
- Sets ID in response headers
- Stores ID in coroutine-safe storage

```
// In your controllers, you can access the request ID:
use RequestIdBundle\Service\RequestIdStorage;

class MyController
{
    public function index(RequestIdStorage $requestIdStorage)
    {
        $currentRequestId = $requestIdStorage->getRequestId();
        // Use the request ID...
    }
}
```

### 2. Message Queue Integration

[](#2-message-queue-integration)

Request IDs are automatically propagated through message queues:

```
// The message will automatically carry the current request ID
$messageBus->dispatch(new MyMessage());

// In message handlers, the original request ID is available:
public function handleMessage(MyMessage $message, RequestIdStorage $requestIdStorage)
{
    $originalRequestId = $requestIdStorage->getRequestId();
    // Process with original request context...
}
```

### 3. CLI Support

[](#3-cli-support)

CLI commands automatically get request IDs with a "CLI" prefix:

```
$ php bin/console my:command
# A request ID like "CLIxxxxx" will be generated automatically
```

```
// In your commands:
use RequestIdBundle\Service\RequestIdStorage;

class MyCommand extends Command
{
    private RequestIdStorage $requestIdStorage;

    public function __construct(RequestIdStorage $requestIdStorage)
    {
        $this->requestIdStorage = $requestIdStorage;
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $commandRequestId = $this->requestIdStorage->getRequestId(); // CLI[uuid]
        // Use request ID...
    }
}
```

### 4. Log Integration

[](#4-log-integration)

Request IDs are automatically added to log records:

```
$logger->info('Processing user request', ['user_id' => 123]);
// Log output will include "request_id": "7fT9P5RoJ3a..."
```

How It Works
------------

[](#how-it-works)

For a detailed workflow diagram, see [WORKFLOW.md](WORKFLOW.md).

1. **HTTP Requests:**

    - `RequestIdSubscriber` handles request/response events
    - Checks if request ID exists in headers
    - Uses existing ID if trusted, otherwise generates new one
    - Adds ID to response headers
2. **Message Queue:**

    - `RequestIdMiddleware` intercepts message dispatching/handling
    - Attaches `RequestIdStamp` to outgoing messages
    - Restores original request ID when consuming messages
    - Cleans up after message handling
3. **CLI Commands:**

    - `CommandRequestIdSubscriber` generates "CLI"-prefixed request ID
    - Sets ID at command start
    - Cleans up at command termination
4. **Log Integration:**

    - `RequestIdProcessor` adds request ID to all log records
    - Makes request ID available in log formatters and outputs

Performance Optimization
------------------------

[](#performance-optimization)

- Uses Base58 encoding for shorter IDs than standard UUIDs
- Coroutine support ensures thread safety in async environments
- Automatic cleanup prevents memory leaks in long-running processes
- Middleware approach avoids performance impact on non-request paths

Contributing
------------

[](#contributing)

Contributions are welcome! Please see our [contribution guidelines](https://github.com/tourze/request-id-bundle/blob/master/.github/CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance73

Regular maintenance activity

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

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

Total

5

Last Release

150d ago

Major Versions

0.0.3 → 1.0.02025-10-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

---

Tags

symfonysymfony-bundle

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-request-id-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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