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: '',
  controller_trace_prefix: 'controllers.',
  access_token: '',
  host: 'lightstep-collector.linkerd',
  port: 4140,
  ssl_verify_peer: true,
  open_timeout: 20,
  read_timeout: 20,
  continue_timeout: nil,
  keep_alive_timeout: 2,
  logger: nil,
  verbosity: 1,
  http1_error_code: 500,
  http1_error_code_minimum: 500,
  max_buffered_spans: 1_000,
  max_log_records: 1_000,
  max_reporting_interval_seconds: 3.0,
  redis_excluded_commands: %w(ping),
  redis_allow_root_spans: false,
  enabled: true
}.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



51
52
53
# File 'lib/bigcommerce/lightstep/configuration.rb', line 51

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)


61
62
63
64
65
# File 'lib/bigcommerce/lightstep/configuration.rb', line 61

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

#configured?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/bigcommerce/lightstep/configuration.rb', line 70

def configured?
  @configured
end

#environmentObject

Automatically determine environment



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

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)


79
80
81
82
83
84
85
# File 'lib/bigcommerce/lightstep/configuration.rb', line 79

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

#resetObject

Set the default configuration onto the extended class



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/bigcommerce/lightstep/configuration.rb', line 90

def reset
  VALID_CONFIG_KEYS.each do |k, v|
    send("#{k}=".to_sym, v)
  end
  self.component_name = ENV.fetch('LIGHTSTEP_COMPONENT_NAME', '')
  self.access_token = ENV.fetch('LIGHTSTEP_ACCESS_TOKEN', '')
  self.host = ENV.fetch('LIGHTSTEP_HOST', 'lightstep-collector.linkerd')
  self.port = ENV.fetch('LIGHTSTEP_PORT', 4140).to_i
  self.ssl_verify_peer = ENV.fetch('LIGHTSTEP_SSL_VERIFY_PEER', true)

  self.max_buffered_spans = ENV.fetch('LIGHTSTEP_MAX_BUFFERED_SPANS', 1_000).to_i
  self.max_log_records = ENV.fetch('LIGHTSTEP_MAX_LOG_RECORDS', 1_000).to_i
  self.max_reporting_interval_seconds = ENV.fetch('LIGHTSTEP_MAX_REPORTING_INTERVAL_SECONDS', 3.0).to_f

  self.verbosity = ENV.fetch('LIGHTSTEP_VERBOSITY', 1).to_i
  self.logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
  self.enabled = ENV.fetch('LIGHTSTEP_ENABLED', 1).to_i > 0
end