Class: Bigcommerce::Lightstep::Interceptors::Env

Inherits:
Base
  • Object
show all
Defined in:
lib/bigcommerce/lightstep/interceptors/env.rb

Overview

Hydrates span tags with specified ENV vars

Constant Summary collapse

PRESET_NOMAD =
{
  'container.cpu': 'NOMAD_CPU_LIMIT',
  'container.mem': 'NOMAD_MEMORY_LIMIT',
  'git.sha': 'NOMAD_META_SHA',
  'nomad.task_name': 'NOMAD_TASK_NAME',
  'provider.region': 'NOMAD_REGION',
  'provider.datacenter': 'NOMAD_DC'
}.freeze
PRESET_HOSTNAME =
{
  'hostname': 'HOSTNAME',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(keys: nil, env: nil, presets: []) ⇒ Env

Returns a new instance of Env.

Parameters:

  • keys (Hash) (defaults to: nil)

    A hash of span->env key mappings

  • env (ENV) (defaults to: nil)

    The ENV class to get variables from

  • presets (Array<Symbol>) (defaults to: [])

    Specify presets that automatically setup keys



43
44
45
46
47
48
# File 'lib/bigcommerce/lightstep/interceptors/env.rb', line 43

def initialize(keys: nil, env: nil, presets: [])
  @keys = keys || {}
  @presets = presets || []
  @env = env || ENV
  augment_keys_with_presets!
end

Instance Method Details

#call(span:) {|span| ... } ⇒ Object

Parameters:

  • span (::LightStep::Span)

Yields:

  • (span)


53
54
55
56
57
58
59
60
# File 'lib/bigcommerce/lightstep/interceptors/env.rb', line 53

def call(span:)
  @keys.each do |span_key, env_key|
    value = @env.fetch(env_key.to_s, nil)
    span.set_tag(span_key.to_s.downcase.tr('-', '_').strip, value.nil? ? '' : value)
  end

  yield span
end