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

Support non-exception error values from Oban jobs #807

Merged
merged 6 commits into from
Oct 12, 2024

Conversation

savhappy
Copy link
Collaborator

@savhappy savhappy commented Oct 9, 2024

-added capture_message to handle_event in Sentry.Integrations.Oban.ErrorReporter to account for non-exception args that are passed

-closes #805

Map.take(job, [:args, :attempt, :id, :max_attempts, :meta, :queue, :tags, :worker]),
integration_meta: %{oban: %{job: job}}
)
if is_struct(exception) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want more specifically is_exception here, rather than just is_struct, because I think Exception.message/1 below won't work on just any general struct.

This may not really matter in practice, though, because I think the errors will probably never end up being a struct other than an Exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not but good to use the right tool for the job. Thanks and updated!

)
else
Sentry.capture_message("Error with %s", interpolation_parameters: [exception])
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more clear to have reason instead of exception here since it may not be an exception after all :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True! Updated, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a wildly generic error message we got going on here 😄 I think it'd be really hard to debug as it's just a generic message plus there are no metadata about the job (which you have available).

This needs to be completely restructured to basically build shared options, and then use Sentry.capture_message or Sentry.capture_exception based on whether reason is an exception or not. Also, doesn't :interpolation_parameters require string parameters? If so, do inspect(reason) here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also let's have the message be something like

"Oban job #{job.worker} errored out: %s"

Btw the fingerprint option needs to be customized, if it's just reason use inspect(reason) insted of Exception.message/1

@savhappy savhappy requested a review from solnic October 10, 2024 08:14
Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job, but we need a slightly different approach 🙃

)
else
Sentry.capture_message("Error with %s", interpolation_parameters: [exception])
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a wildly generic error message we got going on here 😄 I think it'd be really hard to debug as it's just a generic message plus there are no metadata about the job (which you have available).

This needs to be completely restructured to basically build shared options, and then use Sentry.capture_message or Sentry.capture_exception based on whether reason is an exception or not. Also, doesn't :interpolation_parameters require string parameters? If so, do inspect(reason) here.

)
else
Sentry.capture_message("Error with %s", interpolation_parameters: [exception])
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also let's have the message be something like

"Oban job #{job.worker} errored out: %s"

Btw the fingerprint option needs to be customized, if it's just reason use inspect(reason) insted of Exception.message/1

@savhappy
Copy link
Collaborator Author

@whatyouhide updated with your feedback! Yeah, I assumed that error message was not up to code 😆 . This restructure feels better

@savhappy savhappy requested a review from whatyouhide October 11, 2024 10:55
Copy link
Collaborator

@solnic solnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing to consider here is logging differently based on attempt counter - in one project I used a strategy where only the last attempt would result in an error, all other attempts were logged to sentry as warnings. Probably out of scope here but I figured I should mention it here for future consideration.

Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comment and we can ship this.

@solnic yeah that's probably something that could be configurable I think.

Comment on lines 36 to 37
(is_exception(reason) && [inspect(reason.__struct__), Exception.message(reason)]) ||
[inspect(reason)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use if, this is pretty hard to read and tries to mimic the ? : operator thing that Elixir doesn't have 🙃

Comment on lines 43 to 46
fingerprint:
[
inspect(job.worker)
] ++ fingerprint_opts,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but saves some space 😉

Suggested change
fingerprint:
[
inspect(job.worker)
] ++ fingerprint_opts,
fingerprint: [inspect(job.worker)] ++ fingerprint_opts,

Comment on lines 54 to 57
Sentry.capture_exception(
reason,
opts
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saves some space.

Suggested change
Sentry.capture_exception(
reason,
opts
)
Sentry.capture_exception(reason, opts)

@savhappy savhappy force-pushed the sav/oban-errorreporter-crash branch from 9a6dccd to 078a802 Compare October 11, 2024 18:45
@savhappy savhappy requested a review from whatyouhide October 11, 2024 18:46
@whatyouhide whatyouhide changed the title Oban ErrorReporter Crash Support non-exception error values from Oban jobs Oct 12, 2024
@whatyouhide whatyouhide merged commit 7d26e0c into master Oct 12, 2024
4 checks passed
@whatyouhide whatyouhide deleted the sav/oban-errorreporter-crash branch October 12, 2024 10:34
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.

Oban ErrorReporter can crash and detach future telemetry events
4 participants