It's very difficult to track a request across the system when we are working with microservices. We came out with a solution for that. We generate a unique version 4 uuid for every request and every service passes this id via request headers to other services. We call this correlation ID.
Add service provider to bootstrap/app.php in your Lumen project.
// bootstrap/app.php
$app->register(\ProEmergotech\Correlate\Laravel\LaravelCorrelateServiceProvider::class);
This middleware automatically adds correlation id (coming from request header) to every log message.
There are some macros added to the request object if you want to work with correlation id.
if ($request->hasCorrelationId()) {
$cid = $request->getCorrelationId();
}
// or if you can change the ID
$request->setCorrelationId(\ProEmergotech\Correlate\Correlate::id());