From dfdfd53a7e47abd94c67dc44523ba0117608e424 Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Wed, 23 Oct 2024 09:16:21 +0200 Subject: [PATCH] Automatically ignore Rails' health-check 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 <45180344+unflxw@users.noreply.github.com> --- .../ignore-rails-healthcheck-by-default.md | 31 +++++++++++++++++++ lib/appsignal/integrations/railtie.rb | 3 +- .../appsignal/integrations/railtie_spec.rb | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changesets/ignore-rails-healthcheck-by-default.md diff --git a/.changesets/ignore-rails-healthcheck-by-default.md b/.changesets/ignore-rails-healthcheck-by-default.md new file mode 100644 index 000000000..5be9a005c --- /dev/null +++ b/.changesets/ignore-rails-healthcheck-by-default.md @@ -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 +``` diff --git a/lib/appsignal/integrations/railtie.rb b/lib/appsignal/integrations/railtie.rb index 3ea6804a4..fb5706232 100644 --- a/lib/appsignal/integrations/railtie.rb +++ b/lib/appsignal/integrations/railtie.rb @@ -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 diff --git a/spec/lib/appsignal/integrations/railtie_spec.rb b/spec/lib/appsignal/integrations/railtie_spec.rb index db0c14a4c..cb05eccf9 100644 --- a/spec/lib/appsignal/integrations/railtie_spec.rb +++ b/spec/lib/appsignal/integrations/railtie_spec.rb @@ -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