lib/heroku_metal.rb in oboe-heroku-0.9.17.4 vs lib/heroku_metal.rb in oboe-heroku-0.9.17.8
- old
+ new
@@ -43,27 +43,34 @@
end
end
class << self
def sample?(opts = {})
- return false unless Oboe.always?
+ begin
+ return false unless Oboe.always? && Oboe.loaded
- # Assure defaults since SWIG enforces Strings
- opts[:layer] ||= ''
- opts[:xtrace] ||= ''
- opts['X-TV-Meta'] ||= ''
+ # Assure defaults since SWIG enforces Strings
+ layer = opts[:layer] ? opts[:layer].strip : ''
+ xtrace = opts[:xtrace] ? opts[:xtrace].strip : ''
+ tv_meta = opts['X-TV-Meta'] ? opts['X-TV-Meta'].strip : ''
- rv = Oboe::Context.sampleRequest(opts[:layer], opts[:xtrace], opts['X-TV-Meta'])
+ rv = Oboe::Context.sampleRequest(layer, xtrace, 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
+ if rv == 0
+ Oboe.sample_rate = -1
+ Oboe.sample_source = -1
+ false
+ else
+ # 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
+ true
+ end
+ rescue StandardError => e
+ Oboe.logger.debug "[oboe/error] sample? error: #{e.inspect}"
+ false
+ end
end
def set_tracing_mode(mode)
return unless Oboe.loaded