1. Go to this page and download the library: Download kolaybi/request-tracer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// bootstrap/app.php
use KolayBi\RequestTracer\Middleware\RequestTracerMiddleware;
->withMiddleware(function (Middleware $middleware) {
$middleware->prepend(RequestTracerMiddleware::class);
})
// Per route group — channel set via middleware parameter
Route::middleware([RequestTracerMiddleware::class.':web'])->group(...)
Route::middleware([RequestTracerMiddleware::class.':mobile'])->group(...)
// Channel from request header — set incoming.channel_header in config
// Header value takes priority over middleware parameter
use KolayBi\RequestTracer\Contracts\TraceContextProvider;
class AppTraceContextProvider implements TraceContextProvider
{
public function tenantId(): int|string|null
{
return auth()->user()?->company_id;
}
public function userId(): int|string|null
{
return auth()->id();
}
public function clientIp(): ?string
{
return request()?->ip();
}
public function serverIdentifier(): ?string
{
return gethostname();
}
}