lib/joboe_metal.rb in oboe-2.2.6 vs lib/joboe_metal.rb in oboe-2.3.2

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2012 by Tracelytics, Inc. +# Copyright (c) 2013 AppNeta, Inc. # All rights reserved. module Oboe_metal include_package 'com.tracelytics.joboe' import 'com.tracelytics.joboe' @@ -10,11 +10,11 @@ import 'com.tracelytics.joboe.Context' include_package 'com.tracelytics.joboe.Event' import 'com.tracelytics.joboe.Event' class Context - def self.log(layer, label, options = {}, with_backtrace = true) + def self.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| @@ -68,53 +68,71 @@ module Metadata Java::ComTracelyticsJoboeMetaData end module Reporter + ## + # Initialize the Oboe Context, reporter and report the initialization + # + def self.start + begin + Oboe_metal::Context.init() + + if ENV['RACK_ENV'] == "test" + Oboe.reporter = Oboe::FileReporter.new("./tmp/trace_output.bson") + else + Oboe.reporter = Oboe::UdpReporter.new(Oboe::Config[:reporter_host]) + end + + Oboe::API.report_init('ruby') unless ["development", "test"].include? ENV['RACK_ENV'] + + rescue Exception => e + $stderr.puts e.message + raise + end + end + def self.sendReport(evt) evt.report end end end module Oboe include Oboe_metal - def self.always? - Oboe::Config[:tracing_mode].to_s == "always" - end + class << self + attr_accessor :reporter - def self.log(layer, label, options = {}) - Context.log(layer, label, options = options) - end - - def self.never? - Oboe::Config[:tracing_mode].to_s == "never" - end - - def self.passthrough? - ["always", "through"].include?(Oboe::Config[:tracing_mode]) - end + def always? + Oboe::Config[:tracing_mode].to_s == "always" + end - def self.sample?(opts = {}) - # Assure defaults since SWIG enforces Strings - opts[:layer] ||= '' - opts[:xtrace] ||= '' - opts['X-TV-Meta'] ||= '' - Java::ComTracelyticsJoboeSettingsReader.shouldTraceRequest(opts[:layer], opts[:xtrace], opts['X-TV-Meta']) - end - - def self.through? - Oboe::Config[:tracing_mode] == "through" - end + def log(layer, label, options = {}) + Context.log(layer, label, options = options) + end - def self.tracing? - Oboe::Context.isValid and not Oboe.never? - end + def never? + Oboe::Config[:tracing_mode].to_s == "never" + end - def self.reporter - if !@reporter - @reporter = Oboe::UdpReporter.new(Oboe::Config[:reporter_host]) + def passthrough? + ["always", "through"].include?(Oboe::Config[:tracing_mode]) end - return @reporter + + def sample?(opts = {}) + # Assure defaults since SWIG enforces Strings + opts[:layer] ||= '' + opts[:xtrace] ||= '' + opts['X-TV-Meta'] ||= '' + Java::ComTracelyticsJoboeSettingsReader.shouldTraceRequest(opts[:layer], opts[:xtrace], opts['X-TV-Meta']) + end + + def through? + Oboe::Config[:tracing_mode] == "through" + end + + def tracing? + Oboe::Context.isValid and not Oboe.never? + end end end