Skip to content
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

Errors from queued jobs aren't sent until the queue runner is restarted #222

Closed
misenhower opened this issue Mar 27, 2019 · 13 comments · Fixed by #228
Closed

Errors from queued jobs aren't sent until the queue runner is restarted #222

misenhower opened this issue Mar 27, 2019 · 13 comments · Fixed by #228

Comments

@misenhower
Copy link

misenhower commented Mar 27, 2019

Exceptions from queued background jobs are logged properly, but they only seem to be sent to the remote Sentry server when you manually restart or shut down the queue runner. I assume that's the intended behavior for HTTP requests, but for queue runners it means reports are delayed indefinitely (or lost).

I'm using the Horizon queue runner, but I assume this happens with the basic one as well.

I think this was handled in #153, but the sendUnsentErrors method was removed from a later version of sentry-php so I'm not sure what the best method to fix this would be at this point.

@stayallive
Copy link
Collaborator

@misenhower sorry about the late response.

As long as the default transport is used reports should be sent immediately, did you implement the SpoolTransport?

@misenhower
Copy link
Author

Nope, nothing out of the ordinary. I set up a test project here that demonstrates the issue: https://github.com/misenhower/laravel-sentry-test

After checking out the repo:

cp .env.example .env
touch database/database.sqlite
composer install
php artisan migrate

Then add a Sentry DSN inside .env.

You can add a job that will throw an exception to the queue with:

php artisan sentry:test

If you run the queue worker, it will process and fail the job but the exception won't be reported to Sentry as long as the worker is running:

php artisan queue:work --tries=1

So that's the issue I'm running into -- failed jobs aren't reported while the queue worker is running.

If you hit ctrl+c, it won't report the job either (probably because it isn't a clean exit) and any accumulated reports will be lost.

If you tell the queue worker to quit when its queue is empty, then errors will be reported after it finishes processing jobs, right before the worker exits (gracefully):

php artisan queue:work --tries=1 --stop-when-empty

Let me know if you need any more info or if you're seeing something different! 😃

@stayallive
Copy link
Collaborator

stayallive commented Apr 2, 2019

@misenhower you got my attention with this, many thanks!

I can reproduce the issue! Going to hunt for a solution!

@dwightwatson
Copy link
Contributor

Just come across this too - errors occurring in Horizon are not being reported to Sentry.

@stayallive
Copy link
Collaborator

@misenhower & @dwightwatson, we have some hurdles not allowing us to implement a proper fix so I crafted up a temporary one until we can fix the base SDK.

I would appreciate if you all could take a look at #228 and see if that would solve the issues described in this issue.

@misenhower
Copy link
Author

Thanks @stayallive, I'm out of town right now but I will check this out next week. Thanks for all your effort, that seemed to kick off a long chain of comments 😄

@stayallive
Copy link
Collaborator

Yeah this is going to require some effort to really "fix" in the end. But in the meantime the #228 PR is there to get a fix out soon while we work out the details :)

@misenhower
Copy link
Author

Hey, sorry for my delay on this. I just tested out the code from #228 with my sample project as well as a real project and it seems to fix the problem in both of them. So everything looks good from what I can see, thanks again for your help! 👍

@andre-hh
Copy link

[...] did you implement the SpoolTransport?

Sorry for disturbing here, but is there anywhere more information about how to do this in Laravel @stayallive ?

@stayallive
Copy link
Collaborator

@andre-hh I am not sure what you are asking here. But if you have a question not related to sending errors from a queue until it's restarted please open a new issue with your question so we can follow it better.

This issue is fixed in 1.0.2 and above of sentry/sentry-laravel.

@dwightwatson
Copy link
Contributor

I'm wondering if this issue has re-surfaced in Laravel 9. I'm seeing "failed jobs" in the Horizon dashboard that aren't being reported to Sentry. Wondering if anyone from this thread has noticed the same behaviour - perhaps some event names have changed and broken reporting.

@stayallive
Copy link
Collaborator

@dwightwatson are you sure the exception with what those jobs failed are not ignored by default (like a ModelNotFoundException) or the job has a failed method?

https://docs.sentry.io/platforms/php/guides/laravel/usage/#queue-jobs

Feel free to open up a new issue with a little more info so we can investigate if needed.

@dwightwatson
Copy link
Contributor

Yeah - everything in my failed job list should have been reported - all proper exceptions.

I'll review closer and open a new issue if I can narrow it down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants