1. Go to this page and download the library: Download ditliti/laravel-sdk 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/ */
// app/Http/Middleware/ContinueDitlitiTrace.php
public function handle(Request $request, Closure $next)
{
$client = app(DitlitiClient::class)->withTrace($request->header('traceparent'));
app()->instance(DitlitiClient::class, $client);
return $next($request);
}
// Service A: start a trace and call Service B, forwarding the header.
$client = $client->withTrace();
Http::withHeaders(['traceparent' => $client->getTraceparent()])->get($serviceBUrl);
$span = $client->startSpan('db.query', ['db' => 'postgres']);
// ... do the work ...
$span->finish();
// report() automatically tags trace_id when a trace is active,
// so errors show up correlated to the trace at GET /api/v1/traces/:trace_id (org-wide).