Middleware PSR-15 compliant which handle Correlation ID Header
This package is auto-updated.
Last update: 2021-11-11 08:55:20 UTC
A Correlation ID is a unique identifier value that is attached to requests and messages that allow reference to a particular transaction or event chain.
Some loadbalancer or WAF provide such additional headers, so you just need to normalize its name a propagate it into your system (sub-request, logs, ...).
Correlation ID is detected as it :
If nothing is found, a new one is generated using a UUID generator and added as
X-Correlation-ID and returned into the response.
Just add the middleware into your
// @todo: generate request $dispatcher = new Dispatcher(); $dispatcher->pipe(new CorrelationIdMiddleware()); // @todo: add other middleware $response = $dispatcher->handle($request);
Correlation ID is also available as
attribute under the
response header can be overridden.
// @todo: generate request $correlationMiddleware = new CorrelationIdMiddleware( [ 'X-Custom-Header', CorrelationIdMiddleware::HEADER_CORRELATION_ID, ], 'X-Custom-Header' ); $dispatcher = new Dispatcher(); $dispatcher->pipe($correlationMiddleware); // @todo: add other middleware $response = $dispatcher->handle($request);
Note: adding correlation id header in response can be skipped by specifying
false as secondary parameter in the constructor.