Class: XRay::Configuration
- Inherits:
-
Object
- Object
- XRay::Configuration
- 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
-
#context ⇒ Object
Returns the value of attribute context.
-
#emitter ⇒ Object
Returns the value of attribute emitter.
-
#logger ⇒ Logger
readonly
The global logger used across the X-Ray SDK.
-
#name ⇒ String
The default segment name.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#sampler ⇒ Object
Returns the value of attribute sampler.
-
#sampling ⇒ Object
Returns the value of attribute sampling.
-
#segment_naming ⇒ Object
Returns the value of attribute segment_naming.
-
#streamer ⇒ Object
Returns the value of attribute streamer.
Instance Method Summary collapse
- #configure(user_config) ⇒ Object
-
#context_missing=(v) ⇒ Object
proxy method to the context’s context_missing config.
-
#daemon_address=(v) ⇒ Object
setting daemon address for components communicate with X-Ray daemon.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#naming_pattern=(v) ⇒ Object
proxy method to the dynamic naming’s pattern config.
-
#sample? ⇒ Boolean
makes a sampling decision without incoming filters.
-
#sampling_rules=(v) ⇒ Object
proxy method to the sampler’s sampling rule config.
-
#stream_threshold=(v) ⇒ Object
proxy method to the streamer’s stream threshold config.
Methods included from Patcher
Constructor Details
#initialize ⇒ Configuration
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
#context ⇒ Object
Returns the value of attribute context.
121 122 123 |
# File 'lib/aws-xray-sdk/configuration.rb', line 121 def context @context end |
#emitter ⇒ Object
Returns the value of attribute emitter.
119 120 121 |
# File 'lib/aws-xray-sdk/configuration.rb', line 119 def emitter @emitter end |
#logger ⇒ Logger (readonly)
The global logger used across the X-Ray SDK.
138 139 140 |
# File 'lib/aws-xray-sdk/configuration.rb', line 138 def logger @logger end |
#name ⇒ String
Returns The default segment name.
134 135 136 |
# File 'lib/aws-xray-sdk/configuration.rb', line 134 def name @name end |
#plugins ⇒ Object
Returns the value of attribute plugins.
129 130 131 |
# File 'lib/aws-xray-sdk/configuration.rb', line 129 def plugins @plugins end |
#sampler ⇒ Object
Returns the value of attribute sampler.
123 124 125 |
# File 'lib/aws-xray-sdk/configuration.rb', line 123 def sampler @sampler end |
#sampling ⇒ Object
Returns the value of attribute sampling.
131 132 133 |
# File 'lib/aws-xray-sdk/configuration.rb', line 131 def sampling @sampling end |
#segment_naming ⇒ Object
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 |
#streamer ⇒ Object
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
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.
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 |