Module: OboeBase
Overview
This module is the base module for the various implementations of Oboe reporting. Current variations as of 2014-09-10 are a c-extension, JRuby (using TraceView Java instrumentation) and a Heroku c-extension (with embedded tracelyzer)
Instance Attribute Summary collapse
-
#loaded ⇒ Object
Returns the value of attribute loaded.
-
#reporter ⇒ Object
Returns the value of attribute reporter.
Class Method Summary collapse
-
.extended(cls) ⇒ Object
extended.
Instance Method Summary collapse
-
#always? ⇒ Boolean
Returns true if the tracing_mode is set to always.
-
#forking_webserver? ⇒ Boolean
Determines if we are running under a forking webserver.
-
#framework? ⇒ Boolean
Indicates whether a supported framework is in use or not.
- #heroku? ⇒ Boolean
- #log(_layer, _label, _options = {}) ⇒ Object
-
#never? ⇒ Boolean
Returns true if the tracing_mode is set to never.
-
#passthrough? ⇒ Boolean
Returns true if the tracing_mode is set to always or through.
-
#pickup_context?(xtrace) ⇒ Boolean
pickup_context.
-
#sample?(_opts = {}) ⇒ Boolean
These methods should be implemented by the descendants (Oboe_metal, Oboe_metal (JRuby), Heroku_metal).
- #set_sample_rate(_rate) ⇒ Object
- #set_tracing_mode(_mode) ⇒ Object
-
#through? ⇒ Boolean
Returns true if the tracing_mode is set to through.
-
#tracing? ⇒ Boolean
Returns true if we are currently tracing a request False otherwise.
-
#tracing_layer?(layer) ⇒ Boolean
tracing_layer?.
-
#tracing_layer_op?(operation) ⇒ Boolean
tracing_layer_op?.
Methods included from Oboe::ThreadLocal
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
33 34 35 |
# File 'lib/oboe/base.rb', line 33 def loaded @loaded end |
#reporter ⇒ Object
Returns the value of attribute reporter.
32 33 34 |
# File 'lib/oboe/base.rb', line 32 def reporter @reporter end |
Class Method Details
.extended(cls) ⇒ Object
extended
Invoked when this module is extended. e.g. extend OboeBase
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/oboe/base.rb', line 70 def self.extended(cls) cls.loaded = true # This gives us pretty accessors with questions marks at the end # e.g. is_continued_trace --> is_continued_trace? Oboe.methods.select{ |m| m =~ /^is_|^has_/ }.each do |c| unless c =~ /\?$|=$/ # Oboe.logger.debug "aliasing #{c}? to #{c}" alias_method "#{c}?", c end end end |
Instance Method Details
#always? ⇒ Boolean
Returns true if the tracing_mode is set to always. False otherwise
135 136 137 |
# File 'lib/oboe/base.rb', line 135 def always? Oboe::Config[:tracing_mode].to_s == 'always' end |
#forking_webserver? ⇒ Boolean
Determines if we are running under a forking webserver
185 186 187 188 189 190 191 192 |
# File 'lib/oboe/base.rb', line 185 def forking_webserver? if (defined?(::Unicorn) && ($PROGRAM_NAME =~ /unicorn/i)) || (defined?(::Puma) && ($PROGRAM_NAME =~ /puma/i)) true else false end end |
#framework? ⇒ Boolean
Indicates whether a supported framework is in use or not
198 199 200 |
# File 'lib/oboe/base.rb', line 198 def framework? defined?(::Rails) or defined?(::Sinatra) or defined?(::Padrino) or defined?(::Grape) end |
#heroku? ⇒ Boolean
178 179 180 |
# File 'lib/oboe/base.rb', line 178 def heroku? ENV.key?('TRACEVIEW_URL') end |
#log(_layer, _label, _options = {}) ⇒ Object
173 174 175 176 |
# File 'lib/oboe/base.rb', line 173 def log(layer, label, = {}) # WARN: Oboe.log will be deprecated in a future release. Please use Oboe::API.log instead. Oboe::API.log(layer, label, ) end |
#never? ⇒ Boolean
Returns true if the tracing_mode is set to never. False otherwise
143 144 145 |
# File 'lib/oboe/base.rb', line 143 def never? Oboe::Config[:tracing_mode].to_s == 'never' end |
#passthrough? ⇒ Boolean
Returns true if the tracing_mode is set to always or through. False otherwise
151 152 153 |
# File 'lib/oboe/base.rb', line 151 def passthrough? %w(always through).include?(Oboe::Config[:tracing_mode]) end |
#pickup_context?(xtrace) ⇒ Boolean
pickup_context
Determines whether we should pickup context from an incoming X-Trace request header. The answer is generally yes but there are cases in JRuby under Tomcat (or Glassfish etc.) where tracing may have been already started by the Java instrumentation (Joboe) in which case we don’t want to do this.
93 94 95 96 97 98 99 100 101 |
# File 'lib/oboe/base.rb', line 93 def pickup_context?(xtrace) return false unless Oboe::XTrace.valid?(xtrace) if defined?(JRUBY_VERSION) && Oboe.tracing? return false else return true end end |
#sample?(_opts = {}) ⇒ Boolean
These methods should be implemented by the descendants (Oboe_metal, Oboe_metal (JRuby), Heroku_metal)
206 207 208 |
# File 'lib/oboe/base.rb', line 206 def sample?(_opts = {}) fail 'sample? should be implemented by metal layer.' end |
#set_sample_rate(_rate) ⇒ Object
218 219 220 |
# File 'lib/oboe/base.rb', line 218 def set_sample_rate(_rate) fail 'set_sample_rate should be implemented by metal layer.' end |
#set_tracing_mode(_mode) ⇒ Object
214 215 216 |
# File 'lib/oboe/base.rb', line 214 def set_tracing_mode(_mode) fail 'set_tracing_mode should be implemented by metal layer.' end |
#through? ⇒ Boolean
Returns true if the tracing_mode is set to through. False otherwise
159 160 161 |
# File 'lib/oboe/base.rb', line 159 def through? Oboe::Config[:tracing_mode] == 'through' end |
#tracing? ⇒ Boolean
Returns true if we are currently tracing a request False otherwise
167 168 169 170 171 |
# File 'lib/oboe/base.rb', line 167 def tracing? return false unless Oboe.loaded Oboe::Context.isValid && !Oboe.never? end |
#tracing_layer?(layer) ⇒ Boolean
tracing_layer?
Queries the thread local variable about the current layer being traced. This is used in cases of recursive operation tracing or one instrumented operation calling another.
110 111 112 |
# File 'lib/oboe/base.rb', line 110 def tracing_layer?(layer) return Oboe.layer == layer end |
#tracing_layer_op?(operation) ⇒ Boolean
tracing_layer_op?
Queries the thread local variable about the current operation being traced. This is used in cases of recursive operation tracing or one instrumented operation calling another.
In such cases, we only want to trace the outermost operation.
123 124 125 126 127 128 129 |
# File 'lib/oboe/base.rb', line 123 def tracing_layer_op?(operation) if operation.is_a?(Array) return operation.include?(Oboe.layer_op) else return Oboe.layer_op == operation end end |