class Atatus::Config

@api private

Constants

DEPRECATED_OPTIONS

Attributes

__root_path[RW]
__view_paths[RW]
logger[RW]
options[R]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source

rubocop:enable Metrics/LineLength, Layout/ExtraSpacing

# File lib/atatus/config.rb, line 102
def initialize(options = {})
  @options = load_schema

  assign(options)

  # Pick out config_file specifically as we need it now to load it,
  # but still need the other env vars to have precedence
  env = load_env
  if (env_config_file = env.delete(:config_file))
    self.config_file = env_config_file
  end

  assign(load_config_file)
  assign(env)

  yield self if block_given?

  self.logger ||= build_logger

  @__view_paths ||= []
  @__root_path ||= Dir.pwd
end

Public Instance Methods

active() click to toggle source
# File lib/atatus/config.rb, line 264
def active
  enabled
end
Also aliased as: active?
active=(value) click to toggle source
# File lib/atatus/config.rb, line 280
def active=(value)
  warn '[DEPRECATED] The option active has been renamed to enabled ' \
    'to align with other agents and with the remote config.'
  self.enabled = value
end
active?()
Alias for: active
app=(app) click to toggle source
# File lib/atatus/config.rb, line 177
def app=(app)
  case app_type?(app)
  when :sinatra
    set_sinatra(app)
  when :rails
    set_rails(app)
  else
    self.service_name = 'ruby'
  end
end
assign(update) click to toggle source
# File lib/atatus/config.rb, line 130
def assign(update)
  return unless update
  update.each { |key, value| send(:"#{key}=", value) }
end
available_instrumentations() click to toggle source
# File lib/atatus/config.rb, line 135
def available_instrumentations
  %w[
    action_dispatch
    delayed_job
    dynamo_db
    elasticsearch
    faraday
    http
    json
    mongo
    net_http
    rake
    redis
    resque
    sequel
    shoryuken
    sidekiq
    sinatra
    sneakers
    sucker_punch
    tilt
  ]
end
collect_metrics?() click to toggle source
# File lib/atatus/config.rb, line 192
def collect_metrics?
  metrics_interval > 0
end
custom_key_filters=(value) click to toggle source
# File lib/atatus/config.rb, line 251
def custom_key_filters=(value)
  unless value == self.class.schema[:custom_key_filters][:default]
    warn '[DEPRECATED] The option custom_key_filters is being removed. ' \
      'See sanitize_field_names for an alternative.'
  end

  set(:custom_key_filters, value)
end
default_tags=(value) click to toggle source

Deprecations

# File lib/atatus/config.rb, line 236
def default_tags=(value)
  warn '[DEPRECATED] The option default_tags has been renamed to ' \
    'default_labels.'
  self.default_labels = value
end
disabled_instrumentations() click to toggle source
# File lib/atatus/config.rb, line 260
def disabled_instrumentations
  disable_instrumentations
end
disabled_instrumentations=(value) click to toggle source
# File lib/atatus/config.rb, line 269
def disabled_instrumentations=(value)
  warn '[DEPRECATED] The option disabled_instrumentations has been ' \
    'renamed to disable_instrumentations to align with other agents.'
  self.disable_instrumentations = value
end
enabled_instrumentations() click to toggle source
# File lib/atatus/config.rb, line 159
def enabled_instrumentations
  available_instrumentations - disable_instrumentations
end
ignore_url_patterns=(value) click to toggle source
# File lib/atatus/config.rb, line 242
def ignore_url_patterns=(value)
  unless value == self.class.schema[:ignore_url_patterns][:default]
    warn '[DEPRECATED] The option ignore_url_patterns is being removed. ' \
      'Consider using transaction_ignore_urls instead.'
  end

  set(:ignore_url_patterns, value)
end
inspect() click to toggle source
Calls superclass method
# File lib/atatus/config.rb, line 230
def inspect
  super.split.first + '>'
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/atatus/config.rb, line 163
def method_missing(name, *args)
  return super unless DEPRECATED_OPTIONS.include?(name)
  warn "The option `#{name}' has been removed."
