chrisguitarguy/request-id-bundle
AppKernel, HttpFoundation). While Laravel shares some middleware concepts, direct integration would require abstraction or a wrapper layer.Request object, event listeners). Laravel’s request handling (e.g., Illuminate\Http\Request) differs in structure, requiring custom middleware or service providers to replicate functionality.EventDispatcher and Container would need replacement (e.g., Laravel’s ServiceProvider + Kernel hooks).Request-Id header logic is straightforward but requires manual mapping in Laravel’s Request facade or custom middleware..env or config/services.php, with minimal overhead.trust_request_header) or generation logic is critical.Request object isn’t always available in background processes.spatie/laravel-requestid) for lower friction. If Symfony integration is mandatory, evaluate:
Request-Id headers upstream.Request-Id headers (see example below).ServiceProvider boot methods or events facade.bind() or singleton() in AppServiceProvider.namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class RequestIdMiddleware
{
public function handle($request, Closure $next)
{
$requestId = $request->header('Request-Id') ?: Str::uuid()->toString();
$request->headers->set('X-Request-Id', $requestId); // Laravel header format
// Store in request for later use (e.g., logging)
$request->attributes->add(['request_id' => $requestId]);
return $next($request);
}
}
config.yml with .env or config/services.php:
// config/services.php
'request_id' => [
'header' => 'Request-Id',
'trust_header' => env('REQUEST_ID_TRUST_HEADER', true),
'response_header' => 'X-Request-Id',
],
Request-Id/X-Request-Id conventions (e.g., W3C Trace Context).request_id to log context).Request-Id via metadata (e.g., dispatchSyncWith() or custom job data).Request-Id in troubleshooting.Str::uuid() vs. custom logic).Request-Id from the original request.Request-Id with platform-native tracing (e.g., uber-trace-id).X-Request-Id vs. Request-Id). Standardize on one format.Request-Id flow (e.g., how to access it in middleware, logs, or errors).Request-Id to correlate logs across services").request_id).How can I help you explore Laravel packages today?