Module: OboeBase

Extended by:
Oboe::ThreadLocal
Included in:
Oboe
Defined in:
lib/oboe-heroku/base.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Oboe::ThreadLocal

thread_local

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



33
34
35
# File 'lib/oboe-heroku/base.rb', line 33

def loaded
  @loaded
end

#reporterObject

Returns the value of attribute reporter.



32
33
34
# File 'lib/oboe-heroku/base.rb', line 32

def reporter
  @reporter
end

#sample_rateObject

Returns the value of attribute sample_rate.



35
36
37
# File 'lib/oboe-heroku/base.rb', line 35

def sample_rate
  @sample_rate
end

#sample_sourceObject

Returns the value of attribute sample_source.



34
35
36
# File 'lib/oboe-heroku/base.rb', line 34

def sample_source
  @sample_source
end

Class Method Details

.extended(cls) ⇒ Object

extended

Invoked when this module is extended. e.g. extend OboeBase



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/oboe-heroku/base.rb', line 69

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



123
124
125
# File 'lib/oboe-heroku/base.rb', line 123

def always?
  Oboe::Config[:tracing_mode].to_s == 'always'
end

#forking_webserver?Boolean

Determines if we are running under a forking webserver



173
174
175
# File 'lib/oboe-heroku/base.rb', line 173

def forking_webserver?
  (defined?(::Unicorn) && ($PROGRAM_NAME =~ /unicorn/i)) ? true : false
end

#framework?Boolean

Indicates whether a supported framework is in use or not



181
182
183
# File 'lib/oboe-heroku/base.rb', line 181

def framework?
  defined?(::Rails) or defined?(::Sinatra) or defined?(::Padrino) or defined?(::Grape)
end

#heroku?Boolean



166
167
168
# File 'lib/oboe-heroku/base.rb', line 166

def heroku?
  ENV.key?('TRACEVIEW_URL')
end

#log(_layer, _label, _options = {}) ⇒ Object



161
162
163
164
# File 'lib/oboe-heroku/base.rb', line 161

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

#never?Boolean

Returns true if the tracing_mode is set to never. False otherwise



131
132
133
# File 'lib/oboe-heroku/base.rb', line 131

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



139
140
141
# File 'lib/oboe-heroku/base.rb', line 139

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.



92
93
94
95
96
97
98
99
100
# File 'lib/oboe-heroku/base.rb', line 92

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)



189
190
191
# File 'lib/oboe-heroku/base.rb', line 189

def sample?(_opts = {})
  fail 'sample? should be implemented by metal layer.'
end

#set_sample_rate(_rate) ⇒ Object



201
202
203
# File 'lib/oboe-heroku/base.rb', line 201

def set_sample_rate(_rate)
  fail 'set_sample_rate should be implemented by metal layer.'
end

#set_tracing_mode(_mode) ⇒ Object



197
198
199
# File 'lib/oboe-heroku/base.rb', line 197

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



147
148
149
# File 'lib/oboe-heroku/base.rb', line 147

def through?
  Oboe::Config[:tracing_mode] == 'through'
end

#tracing?Boolean

Returns true if we are currently tracing a request False otherwise



155
156
157
158
159
# File 'lib/oboe-heroku/base.rb', line 155

def tracing?
  return false unless Oboe.loaded

  Oboe::Context.isValid && !Oboe.never?
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.



111
112
113
114
115
116
117
# File 'lib/oboe-heroku/base.rb', line 111

def tracing_layer_op?(operation)
  if operation.is_a?(Array)
    return operation.include?(Oboe.layer_op)
  else
    return Oboe.layer_op == operation
  end
end