AppSignal for Ruby load order

The AppSignal Ruby gem can be configured in a couple different ways. Through an initializer, with a configuration file or through environment variables.

In Ruby gem version 2.0 the load order changed! Step 4 and 5 were swapped, making sure that environment variables are loaded after the appsignal.yml configuration file. Read more about it in the Pull Request on GitHub.

The configuration is loaded in a five step process. Starting with the gem defaults and ending with reading environment variables. The configuration options can be mixed without losing configuration from a different option. Using an initializer, a configuration file and environment variables together will work.

Config sources

1. Gem defaults

The AppSignal gem starts with loading its default configuration, setting paths and enabling certain features.

The agent defaults can be found in the gem source as Appsignal::Config::DEFAULT_CONFIG.

This source is listed as default in the diagnose output.

2. System detected settings

The gem detects what kind of system it's running on and configures itself accordingly.

For example, when it's running inside a container based system (such as Docker and Heroku) it sets the configuration option :running_in_container to true.

This source is listed as system in the diagnose output.

3. Initial configuration given to Config initializer

This configuration method has been deprecated since Ruby gem 3.12 and removed in Ruby gem 4.0.0 in favor of Appsignal.configure.

When manually creating a Appsignal::Config class you can pass in the initial configuration you want to apply. This is a hash of any of the options described below.

Ruby
Appsignal.config = Appsignal::Config.new(Dir.pwd, "production", { active: true, name: "My app!", push_api_key: "e55f8e96-62df-4817-b672-d10c8d924065" })

This step will override all given options from the defaults or system detected configuration.

This source is listed as initial in the diagnose output.

4. appsignal.yml config file

The most common way to configure your application is using the appsignal.yml file. When you use the appsignal install command the gem will create one for you.

The path of this configuration file is {project_root}/config/appsignal.yml.

This step will override all given options from the defaults, system detected and initializer configuration.

This source is listed as file in the diagnose output.

5. Environment variables

AppSignal will look for its configuration in environment variables. When found these will override all given configuration options from previous steps.

Shell
export APPSIGNAL_APP_NAME="my custom app name" # start your app here

This source is listed as env in the diagnose output.

6. Appsignal.configure

Lastly, the Ruby gem can be configured using the Appsignal.configure helper. When called, any config options configured using this helper will overwrite all given configuration options from previous sources.

Read the Appsignal.configure helper documentation for more information on how to use this helper.

In Rails apps, make sure to configure the AppSignal gem to start after Rails is initialized, otherwise the config set with Appsignal.configure is ignored when called in a Rails initializer like config/initializers/appsignal.rb.

Ruby
# Load AppSignal require "appsignal" # Load your app here # Configure AppSignal Appsignal.configure do |config| # Example config config.activejob_report_errors = "discard" config.sidekiq_report_errors = :discard config.ignore_actions = ["My ignored action", "My other ignored action"] config.request_headers << "MY_HTTP_HEADER" config.send_params = true config.enable_host_metrics = false end Appsignal.start # Do not call this in Rails apps # start your app here

This source is listed as dsl in the diagnose output.