lib/joboe_metal.rb in oboe-2.7.1.7-java vs lib/joboe_metal.rb in oboe-2.7.2.fuchs1
- old
+ new
@@ -46,46 +46,40 @@
module Reporter
##
# Initialize the Oboe Context, reporter and report the initialization
#
def self.start
- begin
- return unless Oboe.loaded
+ return unless Oboe.loaded
- if ENV.has_key?("OBOE_GEM_TEST")
- Oboe.reporter = Java::ComTracelyticsJoboe::TestReporter.new
- else
- Oboe.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance().buildUdpReporter()
- end
+ if ENV.key?('OBOE_GEM_TEST')
+ Oboe.reporter = Java::ComTracelyticsJoboe::TestReporter.new
+ else
+ Oboe.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance.buildUdpReporter
+ end
- # Import the tracing mode and sample rate settings
- # from the Java agent (user configured in
- # /usr/local/tracelytics/javaagent.json when under JRuby)
- cfg = LayerUtil.getLocalSampleRate(nil, nil)
+ # Import the tracing mode and sample rate settings
+ # from the Java agent (user configured in
+ # /usr/local/tracelytics/javaagent.json when under JRuby)
+ cfg = LayerUtil.getLocalSampleRate(nil, nil)
- if cfg.hasSampleStartFlag
- Oboe::Config.tracing_mode = 'always'
- elsif cfg.hasSampleThroughFlag
- Oboe::Config.tracing_mode = 'through'
- else
- Oboe::Config.tracing_mode = 'never'
- end
+ if cfg.hasSampleStartFlag
+ Oboe::Config.tracing_mode = 'always'
+ elsif cfg.hasSampleThroughFlag
+ Oboe::Config.tracing_mode = 'through'
+ else
+ Oboe::Config.tracing_mode = 'never'
+ end
- Oboe.sample_rate = cfg.sampleRate
- Oboe::Config.sample_rate = cfg.sampleRate
- Oboe::Config.sample_source = cfg.sampleRateSource.a
+ Oboe.sample_rate = cfg.sampleRate
+ Oboe::Config.sample_rate = cfg.sampleRate
+ Oboe::Config.sample_source = cfg.sampleRateSource.a
- # Only report __Init from here if we are not instrumenting a framework.
- # Otherwise, frameworks will handle reporting __Init after full initialization
- unless defined?(::Rails) or defined?(::Sinatra) or defined?(::Padrino) or defined?(::Grape)
- Oboe::API.report_init
- end
-
- rescue Exception => e
- $stderr.puts e.message
- raise
+ # Only report __Init from here if we are not instrumenting a framework.
+ # Otherwise, frameworks will handle reporting __Init after full initialization
+ unless defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
+ Oboe::API.report_init
end
end
##
# clear_all_traces
@@ -110,11 +104,11 @@
# the Java::ComTracelyticsExtEbson::DefaultDocument doc to a pure array of Ruby
# hashes
traces = []
Oboe.reporter.getSentEventsAsBsonDocument.to_a.each do |e|
t = {}
- e.each_pair { |k,v|
+ e.each_pair { |k, v|
t[k] = v
}
traces << t
end
traces
@@ -131,26 +125,27 @@
include Oboe_metal
class << self
def sample?(opts = {})
begin
- return false unless Oboe.always? and Oboe.loaded
+ return false unless Oboe.always? && Oboe.loaded
- return true if ENV['OBOE_GEM_TEST'] == "test"
+ return true if ENV.key?('OBOE_GEM_TEST')
# Validation to make Joboe happy. Assure that we have the KVs and that they
# are not empty strings.
- opts[:layer] = nil if opts[:layer].is_a?(String) and opts[:layer].empty?
- opts[:xtrace] = nil if opts[:xtrace].is_a?(String) and opts[:xtrace].empty?
- opts['X-TV-Meta'] = nil if opts['X-TV-Meta'].is_a?(String) and opts['X-TV-Meta'].empty?
+ opts[:layer] = nil if opts[:layer].is_a?(String) && opts[:layer].empty?
+ opts[:xtrace] = nil if opts[:xtrace].is_a?(String) && opts[:xtrace].empty?
+ opts['X-TV-Meta'] = nil if opts['X-TV-Meta'].is_a?(String) && opts['X-TV-Meta'].empty?
opts[:layer] ||= nil
opts[:xtrace] ||= nil
opts['X-TV-Meta'] ||= nil
- sr_cfg = Java::ComTracelyticsJoboe::LayerUtil.shouldTraceRequest( opts[:layer],
- { 'X-Trace' => opts[:xtrace], 'X-TV-Meta' => opts['X-TV-Meta'] } )
+ sr_cfg = Java::ComTracelyticsJoboe::LayerUtil.shouldTraceRequest(
+ opts[:layer],
+ { 'X-Trace' => opts[:xtrace], 'X-TV-Meta' => opts['X-TV-Meta'] })
# Store the returned SampleRateConfig into Oboe::Config
if sr_cfg
Oboe.sample_rate = sr_cfg.sampleRate
Oboe.sample_source = sr_cfg.sampleRateSource.a
@@ -161,15 +156,15 @@
Oboe.logger.debug "[oboe/debug] #{e.message}"
false
end
end
- def set_tracing_mode(mode)
- Oboe.logger.warn "When using JRuby set the tracing mode in /usr/local/tracelytics/javaagent.json instead"
+ def set_tracing_mode(_mode)
+ Oboe.logger.warn 'When using JRuby set the tracing mode in /usr/local/tracelytics/javaagent.json instead'
end
- def set_sample_rate(rate)
+ def set_sample_rate(_rate)
# N/A
end
end
end
@@ -178,6 +173,5 @@
if status == Java::ComTracelyticsAgent::Agent::AgentStatus::UNINITIALIZED
Oboe.loaded = false
else
Oboe.loaded = true
end
-