module OboeBase
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)
Attributes
Public Class Methods
extended
Invoked when this module is extended. e.g. extend OboeBase
# 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
Public Instance Methods
Returns true if the tracing_mode is set to always. False otherwise
# File lib/oboe/base.rb, line 135 def always? Oboe::Config[:tracing_mode].to_s == 'always' end
Determines if we are running under a forking webserver
# 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
Indicates whether a supported framework is in use or not
# File lib/oboe/base.rb, line 198 def framework? defined?(::Rails) or defined?(::Sinatra) or defined?(::Padrino) or defined?(::Grape) end
# File lib/oboe/base.rb, line 178 def heroku? ENV.key?('TRACEVIEW_URL') end
# File lib/oboe/base.rb, line 173 def log(layer, label, options = {}) # WARN: Oboe.log will be deprecated in a future release. Please use Oboe::API.log instead. Oboe::API.log(layer, label, options) end
Returns true if the tracing_mode is set to never. False otherwise
# File lib/oboe/base.rb, line 143 def never? Oboe::Config[:tracing_mode].to_s == 'never' end
Returns true if the tracing_mode is set to always or through. False otherwise
# File lib/oboe/base.rb, line 151 def passthrough? %w(always through).include?(Oboe::Config[:tracing_mode]) end
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.
# 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
These methods should be implemented by the descendants (Oboe_metal
, Oboe_metal
(JRuby), Heroku_metal)
# File lib/oboe/base.rb, line 206 def sample?(_opts = {}) fail 'sample? should be implemented by metal layer.' end
# File lib/oboe/base.rb, line 218 def set_sample_rate(_rate) fail 'set_sample_rate should be implemented by metal layer.' end
# File lib/oboe/base.rb, line 214 def set_tracing_mode(_mode) fail 'set_tracing_mode should be implemented by metal layer.' end
Returns true if the tracing_mode is set to through. False otherwise
# File lib/oboe/base.rb, line 159 def through? Oboe::Config[:tracing_mode] == 'through' end
Returns true if we are currently tracing a request False otherwise
# File lib/oboe/base.rb, line 167 def tracing? return false unless Oboe.loaded Oboe::Context.isValid && !Oboe.never? end
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.
# File lib/oboe/base.rb, line 110 def tracing_layer?(layer) return Oboe.layer == layer end
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.
# 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