-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix raise and throws in instrument helper #292
Conversation
I think this was necessary to actually return the proper value in all scenarios. Doesn't this break some tests? |
By using a "soft return", by saving the return value in a variable, it can happen that an event is not finished when the block that's given to an instrument method raises and error or uses `throw` to throw a signal. Using `ensure` we _ensure_ that the event is finished even when that happens.
4867eb1
to
792ec18
Compare
It shouldn't, but let's wait on TravisCI to give the verdict in combination for all gems. The use of def foo
"bar"
ensure
123
end
foo # => "bar" returns "bar" as a return value from the method. See also this spec: https://github.com/appsignal/appsignal-ruby/pull/292/files#diff-0968d4ed9ff8f5b249a2c7e8bc32784bR19 |
Ok. If it works that's of course fine. It's just that I remember adding this for a specific scenario that was broken, but not exactly sure what it was. |
Ah I get it. The current implementation is: def instrument(name, title = nil, body = nil, body_format = Appsignal::EventFormatter::DEFAULT)
Appsignal::Transaction.current.start_event
return_value = yield if block_given?
Appsignal::Transaction.current.finish_event(name, title, body, body_format)
return_value
end So the new implementation that uses |
By using a "soft return", by saving the return value in a variable, it can happen that an event is not finished when the block that's given to an instrument method raises and error or uses throw to throw a signal. Using ensure we ensure that the event is finished even when that happens. Follow up from #292.
By using a "soft return", by saving the return value in a variable, it
can happen that an event is not finished when the block that's given to
an instrument method raises and error or uses
throw
to throw a signal.Using
ensure
we ensure that the event is finished even when thathappens.
Reported in
As reported in #289 (comment). Doesn't fix the (potential) parent issue of padrino starting two transactions in certain scenarios, still debugging that.
Notes