-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make global helpers work in error method callbacks (#1216)
When using `Appsignal.report_error` and `Appsignal.send_error` (and `Appsignal.set_error`, more on that later), it was required to customize the metadata by calling the `set_*` methods directly on the Transaction object. This is the only time that is needed in our public API and wasn't ever really documented what methods applications can call, and how they might be different from the helpers on `Appsignal`. (I don't think there are any differences now, but there were in the past when we didn't have global helpers for custom data, parameters, headers and session data.) To make matters simpler for our end-user, make the `Appsignal.set_*` helpers work in the callback of `Appsignal.report_error` and `Appsignal.send_error` by temporarily switching the current transaction for the duration of that callback block. In the `Appsignal.set_error` helper callback, applications could already use `Appsignal.set_*` helpers, because it can only set errors an active transaction so I only updated the API docs for it.
- Loading branch information
Showing
5 changed files
with
153 additions
and
28 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
.changesets/global-helpers-work-inside-report_error-and-send_error-callbacks.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
bump: major | ||
type: change | ||
--- | ||
|
||
Global transaction metadata helpers now work inside the `Appsignal.report_error` and `Appsignal.send_error` callbacks. The transaction yield parameter will continue to work, but we recommend using the global `Appsignal.set_*` helpers. | ||
|
||
```ruby | ||
# Before | ||
Appsignal.report_error(error) do |transaction| | ||
transaction.set_namespace("my namespace") | ||
transaction.set_action("my action") | ||
transaction.add_tags(:tag_a => "value", :tag_b => "value") | ||
# etc. | ||
end | ||
Appsignal.send_error(error) do |transaction| | ||
transaction.set_namespace("my namespace") | ||
transaction.set_action("my action") | ||
transaction.add_tags(:tag_a => "value", :tag_b => "value") | ||
# etc. | ||
end | ||
|
||
# After | ||
Appsignal.report_error(error) do | ||
Appsignal.set_namespace("my namespace") | ||
Appsignal.set_action("my action") | ||
Appsignal.add_tags(:tag_a => "value", :tag_b => "value") | ||
# etc. | ||
end | ||
Appsignal.send_error(error) do | ||
Appsignal.set_namespace("my namespace") | ||
Appsignal.set_action("my action") | ||
Appsignal.add_tags(:tag_a => "value", :tag_b => "value") | ||
# etc. | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters