Module: Opbeat

Defined in:
lib/opbeat/linecache.rb,
lib/opbeat.rb,
lib/opbeat/rack.rb,
lib/opbeat/error.rb,
lib/opbeat/event.rb,
lib/opbeat/client.rb,
lib/opbeat/logger.rb,
lib/opbeat/railtie.rb,
lib/opbeat/version.rb,
lib/opbeat/processor.rb,
lib/opbeat/interfaces.rb,
lib/opbeat/configuration.rb,
lib/opbeat/interfaces/http.rb,
lib/opbeat/interfaces/message.rb,
lib/opbeat/integrations/sidekiq.rb,
lib/opbeat/interfaces/exception.rb,
lib/opbeat/capistrano/capistrano2.rb,
lib/opbeat/interfaces/stack_trace.rb,
lib/opbeat/processors/sanitizedata.rb,
lib/opbeat/rails/middleware/debug_exceptions_catcher.rb

Overview

A much simpler source line cacher because linecache sucks at platform compat

Defined Under Namespace

Modules: Capistrano, Integrations, Processor, Rails Classes: Client, ClientState, Configuration, Error, Event, ExceptionInterface, HttpInterface, Interface, LineCache, Logger, MessageInterface, Rack, Railtie, StacktraceInterface

Constant Summary collapse

VERSION =
"0.9.1"
INTERFACES =
{}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

The client object is responsible for delivering formatted data to the Opbeat server. Must respond to #send_event. See Opbeat::Client.



23
24
25
# File 'lib/opbeat.rb', line 23

def client
  @client
end

.configurationObject

The configuration object.

See Also:



40
41
42
# File 'lib/opbeat.rb', line 40

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.capture(&block) ⇒ Object

Capture and process any exceptions from the given block, or globally if no block is given

Examples:

Opbeat.capture do
  MyApp.run
end


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/opbeat.rb', line 73

def capture(&block)
  if block
    begin
      block.call
    rescue Error => e
      raise # Don't capture Opbeat errors
    rescue Exception => e
      self.captureException(e)
      raise
    end
  else
    # Install at_exit hook
    at_exit do
      if $!
        logger.debug "Caught a post-mortem exception: #{$!.inspect}"
        self.captureException($!)
      end
    end
  end
end

.captureException(exception, options = {}) ⇒ Object Also known as: capture_exception



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

def captureException(exception, options={})
  evt = Event.capture_exception(exception, options)
  send(evt) if evt
end

.captureMessage(message, options = {}) ⇒ Object Also known as: capture_message



99
100
101
102
# File 'lib/opbeat.rb', line 99

def captureMessage(message, options={})
  evt = Event.capture_message(message, options)
  send(evt) if evt
end

.configure(silent = false) {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

Opbeat.configure do |config|
  config.server = 'http://...'
end

Yields:



50
51
52
53
54
55
# File 'lib/opbeat.rb', line 50

def configure(silent = false)
  yield(configuration)
  self.client = Client.new(configuration)
  report_ready unless silent
  self.client
end

.find_interface(name) ⇒ Object



33
34
35
# File 'lib/opbeat/interfaces.rb', line 33

def self.find_interface(name)
  INTERFACES[name.to_s]
end

.loggerObject



29
30
31
# File 'lib/opbeat.rb', line 29

def logger
  @logger ||= Logger.new
end

.register_interface(mapping) ⇒ Object



26
27
28
29
30
31
# File 'lib/opbeat/interfaces.rb', line 26

def self.register_interface(mapping)
  mapping.each_pair do |key, klass|
    INTERFACES[key.to_s] = klass
    INTERFACES[klass.name] = klass
  end
end

.report_readyObject

Tell the log that the client is good to go



34
35
36
# File 'lib/opbeat.rb', line 34

def report_ready
  self.logger.info "Opbeat #{VERSION} ready to catch errors"
end

.send(evt) ⇒ Object

Send an event to the configured Opbeat server

Examples:

evt = Opbeat::Event.new(:message => "An error")
Opbeat.send(evt)


62
63
64
# File 'lib/opbeat.rb', line 62

def send(evt)
  @client.send_event(evt) if @client
end

.set_context(options = {}) ⇒ Object



104
105
106
# File 'lib/opbeat.rb', line 104

def set_context(options={})
  Event.set_context(options)
end