-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request - Queuing Request Logs #30
Comments
Hi @Sammyjo20 👋
Thanks so much 🙏
I see your use case 🤔 I originally avoided queued jobs and looked at Terminable Middleware but finally decided to use a synchronous listener (aka non-queued) for the event Solution right nowCould we not just queue the listener we already have for the That means that we need to call the logger (implementing This can actually be done already, in two ways (option 2 is easier):
Should we implement it into this package as a core feature?Albeit it is already possible, then there is no build in config for it, which would be the ideal for any developer wanting to achieve this. I originally thought there were no use cases for this, since the performance concern makes no sense simply because writing is done after the response has been returned to the user. But I do understand your concerns and could imagine there could be other edgecases. Hence I am okay adding this as a build in feature of the package. I will keep this issue open for now, and if I find the time to add this myself I will probably do so. But I am open for any PRs for this feature already. |
Hey @bilfeldt I'm really sorry for not replying sooner - I feel awful! Thank you for such a detailed reply. It would be great if this was a feature in the library but I understand you may have other commitments at this point in time. I wanted to share this with you - we wanted to see what was slowing some of our requests down and it was what I expected: I was wondering if I could somehow make the middleware terminatable. I'm going to have a look today and let you know if I can. |
No worries at all @Sammyjo20 :) Just to be clear, that query is being executed after the response has been returned to the user right? |
No, the middleware isn't terminatable - so it'll be part of the request - this is why it's being picked up in the request lifecycle |
The middleware is only used to "tag" that the request should be logged. Logging happens using the event listener here laravel-request-logger/src/EventServiceProvider.php Lines 11 to 15 in 2fe2f6e
And the event |
Hmm, the listener isn't queued so that leaves me to think it might be running synchronously? I might be wrong - where abouts is the |
Sorry - I didn't realise it was a Laravel event: But it doesn't look like this is after the request lifecycle. I'll keep digging haha |
So looking in I wonder if we could move all of the logic out of a listener and put it into |
Yes the listener is not queued (and cannot be, because of the serialization issue I mentioned). I might have misunderstood the If that is indeed the case then we/I should definitly make it possible to log sync either using a queued job or using terminatable middleware. |
Sorry @Sammyjo20 had not seen your answer when I posted above. So we agree that my original postulate was wrong and that the event I wonder if there is a |
I'm currently working off a fork and I will see if it works - just installing it locally - the PR will be a little crude without testing but I am happy to put one up if you like? Thank you so much for being so cooperative on this one! |
Feel free to post a PR for this - absolutely 👍 A few ideas I have here:
|
I personally vote for combining option 1 and 2 btw 👍 |
I think either option 1 or 2 could be good. For people who haven't enabled queueing it will still run in sync, but for others it'll queue it. Option 2 is probably easier to implement because instead of an event being fired, you could run the terminatable middleware which checks for a request. I'd be happy to try and change my PR to option 2 if you would like. |
With option 1 you could even |
Good idea. Yes a PR would be much appriciated. |
Hey, absolutely love this package - great work on it!
We're currently running into an issue where because every request is written to the
request_logs
table. This results in a single point of failure (if our writer instance fails). It also means that for even read-based operations our writer is only being used. It would be really cool if this library allowed us to queue the storing of request logs. This would allow our GET requests to only touch our load-balanced reader instances and never touch the writer. It would also speed up our requests as we currently have the request logs table on a separate database connection.The text was updated successfully, but these errors were encountered: