Module: Bigcommerce::Lightstep::Configuration

Included in:
Bigcommerce::Lightstep
Defined in:
lib/bigcommerce/lightstep/configuration.rb

Overview

General configuration for lightstep integration

Constant Summary collapse

VALID_CONFIG_KEYS =
{
  component_name: ENV.fetch('LIGHTSTEP_COMPONENT_NAME', ''),
  controller_trace_prefix: ENV.fetch('LIGHTSTEP_CONTROLLER_PREFIX', 'controllers.'),
  access_token: ENV.fetch('LIGHTSTEP_ACCESS_TOKEN', ''),
  host: ENV.fetch('LIGHTSTEP_HOST', 'lightstep-collector.linkerd'),
  interceptors: nil,
  port: ENV.fetch('LIGHTSTEP_PORT', 4_140).to_i,
  ssl_verify_peer: ENV.fetch('LIGHTSTEP_SSL_VERIFY_PEER', 1).to_i.positive?,
  open_timeout: ENV.fetch('LIGHTSTEP_OPEN_TIMEOUT', 2).to_i,
  read_timeout: ENV.fetch('LIGHTSTEP_READ_TIMEOUT', 2).to_i,
  continue_timeout: nil,
  keep_alive_timeout: ENV.fetch('LIGHTSTEP_KEEP_ALIVE_TIMEOUT', 2).to_i,
  logger: nil,
  verbosity: ENV.fetch('LIGHTSTEP_VERBOSITY', 1).to_i,
  http1_error_code: ENV.fetch('LIGHTSTEP_HTTP1_ERROR_CODE', 500).to_i,
  http1_error_code_minimum: ENV.fetch('LIGHTSTEP_HTTP1_ERROR_CODE_MINIMUM', 500).to_i,
  max_buffered_spans: ENV.fetch('LIGHTSTEP_MAX_BUFFERED_SPANS', 1_000).to_i,
  max_log_records: ENV.fetch('LIGHTSTEP_MAX_LOG_RECORDS', 1_000).to_i,
  max_reporting_interval_seconds: ENV.fetch('LIGHTSTEP_MAX_REPORTING_INTERVAL_SECONDS', 3.0).to_f,
  redis_excluded_commands: ENV.fetch('LIGHTSTEP_REDIS_EXCLUDED_COMMANDS', 'ping').to_s.split(','),
  redis_allow_root_spans: ENV.fetch('LIGHTSTEP_REDIS_ALLOW_AS_ROOT_SPAN', 0).to_i.positive?,
  active_record: ENV.fetch('LIGHTSTEP_ACTIVE_RECORD_ENABLED', 1).to_i.positive?,
  active_record_allow_root_spans: ENV.fetch('LIGHTSTEP_ACTIVE_RECORD_ALLOW_AS_ROOT_SPAN', 0).to_i.positive?,
  active_record_span_prefix: ENV.fetch('LIGHTSTEP_ACTIVE_RECORD_SPAN_PREFIX', ''),
  enabled: ENV.fetch('LIGHTSTEP_ENABLED', 1).to_i.positive?
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Whenever this is extended into a class, setup the defaults



57
58
59
# File 'lib/bigcommerce/lightstep/configuration.rb', line 57

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Bigcommerce::Instrumentation::Configuration

Yield self for ruby-style initialization

Yields:

  • (_self)

Yield Parameters:

Returns:

  • (Bigcommerce::Instrumentation::Configuration)


67
68
69
70
71
# File 'lib/bigcommerce/lightstep/configuration.rb', line 67

def configure
  reset unless @configured
  yield self
  @configured = true
end

#configured?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/bigcommerce/lightstep/configuration.rb', line 76

def configured?
  @configured
end

#environmentString

Automatically determine environment

Returns:

  • (String)


113
114
115
116
117
118
119
# File 'lib/bigcommerce/lightstep/configuration.rb', line 113

def environment
  if defined?(Rails)
    Rails.env
  else
    env['RACK_ENV'] || env['RAILS_ENV'] || 'development'
  end
end

#optionsHash

Return the current configuration options as a Hash

Returns:

  • (Hash)


85
86
87
88
89
90
91
# File 'lib/bigcommerce/lightstep/configuration.rb', line 85

def options
  opts = {}
  VALID_CONFIG_KEYS.each_key do |k|
    opts.merge!(k => send(k))
  end
  opts
end

#releaseString

Returns:

  • (String)


124
125
126
127
128
129
130
131
132
# File 'lib/bigcommerce/lightstep/configuration.rb', line 124

def release
  unless @release
    app_name = env.fetch('LIGHTSTEP_APP_NAME', env.fetch('NOMAD_JOB_NAME', '')).to_s
    sha = env.fetch('LIGHTSTEP_RELEASE_SHA', env.fetch('NOMAD_META_RELEASE_SHA', '')).to_s
    default_release = app_name.empty? && sha.empty? ? '' : "#{app_name}@#{sha}"
    @release = env.fetch('LIGHTSTEP_RELEASE', default_release).to_s
  end
  @release
end

#resetObject

Set the default configuration onto the extended class



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/bigcommerce/lightstep/configuration.rb', line 96

def reset
  VALID_CONFIG_KEYS.each do |k, v|
    send("#{k}=".to_sym, v)
  end

  default_logger = ::Logger.new($stdout)
  default_logger.level = ::Logger::INFO
  self.logger = defined?(Rails) ? Rails.logger : default_logger

  self.interceptors = ::Bigcommerce::Lightstep::Interceptors::Registry.new
end