Module: Oboe::API::Logging
- Defined in:
- lib/oboe/api/logging.rb
Instance Method Summary collapse
-
#log(layer, label, opts = {}) ⇒ Object
Public: Report an event in an active trace.
-
#log_end(layer, opts = {}) ⇒ Object
Public: Report an exit event.
- #log_entry(layer, opts = {}, protect_op = nil) ⇒ Object
-
#log_event(layer, label, event, opts = {}) ⇒ Object
Internal: Report an event.
-
#log_exception(layer, exn) ⇒ Object
Public: Report an exception.
- #log_exit(layer, opts = {}, protect_op = nil) ⇒ Object
-
#log_start(layer, xtrace, opts = {}) ⇒ Object
Public: Decide whether or not to start a trace, and report an event appropriately.
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.
23 24 25 |
# File 'lib/oboe/api/logging.rb', line 23 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
81 82 83 84 85 86 |
# File 'lib/oboe/api/logging.rb', line 81 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, opts = {}, protect_op = nil) ⇒ Object
88 89 90 91 |
# File 'lib/oboe/api/logging.rb', line 88 def log_entry(layer, opts={}, protect_op=nil) Oboe::Context.layer_op = protect_op if protect_op log_event(layer, 'entry', Oboe::Context.createEvent, opts) 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.getMetadata)
log_event('rails', 'exit', exit)
Returns nothing.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/oboe/api/logging.rb', line 115 def log_event(layer, label, event, opts={}) if layer event.addInfo('Layer', layer.to_s) end 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? and 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.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/oboe/api/logging.rb', line 42 def log_exception(layer, exn) unless exn.instance_variable_get(:@oboe_logged) log(layer, 'error', { :ErrorClass => exn.class.name, :Message => exn., :Backtrace => exn.backtrace.join("\r\n") }) exn.instance_variable_set(:@oboe_logged, true) end end |
#log_exit(layer, opts = {}, protect_op = nil) ⇒ Object
93 94 95 96 |
# File 'lib/oboe/api/logging.rb', line 93 def log_exit(layer, opts={}, protect_op=nil) Oboe::Context.layer_op = nil if protect_op log_event(layer, 'exit', Oboe::Context.createEvent, opts) 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.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/oboe/api/logging.rb', line 62 def log_start(layer, xtrace, opts={}) return if Oboe.never? or (opts.has_key?(:URL) and ::Oboe::Util.static_asset?(opts[:URL])) if xtrace Oboe::Context.fromString(xtrace) end if Oboe.tracing? log_entry(layer, opts) elsif Oboe.always? and (Oboe.sample?(opts.merge(:layer => layer, :xtrace => xtrace)) or opts.has_key?('Force')) log_event(layer, 'entry', Oboe::Context.startTrace, opts) end end |