end
replace_options(new_options) click to toggle source
# File lib/atatus/config.rb, line 168
def replace_options(new_options)
  return if new_options.nil? || new_options.empty?
  options_copy = @options.dup
  new_options.each do |key, value|
    options_copy.fetch(key.to_sym).set(value)
  end
  @options = options_copy
end
span_frames_min_duration=(value) click to toggle source
Calls superclass method
# File lib/atatus/config.rb, line 200
def span_frames_min_duration=(value)
  super
  @span_frames_min_duration_us = nil
end
span_frames_min_duration?() click to toggle source
# File lib/atatus/config.rb, line 196
def span_frames_min_duration?
  span_frames_min_duration != 0
end
span_frames_min_duration_us() click to toggle source
# File lib/atatus/config.rb, line 205
def span_frames_min_duration_us
  @span_frames_min_duration_us ||= span_frames_min_duration * 1_000_000
end
ssl_context() click to toggle source
# File lib/atatus/config.rb, line 209
def ssl_context
  return unless use_ssl?

  @ssl_context ||=
    OpenSSL::SSL::SSLContext.new.tap do |context|
      if server_ca_cert
        context.ca_file = server_ca_cert
      else
        context.cert_store =
          OpenSSL::X509::Store.new.tap(&:set_default_paths)
      end

      context.verify_mode =
        if verify_server_cert
          OpenSSL::SSL::VERIFY_PEER
        else
          OpenSSL::SSL::VERIFY_NONE
        end
    end
end
use_experimental_sql_parser=(value) click to toggle source
# File lib/atatus/config.rb, line 275
def use_experimental_sql_parser=(value)
  warn '[DEPRECATED] The new SQL parser is now the default. To use the old one, '
    'use use_legacy_sql_parser and please report why you wish to do so.'
end
use_ssl?() click to toggle source
# File lib/atatus/config.rb, line 188
def use_ssl?
  server_url.start_with?('https')
end

Private Instance Methods

app_type?(app) click to toggle source
# File lib/atatus/config.rb, line 309
def app_type?(app)
  if defined?(::Rails::Application) && app.is_a?(::Rails::Application)
    return :rails
  end

  if app.is_a?(Class) && app.superclass.to_s == 'Sinatra::Base'
    return :sinatra
  end

  nil
end
build_logger() click to toggle source
# File lib/atatus/config.rb, line 303
def build_logger
  Logger.new(log_path == '-' ? STDOUT : log_path).tap do |logger|
    logger.level = log_level
  end
end
format_name(str) click to toggle source
# File lib/atatus/config.rb, line 346
def format_name(str)
  str&.gsub('::', '_')
end
load_config_file() click to toggle source
# File lib/atatus/config.rb, line 288
def load_config_file
  return unless File.exist?(config_file)

  read = File.read(config_file)
  evaled = ERB.new(read).result
  YAML.safe_load(evaled)
end
load_env() click to toggle source
# File lib/atatus/config.rb, line 296
def load_env
  @options.values.each_with_object({}) do |option, opts|
    next unless (value = ENV[option.env_key])
    opts[option.key] = value
  end
end
rails_app_name(app) click to toggle source
# File lib/atatus/config.rb, line 338
def rails_app_name(app)
  if ::Rails::VERSION::MAJOR >= 6
    app.class.module_parent_name
  else
    app.class.parent_name
  end
end
set_rails(app) click to toggle source
# File lib/atatus/config.rb, line 328
def set_rails(app)
  self.service_name ||= format_name(service_name || rails_app_name(app))
  self.framework_name ||= 'Rails'
  self.framework_version ||= ::Rails::VERSION::STRING
  self.logger ||= ::Rails.logger

  self.__root_path = ::Rails.root.to_s
  self.__view_paths = app.config.paths['app/views'].existent + [::Rails.root.to_s]
end
set_sinatra(app) click to toggle source
# File lib/atatus/config.rb, line 321
def set_sinatra(app)
  self.service_name = format_name(service_name || app.to_s)
  self.framework_name = framework_name || 'Sinatra'
  self.framework_version = framework_version || ::Sinatra::VERSION
  self.__root_path = Dir.pwd
end