[9.x] Request lifecycle duration handler#44122
Conversation
960cf7b to
2c17da4
Compare
2c17da4 to
a45f4a8
Compare
|
Hey, just gave this a try. Is there a reason this does NOT work, when I use the HTTP Kernel namespace, and not the kernel contract? (with the contract it works) |
|
Hey christoph, Laravel only binds the Kernel against the contract, so resolving the contract is the only way (that I know of) to resolve the instance Laravel is using. If you resolve the "HTTP Kernel namespace" instance, you are resolving a new instance and not the one that is handling the incoming request. If you wanted to be able to resolve the HTTP namespace Kernel, you would need to bind it to the same instance that the contract uses... Like: $this->app->singleton(\App\Http\Kernel::class, fn ($a) =>
$a[\Illuminate\Contracts\Http\Kernel::class)
);Which feels a little backwards. Alternatively, we could PR a helper to the service provider that handles the resolution under the hood: public function boot()
{
$this->whenRequestLifecycleIsLongerThan(/* ... *);
}which proxies the call to the resolved contract instance, but I don't know that we need it. |
|
Hey Tim, thanks for clearing this up. I don't think there is a need currently to change it. It's just something people have to be aware of when using it. |
This PR is in a similar spirit the the cumulative query duration PR. It allows developers to easily handle when an application request lifecycle exceeds a certain threshold.
The feature includes the duration of the request handle method and the terminating of the middleware and application.
This gives developers a nice hook around the entire lifecycle of the request, as seen: https://github.com/laravel/laravel/blob/c1dc4199b83466a3a6a8c70953250b0e2ec70001/public/index.php#L51-L55
This is an easy starting point for tracking slow requests and not a full blown replacement for APM, but gives developers some quick insight into their system with little to no extra knowledge / setup.
The handler is invoked after the request has been returned to the user.
Command compliment: #44125