Choose a Configuration Option
This guide will walk you through the steps necessary to configure your application to best suit your needs. There are, of course, multiple configuration options for your application, but since the implementation method for all options is identical, in this guide, we’ll focus on the following configurations: We’ll be using thelog_level option as an example for Ruby, Elixir, Node.js and Python applications.
We’ll use the namespace option as an example for Front-end JavaScript applications.
Configuration Methods
There are multiple ways to configure your AppSignal integration, and integrations can vary depending on your application’s language, but they all have the following configuration methods:- File Based Configuration:
A config file where the AppSignal integration reads the AppSignal configuration. - System Environment Variable Configuration:
Environment variables are set on the host system (server) on the parent process that starts your application.
Note: This method is not available for front-end JavaScript.
File Based Configuration
File-based configuration is the easiest way to configure your integration. Some integrations create a config file during the installation of AppSignal in the app. In these config files, you can uniquely configure one or multiple application environments. Config options for:Ruby
When using the Ruby integration gem, it will create theconfig/appsignal.yml in your applications root folder, with basic configuration settings upon installation. If your application reports data to AppSignal without an appsignal.yml file, your application is most likely using system environment variables.
In the below example config file, two environments are defined, development and production - each has environment specific configuration options nested under them. Everything defined and nested within default applies to all environments, as long as default is included in the environment mapping.
We want to set the log_level to debug exclusively in our development environment; to do this, we’ve added log_level: "debug" in the development environment configuration (line 10).
default is applied to all environments, so to set the log_level to debug in all environments, we can instead nest the configuration under default, as done in line 6 of the below example code:
Read More:
Elixir
Upon installation, the Elixir integration creates aconfig/appsignal.exs (default location) file with basic configurations. If this file is not present but your application reports data to AppSignal, check any of the other .exs files in the config/ directory of your Elixir app. If no AppSignal configuration is present in any of the files, your application is likely using system environment variables as a configuration method instead.
To add a configuration option and have it apply to all your application’s environments, add the config option to the config/appsignal.exs file, like on line 7 of the example below:
config/ directory.
In the example below, the log_level option has been added on line 3 of the development (or “dev”) environment:
Read More
Node.js
After installation, you need to create an AppSignal config file to configure your application. If no file with AppSignal configuration is present, it is most likely using system environment variables as a configuration method instead. To configure AppSignal for Node.js apps, we recommend creating anappsignal.js file with the AppSignal config in your application’s root or src directory. Then require/import it from the app’s code before any other packages are required or imported.
In the example below, there is an appsignal.js file in the root of the app directory. In this file, we’ll add the logLevel config option.
NODE_ENV, defaults to “development”).
In Node.js there are many ways to create environment-specific configurations for AppSignal. If you are unsure how to do this within your own application, one method we recommend is using conditionals in your appsignal.js, such as in the example below where we specify debug for the production environment.
- On line 4 - we only activate the AppSignal integration if the environment is production.
- On line 8 - as in our previous code example we set the
logLeveltodebug
appsignal.js at the very top of your app’s main file. Your application’s main file name may vary depending on how your application is structured. It is the file you use to start your Node application and is usually called index.js or app.js. Ensure AppSignal is required at the very top of the file like in the example below:
Read More
Python
When using the Python integration installer, it will create the__appsignal__.py in your applications root folder, with basic configuration settings. Your application can also be configured using system environment variables.
To add a configuration option and have it apply to your development application environment, add the config option to the __appsignal__.py file, like in the example below.
environment config option in the same way your app determines its environment (development/staging/production). This can be using a system environment variable or some other application specific method. In the example below we’ll be using a system environment variable MY_APP_ENV to both set the app environment and only activate for the production environment.
Read More:
Front-end JavaScript
To configure AppSignal for front-end JavaScript, we recommend creating anappsignal.js file with the AppSignal config in your project’s root or src directory. Then require or import it from the app’s code before any other packages are required or imported.
In the example below, there is an appsignal.js file in the root of the applications directory. On line 8 we’ve added the namespace config option.
appsignal.js the very top of your application’s main file, like in the example below:
Read More
System Environment Variable Configuration
System environment variables, or “environment variables” for short, are variables that are accessible by processes, and are inherited from the parent process who starts them. Instead of using a configuration file for configuration, it’s possible to configure AppSignal using only environment variables. It is also possible to store config keys that contain sensitive data, such as the Push API key in an environment variable, and use config files for the rest of the config. This configuration method is compatible with Ruby, Elixir, and Node.js applications. Before moving on to the following example of setting environment variables via a shell, let’s explain how environment variables work concerning shells and processes. Environment variables can belong to a process such as a shell or your application. The commandexport FOO=BAR, for example, would set your shell’s FOO environment variable to equal BAR. Environment variables are inherited between processes, so when that shell starts a new process, that process will also have any of the shell’s environment variables.
When you launch a process in the shell (i.e., npm start) you can also provide more environment variables for only that process by assigning the variables like so: FOO=BAR npm start
For convenience, you may want to configure your shell to set certain environment variables when it starts, so that any processes started from that shell inherits those environment variables. If you’re using the bash shell, the commands in the .bash_profile file in your home directory are executed when the shell is started. If using zsh, which is the default shell in macOS, the .zshenv file would be used instead to configure environment variables.
In the example file below, we export the environment variables that configure AppSignal’s push API key and log level, so that when a new shell is started, the correct environment variables are accessible to your application, allowing it to communicate with AppSignal.
Config options set via environment variables apply to all application environments, however some config options are language specific. For example, the config option instrument_sequel only exists in the Ruby integration, because Sequel is a Ruby gem, and therefore setting the APPSIGNAL_INSTRUMENT_SEQUEL environment variable has no effect for other integrations.
~/.profileor~/.bash_profile- User specific settings. Use this location to configure environment variables per user./etc/profile- System-wide settings. If multiple users or apps use the same host machine, do not use this location.
When using system environment variable based configuration, make sure to use
the “System environment key” value from the config options table as the config
key. This key is always is capitalized* snake case, like this:
Fun Fact: this is also known as SCREAMING_SNAKE_CASE 🐍
EXAMPLE_OF_A_CONFIG_KEYFun Fact: this is also known as SCREAMING_SNAKE_CASE 🐍