Module: Oboe_metal::Reporter

Defined in:
lib/joboe_metal.rb

Class Method Summary collapse

Class Method Details

.clear_all_tracesObject

clear_all_traces

Truncates the trace output file to zero



94
95
96
# File 'lib/joboe_metal.rb', line 94

def self.clear_all_traces
  Oboe.reporter.reset if Oboe.loaded
end

.get_all_tracesObject

get_all_traces

Retrieves all traces written to the trace file



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/joboe_metal.rb', line 103

def self.get_all_traces
  return [] unless Oboe.loaded

  # Joboe TestReporter returns a Java::ComTracelyticsExtEbson::DefaultDocument
  # document for traces which doesn't correctly support things like has_key? which
  # raises an unhandled exception on non-existent key (duh).  Here we convert
  # 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|
      t[k] = v
    }
    traces << t
  end
  traces
end

.sendReport(evt) ⇒ Object



122
123
124
# File 'lib/joboe_metal.rb', line 122

def self.sendReport(evt)
  evt.report(Oboe.reporter)
end

.startObject

Initialize the Oboe Context, reporter and report the initialization



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/joboe_metal.rb', line 50

def self.start
  return unless Oboe.loaded

  if ENV.key?('OBOE_GEM_TEST')
    Oboe.reporter = Java::ComTracelyticsJoboe::TestReporter.new
  else
    Oboe.reporter = Java::ComTracelyticsJoboe::ReporterFactory.getInstance.buildUdpReporter
  end


  begin
    # 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

    Oboe.sample_rate = cfg.getSampleRate
    Oboe::Config.sample_rate = cfg.sampleRate
    Oboe::Config.sample_source = cfg.sampleRateSourceValue
  rescue => e
    Oboe.logger.debug "[oboe/debug] Couldn't retrieve/acces joboe sampleRateCfg"
    Oboe.logger.debug "[oboe/debug] #{e.message}"
  end

  # 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 unless ENV.key?('OBOE_GEM_TEST')
  end
end