Module: TraceViewBase

Extended by:
TraceView::ThreadLocal
Included in:
Oboe, TraceView
Defined in:
lib/traceview/base.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TraceView::ThreadLocal

thread_local

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



33
34
35
# File 'lib/traceview/base.rb', line 33

def loaded
  @loaded
end

#reporterObject

Returns the value of attribute reporter.



32
33
34
# File 'lib/traceview/base.rb', line 32

def reporter
  @reporter
end

Class Method Details

.extended(cls) ⇒ Object

extended

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



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/traceview/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?
  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

Returns:

  • (Boolean)


135
136
137
# File 'lib/traceview/base.rb', line 135

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

#forking_webserver?Boolean

Determines if we are running under a forking webserver

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
# File 'lib/traceview/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

Returns:

  • (Boolean)


198
199
200
# File 'lib/traceview/base.rb', line 198

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

#heroku?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/traceview/base.rb', line 178

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

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



173
174
175
176
# File 'lib/traceview/base.rb', line 173

def log(layer, label, options = {})
  # WARN: TraceView.log will be deprecated in a future release.  Please use TraceView::API.log instead.
  TraceView::API.log(layer, label, options)
end

#never?Boolean

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

Returns:

  • (Boolean)


143
144
145
# File 'lib/traceview/base.rb', line 143

def never?
  TraceView::Config[:tracing_mode].to_s == 'never'
end

#passthrough?Boolean

Returns true if the tracing_mode is set to always or through. False otherwise

Returns:

  • (Boolean)


151
152
153
# File 'lib/traceview/base.rb', line 151

def passthrough?
  %w(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.

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
# File 'lib/traceview/base.rb', line 93

def pickup_context?(xtrace)
  return false unless TraceView::XTrace.valid?(xtrace)

  if defined?(JRUBY_VERSION) && TraceView.tracing?
    return false
  else
    return true
  end
end

#sample?(_opts = {}) ⇒ Boolean

These methods should be implemented by the descendants (Oboe_metal, JOboe_metal (JRuby), Heroku_metal)

Returns:

  • (Boolean)


206
207
208
# File 'lib/traceview/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/traceview/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/traceview/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

Returns:

  • (Boolean)


159
160
161
# File 'lib/traceview/base.rb', line 159

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

#tracing?Boolean

Returns true if we are currently tracing a request False otherwise

Returns:

  • (Boolean)


167
168
169
170
171
# File 'lib/traceview/base.rb', line 167

def tracing?
  return false unless TraceView.loaded

  TraceView::Context.isValid && !TraceView.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.

Returns:

  • (Boolean)


110
111
112
# File 'lib/traceview/base.rb', line 110

def tracing_layer?(layer)
  return TraceView.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.

Returns:

  • (Boolean)


123
124
125
126
127
128
129
# File 'lib/traceview/base.rb', line 123

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