Configure the Bearer Agent

The Bearer Agent allows you to update the configuration in your code using the following syntax after installing and requiring the bearer-agent gem:

Bearer.init_config do |config|
config.secret_key = "YOUR_BEARER_SECRET_KEY" # Required, string: Your Bearer private key
config.disabled = false # Optional, boolean: enable/disable Bearer globally

Available Configuration Options

The following is a list of all available configuration options.




Your Bearer Secret Key (required)


When set, the Bearer agent is disabled


Sets the name of the environment to be used in the dashboard. See below for details.


Remove sensitive data before sending it to (defaults to true)


Regular expression used for key name values to strip (see defaults)


Regular expression used for value stripping (see defaults)


Select between :prepend and :alias hook types. Learn more below (defaults to :prepend)


Sets the max recursive attempts the hook method will make. Learn more below. (defaults to 10)

For more on using the strip_sensitive_data, strip_sensitive_keys, and strip_sensitive_regex configuration properties see Keep your Data Protected.

Setting an application's environment name

Bearer uses your application's environment variable or the configuration to determine the environments that exist for an application in the Bearer Dashboard. For Ruby, Bearer will look for any of the following environment variables to determine the name:





If the config.environment is set in your agent configuration, it will override any of the above ENV names. If no environment name can be detected through environment variables or the configuration, the environment will be set to development.

What is Hook Mode?

The Bearer Agent intercepts HTTP request by hooking into the HTTP clients your application uses. This is done by replacing the HTTP methods with instrumented versions that handle its internal logic, then call the original method. When combined with some gems that use a similar approach, you may experience a BearerAgent::Interceptor::ConflictDetector::Error exception type. Hook mode helps alleviate and avoid this problem. You can read our full explaination into why this happens and the steps we've taken to resolve it over on our engineering blog, but for most users changing to the alternative mode (to :alias from the default:prepend ) should resolve any issues.

The hook_conflict_detection_max_depth setting can help if you're experiencing too many recursive retries. This shouldn't be necessary for most users, but if you're experiencing too many stack traces when a conflict error is raised, changing this value should help resolve the problem.