Module: Oboe

Extended by:
OboeBase
Includes:
Oboe_metal
Defined in:
lib/heroku_metal.rb

Instance Attribute Summary

Attributes included from OboeBase

#loaded, #reporter, #sample_rate, #sample_source

Class Method Summary collapse

Methods included from OboeBase

always?, forking_webserver?, heroku?, included, log, never?, passthrough?, sample?, set_sample_rate, set_tracing_mode, through?, tracing?

Class Method Details

.disconnect!Object

Disconnect/Reconnect wrappers used for forking webservers such as Unicorn or Passenger



123
124
125
126
# File 'lib/heroku_metal.rb', line 123

def disconnect!
  # To avoid an issue with SSL reconnects, delay Reporter initialization
  # until after the fork is completed.  Here, do nothing for now.
end

.reconnect!Object



128
129
130
# File 'lib/heroku_metal.rb', line 128

def reconnect!
  Oboe::Reporter.start
end

.sample?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/heroku_metal.rb', line 73

def sample?(opts = {})
  # Assure defaults since SWIG enforces Strings
  opts[:layer]      ||= ''
  opts[:xtrace]     ||= ''
  opts['X-TV-Meta'] ||= ''

  rv = Oboe::Context.sampleRequest(opts[:layer], opts[:xtrace], opts['X-TV-Meta'])

  # For older liboboe that returns true/false, just return that.
  return rv if [TrueClass, FalseClass].include?(rv.class) or (rv == 0)

  # liboboe version > 1.3.1 returning a bit masked integer with SampleRate and
  # source embedded
  Oboe.sample_rate = (rv & SAMPLE_RATE_MASK)
  Oboe.sample_source = (rv & SAMPLE_SOURCE_MASK) >> 24

  rv
end

.set_sample_rate(rate) ⇒ Object



113
114
115
116
117
118
# File 'lib/heroku_metal.rb', line 113

def set_sample_rate(rate)
  if Oboe.loaded
    # Update liboboe with the new SampleRate value
    Oboe::Context.setDefaultSampleRate(rate.to_i)
  end
end

.set_tracing_mode(mode) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/heroku_metal.rb', line 92

def set_tracing_mode(mode)
  return unless Oboe.loaded

  value = mode.to_sym

  case value
  when :never
    Oboe::Context.setTracingMode(OBOE_TRACE_NEVER)

  when :always
    Oboe::Context.setTracingMode(OBOE_TRACE_ALWAYS)

  when :through
    Oboe::Context.setTracingMode(OBOE_TRACE_THROUGH)

  else
    Oboe.logger.fatal "[oboe/error] Invalid tracing mode set: #{mode}"
    Oboe::Context.setTracingMode(OBOE_TRACE_THROUGH)
  end
end