Laravel Octane (Swoole) support
Closed this issue · 3 comments
esseplore-it commented
HTTP requests monitoring not working when using Laravel Octane (Swoole).
Similiar issue DataDog/dd-trace-php#704.
ilvalerione commented
Hi @esseplore-it,
thank you for your report.
To make Inspector work using Octane, you simply need to manually flush data to Inspector, since Octane runs the application in a long running process.
- Create a new middleware that extends the Inspector original
WebRequestMonitoring
middleware:
php artisan make:middleware InspectorFlushMiddleware
- Override the
terminate
method to flush data when the request is completed:
<?php
namespace App\Http\Middleware;
use Inspector\Laravel\Middleware\WebRequestMonitoring;
class InspectorFlushMiddleware extends WebRequestMonitoring
{
public function terminate($request, $response)
{
parent::terminate($request, $response);
// Explicitly flush data to Inspector after the request is completed
inspector()->flush();
}
}
- Use this middleware in your App\Http\Kernel class instead of the original Inspector middleware:
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
...,
InspectorFlushMiddleware::class,
],
'api' => [
...,
InspectorFlushMiddleware::class,
],
];
Let me know if this fix your issue, so we can add the solution to the official documentation.
esseplore-it commented
ilvalerione commented
It depends by the design of your system.
Take a look at this article, it could be helpful for this scenario:
https://inspector.dev/how-to-monitor-your-laravel-application-by-services-not-by-hostnames/