class Binnacle::Configuration

Constants

DEFAULT_BACKTRACE_FILTERS
DEFAULT_IGNORED_EXCEPTIONS
DEFAULT_PORT

Attributes

api_key[RW]

An approved publisher API key for the App (BINNACLE_API_KEY)

api_secret[RW]

The API secret for the given API key (BINNACLE_API_SECRET)

asynch_logging[RW]

Whether to log asynchronoushly via the Ruby logger

encrypted[R]

Whether to make the requests over HTTPS, default is HTTPS

endpoint[RW]

The Binnacle Endpoint (BINNACLE_ENDPOINT) single IP or Array of IPs

error_channel[RW]

The application error Binnacle Channel (BINNACLE_APP_ERR_CHANNEL)

ignore_actions[W]

Array of Events to skip, e.g. ['home#index', 'webhooks#test']

ignore_cascade_pass[RW]

Whether to skip reporting exceptions where the headers is set to 'pass'. In Rails typically it means route was not found (404 error).

ignored_exceptions[RW]

Exceptions that do not get reported to Binnacle (BINNACLE_IGNORED_EXCEPTIONS)

intercept_rails_logging[RW]

Whether to redirect rails logging to Binnacle (BINNACLE_RAILS_LOG)

log_binnacle_signals[RW]
logging_channel[RW]

The application logger Binnacle Channel (BINNACLE_APP_LOG_CHANNEL)

port[RW]

The Binnacle Endpoint PORT (BINNACLE_PORT), defaults to 8080 if not encrypted

rails_verbose_logging[RW]

Whether to pipe Rails logs as they are (verbose as shit) or just grab action_controller events and single line them (BINNACLE_RAILS_LOG_VERBOSE)

report_exceptions[RW]

Whether to report exceptions to Binnacle (BINNACLE_REPORT_EXCEPTIONS)

url_blacklist_pattern[R]
url_blacklist_patterns[RW]
url_whitelist_pattern[R]
url_whitelist_patterns[RW]

HTTP outgoing logging options

Public Class Methods

new() click to toggle source
# File lib/binnacle/configuration.rb, line 80
def initialize
  if ENV['BINNACLE_ENDPOINT']
    self.endpoint    ||= ENV['BINNACLE_ENDPOINT'].include?(',') ? ENV['BINNACLE_ENDPOINT'].split(',') : ENV['BINNACLE_ENDPOINT']
  else
    if self.endpoint !~ /[^[:space:]]/
      self.endpoint = (1..6).to_a.sample(3).map { |n| "api#{n}.binnacle-api.io" }
    end
  end

  self.logging_channel ||= ENV['BINNACLE_APP_LOG_CHANNEL']
  self.error_channel   ||= ENV['BINNACLE_APP_ERR_CHANNEL']
  self.api_key     ||= ENV['BINNACLE_API_KEY']
  self.api_secret  ||= ENV['BINNACLE_API_SECRET']
  self.intercept_rails_logging = Configuration.set_boolean_flag_for(ENV['BINNACLE_RAILS_LOG'])
  self.rails_verbose_logging = Configuration.set_boolean_flag_for(ENV['BINNACLE_RAILS_LOG_VERBOSE'])
  self.report_exceptions = Configuration.set_boolean_flag_for(ENV['BINNACLE_REPORT_EXCEPTIONS'])
  self.ignored_exceptions ||= ENV['BINNACLE_IGNORED_EXCEPTIONS'] ? DEFAULT_IGNORED_EXCEPTIONS + ENV['BINNACLE_IGNORED_EXCEPTIONS'].split(',') : DEFAULT_IGNORED_EXCEPTIONS
  self.ignore_cascade_pass     ||= true
  self.asynch_logging = Configuration.set_boolean_flag_for(ENV['BINNACLE_RAILS_LOG_ASYNCH'], true)
  @encrypted = Configuration.set_boolean_flag_for(ENV['BINNACLE_ENCRYPTED'], true)

  self.url_whitelist_patterns ||= ENV['BINNACLE_HTTP_LOGGING_WHITELIST'] ? ENV['BINNACLE_HTTP_LOGGING_WHITELIST'].split(',') : []
  self.url_blacklist_patterns ||= ENV['BINNACLE_HTTP_LOGGING_BLACKLIST'] ? ENV['BINNACLE_HTTP_LOGGING_BLACKLIST'].split(',') : []
  @url_whitelist_pattern = /.*/
  @url_blacklist_pattern = nil

  self.log_binnacle_signals = Configuration.set_boolean_flag_for(ENV['BINNACLE_LOG_SIGNALS'])

  prepare!
end
set_boolean_flag_for(value, default = false) click to toggle source
# File lib/binnacle/configuration.rb, line 234
def self.set_boolean_flag_for(value, default = false)
  !value.nil? ? value.downcase == 'true' : default
end

Public Instance Methods

build_url(ip_or_host) click to toggle source
# File lib/binnacle/configuration.rb, line 160
def build_url(ip_or_host)
  ["#{protocol}://#{ip_or_host}", port].compact.join(":")
end
can_setup_logger?() click to toggle source
# File lib/binnacle/configuration.rb, line 136
def can_setup_logger?
  !self.logging_channel.nil?
end
encrypted=(value) click to toggle source
# File lib/binnacle/configuration.rb, line 214
def encrypted=(value)
  @encrypted = value
  set_default_port
  set_urls
