Skip to main content

Ruby SDK Configuration

Complete reference for all configuration options.

Configuration Block

config/initializers/brainzlab.rb
BrainzLab.configure do |config|
  # Your configuration here
end

Authentication

OptionTypeDescription
secret_keyStringRequired. Your API key from the dashboard
config.secret_key = ENV['BRAINZLAB_SECRET_KEY']

Environment Settings

OptionTypeDefaultDescription
environmentStringRails.envEnvironment name
serviceStringApp nameService/application name
hostStringHostnameServer hostname
commitStringAuto-detectedGit commit SHA
branchStringAuto-detectedGit branch name
config.environment = Rails.env
config.service = 'my-rails-app'
config.host = Socket.gethostname
config.commit = ENV['GIT_COMMIT']
config.branch = ENV['GIT_BRANCH']

Recall Settings

OptionTypeDefaultDescription
recall_enabledBooleantrueEnable/disable logging
recall_min_levelSymbol:debugMinimum log level
recall_buffer_sizeInteger50Logs to buffer before flush
recall_flush_intervalInteger5Seconds between flushes
recall_urlStringCloud URLRecall server URL
config.recall_enabled = true
config.recall_min_level = :info  # :debug, :info, :warn, :error, :fatal
config.recall_buffer_size = 100
config.recall_flush_interval = 3

Log Levels

LevelValueUse Case
:debug0Detailed debugging info
:info1General information
:warn2Warning conditions
:error3Error conditions
:fatal4Critical errors

Reflex Settings

OptionTypeDefaultDescription
reflex_enabledBooleantrueEnable/disable error tracking
reflex_excluded_exceptionsArray[]Exceptions to ignore
reflex_sample_rateFloatnilSample rate (0.0-1.0), nil = 100%
reflex_before_sendProcnilCallback to modify/drop errors
reflex_urlStringCloud URLReflex server URL
config.reflex_enabled = true
config.reflex_excluded_exceptions = [
  'ActionController::RoutingError',
  'ActionController::InvalidAuthenticityToken',
  'ActiveRecord::RecordNotFound'
]
config.reflex_sample_rate = 0.5  # 50% of errors

Pulse Settings

OptionTypeDefaultDescription
pulse_enabledBooleantrueEnable/disable APM
pulse_sample_rateFloatnilSample rate (0.0-1.0), nil = 100%
pulse_buffer_sizeInteger50Traces to buffer before flush
pulse_flush_intervalInteger5Seconds between flushes
pulse_excluded_pathsArray['/health', '/ping']Paths to exclude from tracing
pulse_urlStringCloud URLPulse server URL
config.pulse_enabled = true
config.pulse_sample_rate = 1.0  # 100% of requests
config.pulse_excluded_paths = ['/health', '/ping', '/up', '/assets']

Instrumentation

Control which libraries are automatically instrumented:
OptionTypeDefaultDescription
instrument_httpBooleantrueNet::HTTP, Faraday, HTTParty
instrument_active_recordBooleantrueSQL queries
instrument_redisBooleantrueRedis commands
instrument_sidekiqBooleantrueSidekiq jobs
instrument_delayed_jobBooleantrueDelayed::Job
instrument_graphqlBooleantrueGraphQL queries
instrument_mongodbBooleantrueMongoDB operations
instrument_elasticsearchBooleantrueElasticsearch queries
instrument_action_mailerBooleantrueEmail delivery
instrument_grapeBooleantrueGrape API
# Disable specific instrumentations
config.instrument_redis = false
config.instrument_sidekiq = false

# Filter specific hosts/commands
config.http_ignore_hosts = ['localhost', '127.0.0.1']
config.redis_ignore_commands = ['ping', 'info']

Data Scrubbing

OptionTypeDefaultDescription
scrub_fieldsArrayCommon fieldsFields to scrub from logs/errors
config.scrub_fields = [
  :password,
  :password_confirmation,
  :credit_card,
  :cvv,
  :ssn,
  /token/i,
  /secret/i,
  /key/i
]

Callbacks

Before Send (Reflex)

Filter or modify errors before sending:
config.reflex_before_send = ->(payload, exception) {
  # Return nil to drop the event
  return nil if exception&.message&.include?("expected")

  # Add custom data
  payload[:tags] ||= {}
  payload[:tags][:custom] = "value"

  # Return the modified payload
  payload
}

Context Builder

Add custom context to all logs:
config.recall_context_builder = -> {
  {
    tenant_id: Current.tenant&.id,
    request_id: Current.request_id
  }
}

Environment-Specific Configuration

BrainzLab.configure do |config|
  config.secret_key = ENV['BRAINZLAB_SECRET_KEY']

  case Rails.env
  when 'development'
    config.recall_min_level = :debug
    config.recall_flush_interval = 1

  when 'test'
    config.recall_enabled = false
    config.reflex_enabled = false

  when 'production'
    config.recall_min_level = :info
    config.recall_buffer_size = 100
  end
end