Module: Oboe::API::Logging

Defined in:
lib/oboe/api/logging.rb

Overview

This modules provides the X-Trace logging facilities.

Instance Method Summary collapse

Instance Method Details

#log(layer, label, opts = {}) ⇒ Object

Public: Report an event in an active trace.

layer - The layer the reported event belongs to label - The label for the reported event. See API documentation for

reserved labels and usage.

opts - A hash containing key/value pairs that will be reported along

with this event (optional).

Example

log('logical_layer', 'entry')
log('logical_layer', 'info', { :list_length => 20 })
log('logical_layer', 'exit')

Returns nothing.



24
25
26
# File 'lib/oboe/api/logging.rb', line 24

def log(layer, label, opts = {})
  log_event(layer, label, Oboe::Context.createEvent, opts)
end

#log_end(layer, opts = {}) ⇒ Object

Public: Report an exit event.

layer - The layer the reported event belongs to

Returns an xtrace metadata string



80
81
82
83
84
85
# File 'lib/oboe/api/logging.rb', line 80

def log_end(layer, opts = {})
  log_event(layer, 'exit', Oboe::Context.createEvent, opts)
  xtrace = Oboe::Context.toString
  Oboe::Context.clear
  xtrace
end

#log_entry(layer, kvs = {}, op = nil) ⇒ Object

Public: Log an entry event

A helper method to create and log an entry event

Returns an xtrace metadata string



94
95
96
97
# File 'lib/oboe/api/logging.rb', line 94

def log_entry(layer, kvs = {}, op = nil)
  Oboe.layer_op = op if op
  log_event(layer, 'entry', Oboe::Context.createEvent, kvs)
end

#log_event(layer, label, event, opts = {}) ⇒ Object

Internal: Report an event.

layer - The layer the reported event belongs to label - The label for the reported event. See API documentation for

reserved labels and usage.

opts - A hash containing key/value pairs that will be reported along

with this event (optional).

Examples

entry = Oboe::Context.createEvent
log_event('rails', 'entry', exit, { :controller => 'user', :action => 'index' })
exit = Oboe::Context.createEvent
exit.addEdge(entry.)
log_event('rails', 'exit', exit)

Returns nothing.



139
140
141
142
143
144
145
146
147
148
# File 'lib/oboe/api/logging.rb', line 139

def log_event(layer, label, event, opts = {})
  event.addInfo('Layer', layer.to_s) if layer
  event.addInfo('Label', label.to_s)

  opts.each do |k, v|
    event.addInfo(k.to_s, v.to_s) if valid_key? k
  end if !opts.nil? && opts.any?

  Oboe::Reporter.sendReport(event) if Oboe.loaded
end

#log_exception(layer, exn) ⇒ Object

Public: Report an exception.

layer - The layer the reported event belongs to exn - The exception to report

Example

begin
  function_without_oboe()
rescue Exception => e
  log_exception('rails', e)
  raise
end

Returns nothing.



43
44
45
46
47
48
49
50
51
52
# File 'lib/oboe/api/logging.rb', line 43

def log_exception(layer, exn)
  return if exn.instance_variable_get(:@oboe_logged)

  kvs = { :ErrorClass => exn.class.name,
          :Message => exn.message,
          :Backtrace => exn.backtrace.join("\r\n") }

  exn.instance_variable_set(:@oboe_logged, true)
  log(layer, 'error', kvs)
end

#log_exit(layer, kvs = {}, op = nil) ⇒ Object

Public: Log an exit event

A helper method to create and log an exit event

Returns an xtrace metadata string



117
118
119
120
# File 'lib/oboe/api/logging.rb', line 117

def log_exit(layer, kvs = {}, op = nil)
  Oboe.layer_op = nil if op
  log_event(layer, 'exit', Oboe::Context.createEvent, kvs)
end

#log_info(layer, kvs = {}) ⇒ Object

Public: Log an info event

A helper method to create and log an info event

Returns an xtrace metadata string



106
107
108
# File 'lib/oboe/api/logging.rb', line 106

def log_info(layer, kvs = {})
  log_event(layer, 'info', Oboe::Context.createEvent, kvs)
end

#log_start(layer, xtrace, opts = {}) ⇒ Object

Public: Decide whether or not to start a trace, and report an event appropriately.

layer - The layer the reported event belongs to xtrace - An xtrace metadata string, or nil. opts - A hash containing key/value pairs that will be reported along

with this event (optional).

Returns nothing.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/oboe/api/logging.rb', line 63

def log_start(layer, xtrace, opts = {})
  return if Oboe.never? || (opts.key?(:URL) && ::Oboe::Util.static_asset?(opts[:URL]))

  Oboe::Context.fromString(xtrace) if xtrace && !xtrace.to_s.empty?

  if Oboe.tracing?
    log_entry(layer, opts)
  elsif opts.key?('Force') || Oboe.sample?(opts.merge(:layer => layer, :xtrace => xtrace))
    log_event(layer, 'entry', Oboe::Context.startTrace, opts)
  end
end