lib/heroku_metal.rb in oboe-heroku-0.8.0.27.beta2 vs lib/heroku_metal.rb in oboe-heroku-0.9.0.1

- old
+ new

@@ -1,44 +1,45 @@ # Copyright (c) 2013 AppNeta # All rights reserved. -module Oboe_metal - class Event - def self.metadataString(evt) - evt.metadataString() - end - end +require 'base' +module Oboe_metal class Context class << self attr_accessor :layer_op - - def log(layer, label, options = {}, with_backtrace = true) - Oboe.logger.debug "HerokuMetal log: layer: #{layer}, label: #{label}, options: #{options}, with_backtrace: #{with_backtrace.to_s}" - + + def log(layer, label, options = {}, with_backtrace = false) evt = Oboe::Context.createEvent() evt.addInfo("Layer", layer.to_s) evt.addInfo("Label", label.to_s) options.each_pair do |k, v| evt.addInfo(k.to_s, v.to_s) end evt.addInfo("Backtrace", Oboe::API.backtrace) if with_backtrace + Oboe.reporter.sendReport(evt) end - + def tracing_layer_op?(operation) if operation.is_a?(Array) return operation.include?(@layer_op) else return @layer_op == operation end end end end + class Event + def self.metadataString(evt) + evt.metadataString() + end + end + class Reporter ## # Initialize the Oboe Context, reporter and report the initialization # def self.start @@ -60,52 +61,63 @@ Oboe.reporter.sendReport(evt) end end end -module Oboe +module Oboe + extend OboeBase include Oboe_metal class << self - attr_accessor :reporter - def always? - Oboe::Config[:tracing_mode].to_s == "always" - end - - def never? - Oboe::Config[:tracing_mode].to_s == "never" - end - - def passthrough? - ["always", "through"].include?(Oboe::Config[:tracing_mode]) - end - def sample?(opts = {}) # Assure defaults since SWIG enforces Strings opts[:layer] ||= '' opts[:xtrace] ||= '' opts['TV-Meta'] ||= '' Oboe::Context.sampleRequest(opts[:layer], opts[:xtrace], opts['TV-Meta']) end + + def set_tracing_mode(mode) + return unless Oboe.loaded - def through? - Oboe::Config[:tracing_mode] == "through" + value = mode.to_sym + + case value + when :never + # OBOE_TRACE_NEVER + Oboe::Context.setTracingMode(0) + when :always + # OBOE_TRACE_ALWAYS + Oboe::Context.setTracingMode(1) + when :through + # OBOE_TRACE_THROUGH + Oboe::Context.setTracingMode(2) + else + Oboe.logger.fatal "[oboe/error] Invalid tracing mode set: #{mode}" + # OBOE_TRACE_ALWAYS + Oboe::Context.setTracingMode(1) + end end - - def tracing? - Oboe::Context.isValid and not Oboe.never? + + def set_sample_rate(rate) + if Oboe.loaded + # Update liboboe with the new SampleRate value + Oboe::Context.setDefaultSampleRate(rate.to_i) + end end # Disconnect/Reconnect wrappers used for forking webservers # such as Unicorn or Passenger # def disconnect! - ::Oboe::Context.disconnect(::Oboe.reporter) + ::Oboe::Context.disconnect(::Oboe.reporter) if Oboe.loaded end def reconnect! - ::Oboe::Context.reconnect(::Oboe.reporter) + ::Oboe::Context.reconnect(::Oboe.reporter) if Oboe.loaded end end end + +Oboe.loaded = true