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

[5.x] Add exception context on failed jobs #1115

Merged
merged 1 commit into from
Feb 5, 2022

Conversation

antoinelame
Copy link
Contributor

This PR adds the exception context when displaying a failed job.

Capture d’écran 2022-01-28 à 02 06 20

@driesvints
Copy link
Member

This is a good pr but we'll need to make sure it's backwards compatible with existing horizon installations. To try this out, install an existing Laravel 8 app with current horizon, log a few jobs and afterwards update to your changes in the PR and log a few new jobs. Make sure the old ones still function.

@driesvints driesvints marked this pull request as draft January 28, 2022 07:28
@antoinelame
Copy link
Contributor Author

👋 @driesvints! I installed it on two existing and well-used Laravel 8 applications, and everything has been working like a charm for the past 5 days. It has been pretty useful for us to have the exception context directly in Horizon (like Telescope already does), rather than having to read it in the log file.

@driesvints driesvints marked this pull request as ready for review February 3, 2022 10:40
@driesvints
Copy link
Member

Cool, thanks @antoinelame. Taylor will review this.

@taylorotwell
Copy link
Member

Does this only work for custom exceptions in your application that define a context method? context is not a method that is present on all exceptions.

@antoinelame
Copy link
Contributor Author

antoinelame commented Feb 4, 2022

Yep, it only works for exceptions that define a context method.

Do you think it's an issue? The idea is to unify the use of the context method between the Handler, Telescope and Horizon, given that:

  • Illuminate Handler specifically adds this method data, if it exists, to the logs (see here)
  • Telescope also adds this method data to the "Exception" screen (see here)

What do you think?

@taylorotwell
Copy link
Member

taylorotwell commented Feb 4, 2022

This does not unify that though. Note that in Telescope the context is derived from the Logging system - where context can be applied globally to all logged messages. This PR only pulls context from the exception's context method if it exists. So, they are not entirely the same implementation and the data will not always match between these Horizon and Telescope in this case. I believe this implementation will be missing any globally applied context that is defined in the exception handler.

@antoinelame
Copy link
Contributor Author

Indeed, I see your point.

I don't see a simple way to implement the functionality in the same way as Telescope, since Horizon doesn't rely on MessageLogged event. I will see if I can change the implementation. Maybe we should close the PR in the meantime.

@taylorotwell
Copy link
Member

taylorotwell commented Feb 5, 2022

I don't think it's a bad PR and it might be better than nothing - just pointing out it's not quite the same as Telescope.

@taylorotwell taylorotwell merged commit de11b32 into laravel:5.x Feb 5, 2022
@flexchar
Copy link

Hi @antoinelame! An amazing addition to the ecosystem.

I'm looking forward to using it. However struggling to find how exactly the context is added. I myself checked Laravel documentation - doesn't mention anything on the horizon page.

I'd greatly appreciate if you throw an example job code or reference a documentation article!

@antoinelame
Copy link
Contributor Author

Hi @flexchar, you just have to declare the context() method in your exception. You can find an example in the documentation.

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 this pull request may close these issues.

4 participants