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.node.id': 'NOMAD_NODE_ID',
  'nomad.node.name': 'NOMAD_NODE_NAME',
  '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



45
46
47
48
49
50
51
52
# File 'lib/bigcommerce/lightstep/interceptors/env.rb', line 45

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

Instance Method Details

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

Parameters:

  • span (::LightStep::Span)

Yields:

  • (span)


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bigcommerce/lightstep/interceptors/env.rb', line 57

def call(span:)
  return yield span unless root_span?(span)

  value_mutex do
    @values.each do |span_key, value|
      span.set_tag(span_key, value)
    end
  end

  yield span
end