{"id":13395600,"url":"https://github.com/php-middleware/request-id","last_synced_at":"2025-12-28T09:08:56.248Z","repository":{"id":55909479,"uuid":"41703490","full_name":"php-middleware/request-id","owner":"php-middleware","description":"PSR-7 Request ID (Correlation ID) middleware","archived":false,"fork":false,"pushed_at":"2021-04-29T20:08:16.000Z","size":60,"stargazers_count":34,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-19T16:35:37.617Z","etag":null,"topics":["correlation-id","middleware","monolog","psr-15","psr-7","request-id","uuid"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-middleware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-31T22:20:06.000Z","updated_at":"2024-03-09T10:34:04.000Z","dependencies_parsed_at":"2022-08-15T09:10:44.994Z","dependency_job_id":null,"html_url":"https://github.com/php-middleware/request-id","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-middleware%2Frequest-id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-middleware%2Frequest-id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-middleware%2Frequest-id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-middleware%2Frequest-id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-middleware","download_url":"https://codeload.github.com/php-middleware/request-id/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243493031,"owners_count":20299585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["correlation-id","middleware","monolog","psr-15","psr-7","request-id","uuid"],"created_at":"2024-07-30T18:00:25.541Z","updated_at":"2025-12-28T09:08:51.193Z","avatar_url":"https://github.com/php-middleware.png","language":"PHP","readme":"# Request ID middleware for PHP\n\n[![Build Status](https://travis-ci.org/php-middleware/request-id.svg?branch=master)](https://travis-ci.org/php-middleware/request-id)\n\nPSR-7 Request ID middleware\n\nThis middleware provide framework-agnostic possibility to generate and add to request/response's header Request ID (Correlation ID).\n\n## Installation\n\n```bash\ncomposer require php-middleware/request-id\n```\n\n## Usage\n\nThis middleware require in contructor `PhpMiddleware\\RequestId\\RequestIdProviderFactoryInterface` implementation which\nmust create a new `RequestIdProviderInterface` object. We provide `RequestIdProvider` default implementation.\n\n```php\n$generator = new PhpMiddleware\\RequestId\\Generator\\PhpUniqidGenerator();\n$requestIdProvider = new PhpMiddleware\\RequestId\\RequestIdProviderFactory($generator);\n$requestIdMiddleware = new PhpMiddleware\\RequestId\\RequestIdMiddleware($requestIdProvider);\n\n$app = new MiddlewareRunner();\n$app-\u003eadd($requestIdMiddleware);\n$app-\u003erun($request, $response);\n```\n\nAll Provider factory constructor options:\n\n* `PhpMiddleware\\RequestId\\Generator\\GeneratorInterface` `$generator` - generator implementation (required)\n* `bool|PhpMiddleware\\RequestId\\OverridePolicy\\OverridePolicyInterface` `$allowOverride` (default `true`) - if `true` and request id header exists in incoming request, then value from request header will be used in middleware, using generator will be avoid\n* `string` `$requestHeader` (default `X-Request-Id`) - request header name\n\nHow to get request id in my application?\n\n* Middleware implements `RequestIdProviderInterface`, so you are able to use `getRequestId()` method,\n* from `request-id` attribute in `ServerRequest` object (`$request-\u003egetAttribute(RequestIdMiddleware::ATTRIBUTE_NAME)`).\n\n### Override policy\n\nYou can add your own logic to decide when override incoming request id. You can implement `OverridePolicyInterface` and pass it as `$allowOverride` variable in constructor.\n\n### Monolog processor\n\nWe provide simple [Monolog](https://github.com/Seldaek/monolog) [processor](src/MonologProcessor.php) to add request it to every log entry!\n\n### Request decorator\n\n[RequestDecorator](src/RequestDecorator.php) adds header with request id to your request object. It's useful when your microservices communicate between using PSR-7 HTTP messages e.g. [Guzzle](https://github.com/guzzle/guzzle).\n\n### Request Id generators\n\nTo generate request id you need to use implementation of `PhpMiddleware\\RequestId\\Generator\\GeneratorInterface`. There are predefined generators in `PhpMiddleware\\RequestId\\Generator\\` namespace:\n\n#### PhpUniqidGenerator\n\nSimple generator using [uniqid](http://php.net/manual/en/function.uniqid.php) function.\n\n#### RamseyUuid1Generator\n\n[UUID](https://tools.ietf.org/html/rfc4122)1 implementations of [Ramsey\\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.\n\n#### RamseyUuid3Generator\n\n[UUID](https://tools.ietf.org/html/rfc4122)3 implementations of [Ramsey\\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.\n\n#### RamseyUuid4Generator\n\n[UUID](https://tools.ietf.org/html/rfc4122)4 implementations of [Ramsey\\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.\n\n#### RamseyUuid4StaticGenerator\n\nGenerates Uuid4 like `RamseyUuid4Generator` however it's not require any dependency (it use static factory method).\n\n#### RamseyUuid5Generator\n\n[UUID](https://tools.ietf.org/html/rfc4122)5 implementations of [Ramsey\\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.\n\n#### PrefixedGenerator\n\nIt adds prefix to generated request id.\n\n#### Md5Generator\n\nThis generator converts generated request id to md5 hash.\n\n## It's just works with any modern php framework!\n\nMiddleware tested on:\n* [Expressive](https://github.com/zendframework/zend-expressive)\n\nMiddleware should works with:\n* [Slim 3.x](https://github.com/slimphp/Slim)\n\nAnd any other modern framework [supported middlewares and PSR-7](https://mwop.net/blog/2015-01-08-on-http-middleware-and-psr-7.html).\n","funding_links":[],"categories":["Middleware"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-middleware%2Frequest-id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-middleware%2Frequest-id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-middleware%2Frequest-id/lists"}