Open alignwebs opened 2 years ago
@alignwebs I don't have experience with Octane, but we faced a similar problem with workers/jobs, that we handle checking if the application is running in the console via $this->app->runningInConsole()
.
Do you know if there's a similar helper in Octane that can tell us if the package/application is running via a worker, so we can set the start time on every request?
I also have not used Octane. Nothing in the docs jumped out as an appropriate indicator to use. It looks like inference from the config or something would be needed. I was thinking a new config in this package would be better, that way the user could explicitly indicate they want "per request start time" or something.
I would prefer if this is transparent and it is handled by the package, and not expect from developers to understand that Octane only boots the application once, and specific configuration is needed to make this package work. But I don't see an obvious way to do it.
The use of Octane could be inferred by looking for the presence of it's configuration (I've never tried that in Laravel, so that's really more a theory). We could flip the behavior and add auto-detection of Octane with the option to disable auto-detection if needed. That auto-detection method could be extended as other use cases arise.
Do you know if there's a similar helper in Octane that can tell us if the package/application is running via a worker, so we can set the start time on every request?
When I tried to Log the time value inside the RequestStartTime
class, it was giving new values on each request! So technically the class was working fine but I don't know even if it's getting terminated at any point or not.
Octane has a way to attach Listeners to Octane Events in config/octane.php
. I feel this way we need to make some manual adjustments to make it work.
What do you think @arkaitzgarro ?
Stumbled upon this, tried to flush the RequestTime for each request, at least it give me the real latency, although there's Closure span that I dunno where it comes. Also I got warning for route_matching
The sleep/google/facebook duration span is correct but the position is wrong. I also tried to add all the collector to flush, but still the same
Laravel 9.42.2 php:8.1-cli-alpine Octane using roadrunner
Update
So I somewhat get it working in testing environment, turns its only the problem of "terminating" hook from this package, because originally "terminating" event is broadcasted in every request, in octane, it doesn't. But, octane do have "RequestTerminated" event which is equivalent of the normal terminating event, so I just hook the send command to that, it works. Also I don't actually need to flush the RequestStartTime.
But, there seem to be some caveat,
$_SERVER
that doesn't available in roadrunner, here's the json comparison of the data sent to apm, it's the cookies and more notably url
key that affect the view in Kibana in url sectionI'm trying to add this package to my app Laravel + Octane + Swoole, but the time is so long and the trace didn't show.
@fmiqbal I tried to add function into the array requestTerminated but don't work for me :/. How did you resolve this? I need to add something in another place? Could you help me?
I added \AG\ElasticApmLaravel\Collectors\RequestStartTime::class into the key flush and the request time it's ok.
Hi @arkaitzgarro, thanks for the wonderful package! It will be really great if we could use it safely with Laravel Octane.
I have attached a issue that seems to be with Octane:
Long Duration Time due to the Singleton Behavior
Also since most of the microservices will be going over Octane, so authenticity of the data is also required. Once again its great package for PHP devs looking to get APM. I am not so much experienced as you, else i would have surely raised a PR :)
Thanks