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

Returns a new instance of Configuration.



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

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.



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

def context
  @context
end

#emitterObject

Returns the value of attribute emitter.



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

def emitter
  @emitter
end

#loggerLogger (readonly)

The global logger used across the X-Ray SDK.

Returns:

  • (Logger)


138
139
140
# File 'lib/aws-xray-sdk/configuration.rb', line 138

def logger
  @logger
end

#nameString

Returns The default segment name.

Returns:

  • (String)

    The default segment name.



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

def name
  @name
end

#pluginsObject

Returns the value of attribute plugins.



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

def plugins
  @plugins
end

#samplerObject

Returns the value of attribute sampler.



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

def sampler
  @sampler
end

#samplingObject

Returns the value of attribute sampling.



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

def sampling
  @sampling
end

#segment_namingObject

Returns the value of attribute segment_naming.



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

def segment_naming
  @segment_naming
end

#streamerObject

Returns the value of attribute streamer.



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

def streamer
  @streamer
end

Instance Method Details

#configure(user_config) ⇒ Object

Parameters:

  • user_config (Hash)

    The user configuration overrides.

Raises:



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
115
116
117
# File 'lib/aws-xray-sdk/configuration.rb', line 77

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.



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

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

#daemon_address=(v) ⇒ Object

setting daemon address for components communicate with X-Ray daemon.



43
44
45
46
47
48
# File 'lib/aws-xray-sdk/configuration.rb', line 43

def daemon_address=(v)
  v = ENV[DaemonConfig::DAEMON_ADDRESS_KEY] || v
  config = DaemonConfig.new(addr: v)
  emitter.daemon_config = config
  sampler.daemon_config = config if sampler.respond_to?(:daemon_config=)
end

#naming_pattern=(v) ⇒ Object

proxy method to the dynamic naming’s pattern config.



66
67
68
# File 'lib/aws-xray-sdk/configuration.rb', line 66

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

#sample?Boolean

makes a sampling decision without incoming filters.

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/aws-xray-sdk/configuration.rb', line 71

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

#sampling_rules=(v) ⇒ Object

proxy method to the sampler’s sampling rule config.



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

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

#stream_threshold=(v) ⇒ Object

proxy method to the streamer’s stream threshold config.



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

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