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',
  interceptors: nil,
  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



54
55
56
# File 'lib/bigcommerce/lightstep/configuration.rb', line 54

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)


64
65
66
67
68
# File 'lib/bigcommerce/lightstep/configuration.rb', line 64

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

#configured?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/bigcommerce/lightstep/configuration.rb', line 73

def configured?
  @configured
end

#environmentObject

Automatically determine environment



116
117
118
119
120
121
122
# File 'lib/bigcommerce/lightstep/configuration.rb', line 116

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)


82
83
84
85
86
87
88
# File 'lib/bigcommerce/lightstep/configuration.rb', line 82

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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bigcommerce/lightstep/configuration.rb', line 93

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.positive?
  self.interceptors = ::Bigcommerce::Lightstep::Interceptors::Registry.new
end