Module: TraceViewBase
Overview
This module is the base module for the various implementations of TraceView 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.
-
#entry_layer?(layer) ⇒ Boolean
entry_layer?.
-
#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.
-
#pry! ⇒ Object
Debugging helper method.
-
#sample?(_opts = {}) ⇒ Boolean
These methods should be implemented by the descendants (Oboe_metal, JOboe_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 TraceView::ThreadLocal
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
40 41 42 |
# File 'lib/traceview/base.rb', line 40 def loaded @loaded end |
#reporter ⇒ Object
Returns the value of attribute reporter.
39 40 41 |
# File 'lib/traceview/base.rb', line 39 def reporter @reporter end |
Class Method Details
.extended(cls) ⇒ Object
extended
Invoked when this module is extended. e.g. extend TraceViewBase
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/traceview/base.rb', line 80 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? TraceView.methods.select { |m| m =~ /^is_|^has_/ }.each do |c| unless c =~ /\?$|=$/ # TraceView.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
162 163 164 |
# File 'lib/traceview/base.rb', line 162 def always? TraceView::Config[:tracing_mode].to_sym == :always end |
#entry_layer?(layer) ⇒ Boolean
entry_layer?
Determines if the passed layer is an entry only layer where we would want to use smart tracing.
Entry only layers are layers that only start traces and doesn’t directly receive incoming context such as DelayedJob or Sidekiq workers.
154 155 156 |
# File 'lib/traceview/base.rb', line 154 def entry_layer?(layer) %w(delayed_job-worker sidekiq-worker resque-worker rabbitmq-consumer).include?(layer.to_s) end |
#forking_webserver? ⇒ Boolean
Determines if we are running under a forking webserver
211 212 213 214 215 216 217 218 |
# File 'lib/traceview/base.rb', line 211 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
252 253 254 |
# File 'lib/traceview/base.rb', line 252 def framework? defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape) end |
#heroku? ⇒ Boolean
204 205 206 |
# File 'lib/traceview/base.rb', line 204 def heroku? ENV.key?('TRACEVIEW_URL') end |
#log(_layer, _label, _options = {}) ⇒ Object
199 200 201 202 |
# File 'lib/traceview/base.rb', line 199 def log(layer, label, = {}) # WARN: TraceView.log will be deprecated in a future release. Please use TraceView::API.log instead. TraceView::API.log(layer, label, ) end |
#never? ⇒ Boolean
Returns true if the tracing_mode is set to never. False otherwise
170 171 172 |
# File 'lib/traceview/base.rb', line 170 def never? TraceView::Config[:tracing_mode].to_sym == :never end |
#passthrough? ⇒ Boolean
Returns true if the tracing_mode is set to always or through. False otherwise
178 179 180 |
# File 'lib/traceview/base.rb', line 178 def passthrough? [:always, :through].include?(TraceView::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.
103 104 105 106 107 108 109 110 111 |
# File 'lib/traceview/base.rb', line 103 def pickup_context?(xtrace) return false unless TraceView::XTrace.valid?(xtrace) if defined?(JRUBY_VERSION) && TraceView.tracing? return false else return true end end |
#pry! ⇒ Object
Debugging helper method
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/traceview/base.rb', line 223 def pry! # Only valid for development or test environments env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] return unless %w(development, test).include? env if RUBY_VERSION > '1.8.7' require 'pry-byebug' if defined?(PryByebug) Pry.commands.alias_command 'c', 'continue' Pry.commands.alias_command 's', 'step' Pry.commands.alias_command 'n', 'next' Pry.commands.alias_command 'f', 'finish' Pry::Commands.command(/^$/, 'repeat last command') do _pry_.run_command Pry.history.to_a.last end end binding.pry else require 'ruby-debug'; debugger end end |
#sample?(_opts = {}) ⇒ Boolean
These methods should be implemented by the descendants (Oboe_metal, JOboe_metal (JRuby), Heroku_metal)
260 261 262 |
# File 'lib/traceview/base.rb', line 260 def sample?(_opts = {}) fail 'sample? should be implemented by metal layer.' end |
#set_sample_rate(_rate) ⇒ Object
272 273 274 |
# File 'lib/traceview/base.rb', line 272 def set_sample_rate(_rate) fail 'set_sample_rate should be implemented by metal layer.' end |
#set_tracing_mode(_mode) ⇒ Object
268 269 270 |
# File 'lib/traceview/base.rb', line 268 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
186 187 188 |
# File 'lib/traceview/base.rb', line 186 def through? TraceView::Config[:tracing_mode].to_sym == :through end |
#tracing? ⇒ Boolean
Returns true if we are currently tracing a request False otherwise
194 195 196 197 |
# File 'lib/traceview/base.rb', line 194 def tracing? return false if !TraceView.loaded || TraceView.never? TraceView::Context.isValid 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.
120 121 122 |
# File 'lib/traceview/base.rb', line 120 def tracing_layer?(layer) TraceView.layer == layer.to_sym 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.
<operation> can be a single symbol or an array of symbols that will be checked against.
In such cases, we only want to trace the outermost operation.
136 137 138 139 140 141 142 |
# File 'lib/traceview/base.rb', line 136 def tracing_layer_op?(operation) if operation.is_a?(Array) return operation.include?(TraceView.layer_op) else return TraceView.layer_op == operation.to_sym end end |