-
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.
Browse files
Browse the repository at this point in the history
When the Rails version we're integrating with supports the Rails error reporter, add a subscriber to it to report errors to AppSignal. https://guides.rubyonrails.org/error_reporting.html ## Error reporting We report the errors using `Appsignal.send_error` to report the errors separately from the main request sample. If the request did not fail with an error, because `Rails.error.handle` was used to not reraise the error, it will not mark the request transaction as having encountered an error, while the end-user saw none. When `Rails.error.record` is used, we don't record the error in the error handler. It will be reraised and handled by our other instrumentations, like the Rails instrumentation. This prevents the error from reported twice. Using `Appsignal.send_error` is also a bit of a workaround to support reporting multiple errors reported by Rails, even though we don't support multiple errors on a transaction. ## Transaction namespace, action name and tags To make sure the errors are reported in a somewhat similar grouping as the request they belonged to, the error reporter subscriber will check different levels of context. First, it will copy the controller name from the Rails execution context on the transaction, if available. This is done because we don't have this information in the Rails instrumentation middleware beforehand, and the action name will be `nil` at this time. This should result in the same action name as from our Rails middleware. Then it will copy the transaction namespace and action name from the current transaction, to the transaction created by `Appsignal.send_error`. In this step the Active Job's job action name is also is picked up, as we do have that available on the transaction. If people have set a custom namespace or action name on the transaction, that is also copied here, as well as the transaction tags. If the namespace, action name or tags change after the error has been reported by the Rails error reporter, we will not pick up that change. People need to set this metadata on the request transaction in a `before_action` callback, rather than a `after_action` callback in a Rails controller. ### Transaction namespace and action name from other instrumentations For other instrumentations, like Sidekiq, we do not currently report the action name correctly. The error is still reported, but the action name will be unset. The same problem I fixed for Active Job jobs in #945 applies here. This will need to be applied to other instrumentations, where possible. I can't guarantee it can work for all instrumentations, even if we update them. ### Custom namespace and action name If, people want to report this error using a different namespace or action, than the one inherited from the current transaction, they can use the `appsignal` context to customize it for this one error. ```ruby given_context = { :appsignal => { :namespace => "context", :action => "ContextAction" } } Rails.error.handle(context: given_context) do raise ExampleStandardError end ``` ### Custom tags All other context values, that do not have another purpose that I know off (like `controller` and `job`), will be set as tags. If people add their own additional context, this will be added as tags. ```ruby tags = { :abc => "def" } Rails.error.handle(context: tags) do raise ExampleStandardError end ```
- Loading branch information
Showing
6 changed files
with
314 additions
and
1 deletion.
There are no files selected for viewing
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,26 @@ | ||
--- | ||
bump: "patch" | ||
type: "add" | ||
--- | ||
|
||
Add Rails [error reporter](https://guides.rubyonrails.org/error_reporting.html) support. Errors reported using `Rails.error.handle` are tracked as separate errors in AppSignal. We rely on our other Rails instrumentation to report the errors reported with `Rails.error.record`. | ||
|
||
The error is reported under the same controller/job name, on a best effort basis. It may not be 100% accurate. If `Rails.error.handle` is called within a Rails controller or Active Job job, it will copy the AppSignal transaction namespace, action name and tags from the current transaction to the transaction for the `Rails.error.handle` reported error. If you call `Appsignal.set_namespace`, `Appsignal.set_action` or `Appsignal.tag_request` after `Rails.error.handle`, those changes will not be reflected up in the already reported error. | ||
|
||
It is also possible to customize the AppSignal namespace and action name for the reported error using the `appsignal` context: | ||
|
||
```ruby | ||
Rails.error.handle(:context => { :appsignal => { :namespace => "context", :action => "ContextAction" } }) do | ||
raise "Test" | ||
end | ||
``` | ||
|
||
All other key-values are reported as tags: | ||
|
||
```ruby | ||
Rails.error.handle(:context => { :tag_key => "tag value" }) do | ||
raise "Test" | ||
end | ||
``` | ||
|
||
Integration with the Rails error reporter is enabled by default. Disable this feature by setting the `enable_rails_error_reporter` config option to `false`. |
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