Module: HydraulicBrake

Defined in:
lib/hydraulic_brake.rb,
lib/hydraulic_brake/hook.rb,
lib/hydraulic_brake/notice.rb,
lib/hydraulic_brake/sender.rb,
lib/hydraulic_brake/version.rb,
lib/hydraulic_brake/backtrace.rb,
lib/hydraulic_brake/configuration.rb,
lib/hydraulic_brake/test_notification.rb

Defined Under Namespace

Modules: Hook, TestNotification Classes: Backtrace, Configuration, Notice, Sender

Constant Summary collapse

API_VERSION =
"2.3"
LOG_PREFIX =
"** [HydraulicBrake] "
HEADERS =
{
  'Content-type'             => 'text/xml',
  'Accept'                   => 'text/xml, application/xml'
}
VERSION =
File.read(File.join(File.dirname(__FILE__), "../../VERSION"))

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

The configuration object.

See Also:



85
86
87
# File 'lib/hydraulic_brake.rb', line 85

def configuration
  @configuration ||= Configuration.new
end

.senderObject

The sender object is responsible for delivering formatted data to the Airbrake server. Must respond to #send_to_airbrake. See HydraulicBrake::Sender.



25
26
27
# File 'lib/hydraulic_brake.rb', line 25

def sender
  @sender
end

Class Method Details

.build_lookup_hash_for(exception, options = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/hydraulic_brake.rb', line 108

def build_lookup_hash_for(exception, options = {})
  notice = build_notice_for(exception, options)

  result = {}
  result[:action]           = notice.action      rescue nil
  result[:component]        = notice.component   rescue nil
  result[:error_class]      = notice.error_class if notice.error_class
  result[:environment_name] = 'production'

  unless notice.backtrace.lines.empty?
    result[:file]        = notice.backtrace.lines.first.file
    result[:line_number] = notice.backtrace.lines.first.number
  end

  result
end

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

Call this method to modify defaults in your initializers.

Examples:

HydraulicBrake.configure do |config|
  config.api_key = '1234567890abcdef'
  config.secure  = false
end

Yields:



76
77
78
79
80
81
# File 'lib/hydraulic_brake.rb', line 76

def configure(silent = false)
  yield(configuration)
  self.sender = Sender.new(configuration)
  report_ready unless silent
  self.sender
end

.environment_infoObject

Returns the Ruby version, Rails version, and current Rails environment



53
54
55
56
57
# File 'lib/hydraulic_brake.rb', line 53

def environment_info
  info = "[Ruby: #{RUBY_VERSION}]"
  info << " [#{configuration.framework}]" if configuration.framework
  info << " [Env: #{configuration.environment_name}]" if configuration.environment_name
end

.loggerObject

Look for the Rails logger currently defined



65
66
67
# File 'lib/hydraulic_brake.rb', line 65

def logger
  self.configuration.logger
end

.notify(exception, opts = {}) ⇒ Object

Sends an exception manually using this method, even when you are not in a controller.

Parameters:

  • exception (Exception)

    The exception you want to notify Airbrake about

  • opts (Hash) (defaults to: {})

    Data that will be sent to Airbrake

Options Hash (opts):

  • :api_key (String)

    The API key for this project. The API key is a unique identifier that Airbrake uses for identification

  • :error_message (String)

    The error returned by the exception (or the message you want to log)

  • :backtrace (String)

    A backtrace, usually obtained with caller

  • :session_data (String)

    The contents of the user’s session

  • :environment_name (String)

    The application environment name



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

def notify(exception, opts = {})
  send_notice(build_notice_for(exception, opts))
end

.report_environment_infoObject

Prints out the environment info to the log for debugging help



38
39
40
# File 'lib/hydraulic_brake.rb', line 38

def report_environment_info
  write_verbose_log("Environment Info: #{environment_info}")
end

.report_notice(notice) ⇒ Object

Prints out the details about the notice that wasn’t sent to server



48
49
50
# File 'lib/hydraulic_brake.rb', line 48

def report_notice(notice)
  write_verbose_log("Notice details: \n#{notice}")
end

.report_readyObject

Tell the log that the Notifier is good to go



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

def report_ready
  write_verbose_log("Notifier #{VERSION} ready to catch errors")
end

.report_response_body(response) ⇒ Object

Prints out the response body from Airbrake for debugging help



43
44
45
# File 'lib/hydraulic_brake.rb', line 43

def report_response_body(response)
  write_verbose_log("Response from Airbrake: \n#{response}")
end

.write_verbose_log(message) ⇒ Object

Writes out the given message to the #logger



60
61
62
# File 'lib/hydraulic_brake.rb', line 60

def write_verbose_log(message)
  logger.debug LOG_PREFIX + message if logger
end