Keep similar-ai from tripping the global circuit on a lone URL 502, clamp Qdrant search to 100, and add Server-Timing plus slow-request logging. Studio shared props, Academy S3 exists caching, heat chunking, and Redis/scheduler hygiene stay in this rollout.
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Negligible-overhead request duration header for production HTTP profiling.
|
|
* Does not log queries or payloads.
|
|
*/
|
|
final class AddServerTiming
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$started = hrtime(true);
|
|
$response = $next($request);
|
|
$durationMs = (hrtime(true) - $started) / 1_000_000;
|
|
|
|
if (headers_sent()) {
|
|
return $response;
|
|
}
|
|
|
|
$metrics = ['app;desc="Laravel";dur='.number_format($durationMs, 1, '.', '')];
|
|
$ssrMs = $request->attributes->get('http.ssr_ms');
|
|
if (is_numeric($ssrMs) && (float) $ssrMs >= 0) {
|
|
$metrics[] = 'ssr;desc="Inertia SSR";dur='.number_format((float) $ssrMs, 1, '.', '');
|
|
}
|
|
|
|
$metric = implode(', ', $metrics);
|
|
$existing = $response->headers->get('Server-Timing');
|
|
|
|
$response->headers->set(
|
|
'Server-Timing',
|
|
$existing ? $existing.', '.$metric : $metric,
|
|
);
|
|
|
|
return $response;
|
|
}
|
|
}
|