end
encrypted?() click to toggle source
# File lib/binnacle/configuration.rb, line 156
def encrypted?
  self.encrypted
end
endpoint=(value) click to toggle source
# File lib/binnacle/configuration.rb, line 209
def endpoint=(value)
  @endpoint = value
  set_urls
end
ignore(test) click to toggle source
# File lib/binnacle/configuration.rb, line 265
def ignore(test)
  ignore_tests.push(test) if test
end
ignore?(event) click to toggle source
# File lib/binnacle/configuration.rb, line 273
def ignore?(event)
  ignore_tests.any? { |ignore_test| ignore_test.call(event) }
end
ignore_actions(actions) click to toggle source

Set conditions for events that should be ignored

Currently supported formats are:

- A single string representing a controller action, e.g. 'users#sign_in'
- An array of strings representing controller actions
- An object that responds to call with an event argument and returns
  true if the event should be ignored.

The action ignores are given to 'ignore_actions'. The callable ignores are given to 'ignore'. Both methods can be called multiple times, which just adds more ignore conditions to a list that is checked before logging.

# File lib/binnacle/configuration.rb, line 254
def ignore_actions(actions)
  ignore(lamba do |event|
    params = event.payload[:params]
    Array(actions).include?("#{params['controller']}##{params['action']}")
  end)
end
ignore_cascade_pass?() click to toggle source
# File lib/binnacle/configuration.rb, line 152
def ignore_cascade_pass?
  self.ignore_cascade_pass
end
ignore_nothing() click to toggle source
# File lib/binnacle/configuration.rb, line 269
def ignore_nothing
  @ignore_tests = []
end
ignore_tests() click to toggle source
# File lib/binnacle/configuration.rb, line 261
def ignore_tests
  @ignore_tests ||= []
end
intercept_rails_logging?() click to toggle source
# File lib/binnacle/configuration.rb, line 140
def intercept_rails_logging?
  self.intercept_rails_logging && !self.logging_channel.nil?
end
prepare!() click to toggle source
# File lib/binnacle/configuration.rb, line 111
def prepare!
  set_default_port
  set_urls
  set_blacklist_patterns
  set_whitelist_patterns
end
protocol() click to toggle source
# File lib/binnacle/configuration.rb, line 164
def protocol
  self.encrypted? ? 'https' : 'http'
end
rails_verbose_logging?() click to toggle source
# File lib/binnacle/configuration.rb, line 144
def rails_verbose_logging?
  self.rails_verbose_logging
end
ready?() click to toggle source
# File lib/binnacle/configuration.rb, line 128
def ready?
  urls? && self.api_key && self.api_secret
end
set_blacklist_patterns() click to toggle source
# File lib/binnacle/configuration.rb, line 174
def set_blacklist_patterns
  blacklist_patterns = []

  # don't log binnacle's posts
  unless self.log_binnacle_signals
    if @urls.is_a?(Array)
      @urls.each do |url|
        blacklist_patterns << /#{url}/ if url
      end
    elsif @urls
      blacklist_patterns << /#{@urls}/
    end
  end

  self.url_blacklist_patterns.each do |pattern|
    blacklist_patterns << pattern
  end

  unless blacklist_patterns.empty?
    @url_blacklist_pattern = Regexp.union(blacklist_patterns)
  end
end
set_default_port() click to toggle source
# File lib/binnacle/configuration.rb, line 238
def set_default_port
  self.port ||= ENV['BINNACLE_PORT'] || (self.encrypted? ? nil : DEFAULT_PORT)
end
set_urls() click to toggle source
# File lib/binnacle/configuration.rb, line 168
def set_urls
  if self.endpoint && (self.endpoint.is_a?(Array) ? !self.endpoint.empty? : (!self.endpoint !~ /[^[:space:]]/))
    @urls = self.endpoint.is_a?(Array) ? self.endpoint.map { |ep| build_url(ep) } : build_url(endpoint)
  end
end
set_whitelist_patterns() click to toggle source
# File lib/binnacle/configuration.rb, line 197
def set_whitelist_patterns
  whitelist_patterns = []

  self.url_whitelist_patterns.each do |pattern|
    whitelist_patterns << pattern
  end

  unless whitelist_patterns.empty?
    @whitelist_pattern = Regexp.union(whitelist_patterns)
  end
end
to_s() click to toggle source
# File lib/binnacle/configuration.rb, line 220
def to_s
  [ :endpoint,
    :logging_channel,
    :error_channel,
    :api_key,
    :api_secret,
    :intercept_rails_logging,
    :report_exceptions,
    :ignore_cascade_pass,
    :encrypted,
    :asynch_logging
  ].map { |m| "#{m}: #{self.send(m)}" }.join(', ')
end
trap?() click to toggle source
# File lib/binnacle/configuration.rb, line 148
def trap?
  !self.report_exceptions.nil? && !self.error_channel.nil?
end
url() click to toggle source
# File lib/binnacle/configuration.rb, line 118
def url
  if @urls
    @urls.is_a?(Array) ? @urls.sample : @urls
  end
end
urls() click to toggle source
# File lib/binnacle/configuration.rb, line 124
def urls
  @urls
end
urls?() click to toggle source
# File lib/binnacle/configuration.rb, line 132
def urls?
  (!@urls.nil? && !@urls.is_a?(Array)) || (@urls.is_a?(Array) && !@urls.empty?)
end