# Copyright (c) 2013 AppNeta # All rights reserved. module Oboe extend OboeBase include Oboe_metal class Reporter ## # Initialize the Oboe Context, reporter and report the initialization # def self.start begin return unless Oboe.loaded if Oboe.reporter Oboe.logger.warn "[oboe/warn] Attempt to start an already started reporter..." return end Oboe_metal::Context.init() Oboe.logger.debug "[oboe/debug] Initializing Heroku based reporter." # The Oboe Reporter is configured via Heroku config variables. Oboe.reporter = Oboe_metal::Reporter.new(nil, nil) Oboe::API.report_init rescue Exception => e $stderr.puts e.message raise end end def self.sendReport(evt) Oboe.reporter.sendReport(evt) if Oboe.loaded end end class Event def self.metadataString(evt) evt.metadataString() end end class << self def sample?(opts = {}) begin return false unless Oboe.always? && Oboe.loaded # 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(layer, xtrace, tv_meta) 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 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 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! # To avoid an issue with SSL reconnects, delay Reporter initialization # until after the fork is completed. Here, do nothing for now. end def reconnect! Oboe::Reporter.start end end end Oboe.loaded = true