-
Notifications
You must be signed in to change notification settings - Fork 25
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
Oban telemetry start event is not needed + tests #76
Oban telemetry start event is not needed + tests #76
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your time on this change! 🫶
I will mark this one as changes required because we cannot remove the start event as users may lose context that they have now on their manually reported errors.
Aside from that, I think we can avoid the mock and I'm not sure if the testing strategy is correct or not (however, taking the time to introduce tests is really appreciated 🤗 )
defp execute_job_exception(additional_metadata \\ %{}) do | ||
raise "Exception!" | ||
catch | ||
kind, reason -> | ||
metadata = | ||
Map.merge(sample_metadata(), %{ | ||
reason: reason, | ||
kind: kind, | ||
stacktrace: __STACKTRACE__ | ||
}) | ||
|
||
:telemetry.execute( | ||
[:oban, :job, :exception], | ||
%{duration: 123 * 1_000_000}, | ||
Map.merge(metadata, additional_metadata) | ||
) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is the proper way to test this. Integration tests are missing because we do not have yet a clear idea of how to test it.
ideally, we would need to spin up an Oban job using Oban itself, and ensure the library is the one that emits events.
If we do that instead, any change in Oban will break the integration and the tests will continue to pass.
Let me ping @crbelaus to see his thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mocking the :telemetry is the way chosen on https://github.com/appsignal/appsignal-elixir/blob/main/test/appsignal/oban_test.exs so it's a good reference
Thanks for dedicating your time to write this pull request, but I do not agree with this approach. I feel like this test too complicated because it is mixing multiple different concerns. On the one hand it is testing the Telemetry package itself by checking first if an event handler is attached and then if sending an event effectively sends it to the attached handler. On the other hand we are not testing if the ErrorTracker captures the error, just that it emitted a particular Telemetry event. Something that is already tested elsewhere. The way I see it, I would directly call |
👋
The oban
job
metadata can be accessed from the exception event metadata so it's not needed to attach to thestart
event.Testing the oban integration is not easy since
Application.spec
is used directly so I wrapped it inside a Utils module than I can mock in order to simulate a oban event.