Class: XRay::Configuration

Inherits:
Object
  • Object
show all
Includes:
Patcher
Defined in:
lib/aws-xray-sdk/configuration.rb

Overview

This class stores all configurations for X-Ray recorder and should be initialized only once.

Constant Summary collapse

SEGMENT_NAME_KEY =
'AWS_XRAY_TRACING_NAME'.freeze
CONFIG_KEY =
I[logger name sampling plugins daemon_address segment_naming
naming_pattern emitter streamer context context_missing
sampling_rules stream_threshold patch].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Patcher

#patch

Constructor Details

#initializeConfiguration



24
25
26
27
28
29
30
31
32
33
# File 'lib/aws-xray-sdk/configuration.rb', line 24

def initialize
  @name = ENV[SEGMENT_NAME_KEY]
  @sampling = true
  @emitter = DefaultEmitter.new
  @context = DefaultContext.new
  @sampler = DefaultSampler.new
  @streamer = DefaultStreamer.new
  @segment_naming = DynamicNaming.new fallback: @name
  @plugins = []
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



118
119
120
# File 'lib/aws-xray-sdk/configuration.rb', line 118

def context
  @context
end

#emitterObject

Returns the value of attribute emitter.



116
117
118
# File 'lib/aws-xray-sdk/configuration.rb', line 116

def emitter
  @emitter
end

#loggerLogger (readonly)

The global logger used across the X-Ray SDK.



135
136
137
# File 'lib/aws-xray-sdk/configuration.rb', line 135

def logger
  @logger
end

#nameString



131
132
133
# File 'lib/aws-xray-sdk/configuration.rb', line 131

def name
  @name
end

#pluginsObject

Returns the value of attribute plugins.



126
127
128
# File 'lib/aws-xray-sdk/configuration.rb', line 126

def plugins
  @plugins
end

#samplerObject

Returns the value of attribute sampler.



120
121
122
# File 'lib/aws-xray-sdk/configuration.rb', line 120

def sampler
  @sampler
end

#samplingObject

Returns the value of attribute sampling.



128
129
130
# File 'lib/aws-xray-sdk/configuration.rb', line 128

def sampling
  @sampling
end

#segment_namingObject

Returns the value of attribute segment_naming.



124
125
126
# File 'lib/aws-xray-sdk/configuration.rb', line 124

def segment_naming
  @segment_naming
end

#streamerObject

Returns the value of attribute streamer.



122
123
124
# File 'lib/aws-xray-sdk/configuration.rb', line 122

def streamer
  @streamer
end

Instance Method Details

#configure(user_config) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/aws-xray-sdk/configuration.rb', line 74

def configure(user_config)
  raise InvalidConfigurationError.new('User config must be a Hash.') unless user_config.is_a?(Hash)
  return if user_config.empty?

  user_config.each_key do |key|
    case key
    when :logger
      XRay::Logging.logger = user_config[key]
    when :name
      self.name = user_config[key]
    when :context
      self.context = user_config[key]
    when :context_missing
      self.context_missing = user_config[key]
    when :sampler
      self.sampler = user_config[key]
    when :sampling_rules
      self.sampling_rules = user_config[key]
    when :sampling
      self.sampling = user_config[key]
    when :emitter
      self.emitter = user_config[key]
    when :daemon_address
      self.daemon_address = user_config[key]
    when :segment_naming
      self.segment_naming = user_config[key]
    when :naming_pattern
      self.naming_pattern = user_config[key]
    when :streamer
      self.streamer = user_config[key]
    when :stream_threshold
      self.stream_threshold = user_config[key]
    when :plugins
      self.plugins = load_plugins(user_config[key])
    when :patch
      patch(user_config[key])
    else
      raise InvalidConfigurationError.new(%(Invalid config key #{key}.))
    end
  end
end

#context_missing=(v) ⇒ Object

proxy method to the context’s context_missing config.



47
48
49
# File 'lib/aws-xray-sdk/configuration.rb', line 47

def context_missing=(v)
  context.context_missing = v
end

#daemon_address=(v) ⇒ Object

proxy method to the emitter’s daemon_address config.



42
43
44
# File 'lib/aws-xray-sdk/configuration.rb', line 42

def daemon_address=(v)
  emitter.daemon_address = v
end

#naming_pattern=(v) ⇒ Object

proxy method to the dynamic naming’s pattern config.



62
63
64
# File 'lib/aws-xray-sdk/configuration.rb', line 62

def naming_pattern=(v)
  segment_naming.pattern = v
end

#sample?Boolean

makes a sampling decision based on internal configure, e.g.

if sampling enabled and the default sampling rule.


68
69
70
71
# File 'lib/aws-xray-sdk/configuration.rb', line 68

def sample?
  return true unless sampling
  sampler.sample?
end

#sampling_rules=(v) ⇒ Object

proxy method to the sampler’s sampling rule config.



52
53
54
# File 'lib/aws-xray-sdk/configuration.rb', line 52

def sampling_rules=(v)
  sampler.sampling_rules = v
end

#stream_threshold=(v) ⇒ Object

proxy method to the streamer’s stream threshold config.



57
58
59
# File 'lib/aws-xray-sdk/configuration.rb', line 57

def stream_threshold=(v)
  streamer.stream_threshold = v
end