Skip to content

Commit

Permalink
Add reported_by tag to Rails error reporter errors (#1309)
Browse files Browse the repository at this point in the history
Make it easier to identify errors reported by the Rails error reporter
by adding the `reported_by` tag to errors reported by it.

This uses the same tag as we use for the Puma `lowlevel_error` reporter.
  • Loading branch information
tombruijn authored Sep 28, 2024
1 parent 274c387 commit ff98ed6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changesets/add-reported_by-tag-to-rails-error-reporter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: change
---

Add the `reported_by` tag to errors reported by the Rails error reporter so the source of the error is easier to identify.
1 change: 1 addition & 0 deletions lib/appsignal/integrations/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def report(error, handled:, severity:, context: {}, source: nil) # rubocop:disab
transaction.set_action(action_name) if action_name
transaction.add_custom_data(custom_data) if custom_data

tags[:reported_by] = :rails_error_reporter
tags[:severity] = severity
tags[:source] = source.to_s if source
transaction.add_tags(tags)
Expand Down
13 changes: 12 additions & 1 deletion spec/lib/appsignal/integrations/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def subscribe(subscriber)
expect(transaction).to have_action("CustomAction")
expect(transaction).to have_error("ExampleStandardError", "error message")
expect(transaction).to include_tags(
"reported_by" => "rails_error_reporter",
"duplicated_tag" => "duplicated value",
"severity" => "warning"
)
Expand All @@ -317,11 +318,15 @@ def subscribe(subscriber)
current_transaction.complete
end.to change { created_transactions.count }.by(1)

expect(current_transaction)
.to_not include_tags("reported_by" => "rails_error_reporter")

transaction = last_transaction
expect(transaction).to have_namespace("custom")
expect(transaction).to have_action("CustomAction")
expect(transaction).to have_error("ExampleStandardError", "other message")
expect(transaction).to include_tags(
"reported_by" => "rails_error_reporter",
"duplicated_tag" => "duplicated value",
"severity" => "warning"
)
Expand Down Expand Up @@ -359,6 +364,7 @@ def subscribe(subscriber)
expect(transaction).to have_action("ContextAction")
expect(transaction).to have_error("ExampleStandardError", "other message")
expect(transaction).to include_tags(
"reported_by" => "rails_error_reporter",
"duplicated_tag" => "duplicated value",
"severity" => "warning"
)
Expand All @@ -382,6 +388,7 @@ def subscribe(subscriber)
current_transaction.complete

expect(current_transaction).to include_tags(
"reported_by" => "rails_error_reporter",
"tag1" => "value1",
"tag2" => "value2",
"severity" => "warning"
Expand Down Expand Up @@ -431,7 +438,10 @@ def subscribe(subscriber)
expect(transaction).to have_namespace("runner")
expect(transaction).to_not have_action
expect(transaction).to have_error("ExampleStandardError", "error message")
expect(transaction).to include_tags("source" => "application.runner.railties")
expect(transaction).to include_tags(
"reported_by" => "rails_error_reporter",
"source" => "application.runner.railties"
)
end
end

Expand All @@ -446,6 +456,7 @@ def subscribe(subscriber)
end

expect(last_transaction).to include_tags(
"reported_by" => "rails_error_reporter",
"tag1" => "value1",
"tag2" => "value2",
"severity" => "warning"
Expand Down

0 comments on commit ff98ed6

Please sign in to comment.