Skip to content

Commit

Permalink
Automatically ignore Rails' health-check
Browse files Browse the repository at this point in the history
Adds the `Rails::HealthController#show` endpoint to the default
`ignore_actions` config by adding it to the Railtie loader defaults.

Suggested by a customer in:
https://app.intercom.com/a/inbox/yzor8gyw/inbox/shared/unassigned/conversation/16410700366724#part_id=comment-16410700366724-21909575460

Co-authored-by: Noemi <[email protected]>
  • Loading branch information
tombruijn and unflxw committed Oct 23, 2024
1 parent 6b0b3d6 commit dfdfd53
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .changesets/ignore-rails-healthcheck-by-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
bump: patch
type: change
---

Ignore the Rails healthcheck endpoint (Rails::HealthController#show) by default for Rails apps.

If the `ignore_actions` option is set in the `config/appsignal.yml` file, the default is overwritten.
If the `APPSIGNAL_IGNORE_ACTIONS` environment variable is set, the default is overwritten.
When using the `Appsignal.configure` helper, add more actions to the default like so:

```ruby
# config/appsignal.rb
Appsignal.configure do |config|
# Add more actions to ignore
config.ignore_actions << "My action"
end
```

To overwrite the default using the `Appsignal.configure` helper, do either of the following:

```ruby
# config/appsignal.rb
Appsignal.configure do |config|
# Overwrite the default value, ignoring all actions ignored by default
config.ignore_actions = ["My action"]

# To only remove the healtcheck endpoint
config.ignore_actions.delete("Rails::HealthController#show")
end
```
3 changes: 2 additions & 1 deletion lib/appsignal/integrations/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def self.load_default_config
:root_path => Rails.root,
:env => Rails.env,
:name => Appsignal::Utils::RailsHelper.detected_rails_app_name,
:log_path => Rails.root.join("log")
:log_path => Rails.root.join("log"),
:ignore_actions => ["Rails::HealthController#show"]
)
end

Expand Down
2 changes: 2 additions & 0 deletions spec/lib/appsignal/integrations/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def initialize_railtie(event)
expect(rails_defaults[:options][:name]).to eq("MyApp")
expect(rails_defaults[:options][:log_path])
.to eq(Pathname.new(File.join(rails_project_fixture_path, "log")))
expect(rails_defaults[:options][:ignore_actions])
.to eq(["Rails::HealthController#show"])
end

it "loads the app name from the project's appsignal.yml file" do
Expand Down

0 comments on commit dfdfd53

Please sign in to comment.