> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<Warning>
  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](https://github.com/appsignal/appsignal-ruby/pull/180).
</Warning>

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 - `default`](#1-gem-defaults)
* 2. [System detected settings - `system`](#2-system-detected-settings)
* 3. [Initial configuration - `initial`](#3-initial-configuration-given-to-config-initializer)
* 4. [`appsignal.yml` config file - `file`](#4-appsignalyml-config-file)
* 5. [Environment variables - `env`](#5-environment-variables)
* 6. [`appsignal.rb` config file - `dsl`](#appsignal-rb-config-file)
* 7. [`Appsignal.configure` - `dsl`](#appsignal-configure-helper)

## 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](https://github.com/appsignal/appsignal-ruby/blob/main/lib/appsignal/config.rb)
as `Appsignal::Config::DEFAULT_CONFIG`.

This source is listed as `default` in the [diagnose](/ruby/command-line/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](/ruby/command-line/diagnose) output.

## 3. Initial configuration given to `Config` initializer

<Warning>
  This configuration method has been deprecated since Ruby gem 3.12 and removed in Ruby gem 4.0.0 in favor of [`Appsignal.configure`](#appsignal-configure-helper).
</Warning>

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.

<CodeGroup>
  ```ruby Ruby theme={null}
  Appsignal.config = Appsignal::Config.new(Dir.pwd, "production", {
    active: true,
    name: "My app!",
    push_api_key: "e55f8e96-62df-4817-b672-d10c8d924065"
  })
  ```
</CodeGroup>

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

This source is listed as `initial` in the [diagnose](/ruby/command-line/diagnose) output.

## 4. `appsignal.yml` config file

<Warning>
  This configuration method will be removed in the next major version of the Ruby gem.
  We recommend using the [`appsignal.rb` config file](#6-appsignal-dsl) instead.
</Warning>

A 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.

Read [the `appsignal.yml` config file](/ruby/configuration#yaml-configuration-file) documentation for more information on how this configuration method works.

This source is listed as `file` in the [diagnose](/ruby/command-line/diagnose) output.

<a id="environment-variables" />

## 5. Environment variables

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

<CodeGroup>
  ```bash Bash theme={null}
  export APPSIGNAL_APP_NAME="my custom app name"
  # start your app here
  ```
</CodeGroup>

Read [the system environment variables](/ruby/configuration#system-environment-variables) documentation for more information on how this configuration method works.

This source is listed as `env` in the [diagnose](/ruby/command-line/diagnose) output.

## 6. `appsignal.rb` config file {/* id: appsignal-rb-config-file */}

A way to configure your application is using the `appsignal.rb` file.

The path of this configuration file is `{project_root}/config/appsignal.rb`.
This load path cannot be customized.

This step will override all given options from the defaults, system detected and environment variables.

If both an [`appsignal.yml` config file](#4-appsignalyml-config-file) and a `appsignal.rb` config file are present, only the `appsignal.rb` config file is loaded.

Read [the `appsignal.rb` config file](/ruby/configuration#ruby-configuration-file) documentation for more information on how this configuration method works.

This source is listed as `dsl` in the [diagnose](/ruby/command-line/diagnose) output.

## 7. Appsignal.configure helper {/* id: configure-helper */}

<Warning>
  In version 3 and 4 of the Ruby gem, calling the `Appsignal.configure` helper will also load the `appsignal.yml` file, if present.
  This behavior will *removed* in the next major version of the Ruby gem.
  Please only use the [`appsignal.rb` config file](#appsignal-rb-config-file) or [`Appsignal.configure` helper](#configure-helper).
</Warning>

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

If a `config/appsignal.rb` config file is also present in the project, it will **not be loaded** if the `Appsignal.configure` helper is called first in your application.

Read [the `Appsignal.configure` helper](/ruby/configuration#appsignalconfigure-helper) documentation for more information on how this configuration method works.

This source is listed as `dsl` in the [diagnose](/ruby/command-line/diagnose) output.
