Skip to content

Instantly share code, notes, and snippets.

@brianr
Created March 14, 2014 22:27
Show Gist options
  • Select an option

  • Save brianr/9558298 to your computer and use it in GitHub Desktop.

Select an option

Save brianr/9558298 to your computer and use it in GitHub Desktop.
Example showing how to report an exception to Rollbar with a custom fingerprint, from ruby
source 'https://rubygems.org'
gem 'rollbar'
require 'rollbar'
# monkeypatch Rollbar to add a new method, report_exception_with_fingerprint
module Rollbar
class << self
def report_exception_with_fingerprint(exception, fingerprint, request_data = nil, person_data = nil, level = nil)
if person_data
person_id = person_data[Rollbar.configuration.person_id_method.to_sym]
return 'ignored' if configuration.ignored_person_ids.include?(person_id)
end
return 'disabled' unless configuration.enabled
return 'ignored' if ignored?(exception)
data = exception_data(exception, level ? level : filtered_level(exception))
data[:fingerprint] = fingerprint
attach_request_data(data, request_data) if request_data
data[:person] = person_data if person_data
@last_report = data
payload = build_payload(data)
schedule_payload(payload)
log_instance_link(data)
data
rescue => e
report_internal_error(e)
'error'
end
end
end
# now ready to use.
Rollbar.configure do |config|
config.access_token = 'aaaabbbbccccddddeeeeffff00001111'
end
begin
1 / 0
rescue => e
Rollbar.report_exception_with_fingerprint(e, "this will group with the other")
end
# normally, this would group separately from above, but by providing the same fingerprint, they will be grouped together
begin
foo = bar
rescue => e
Rollbar.report_exception_with_fingerprint(e, "this will group with the other")
end
# normally, this would group with the above, but by providing a different fingerprint, they'll be grouped separately
begin
foo = bar
rescue => e
Rollbar.report_exception_with_fingerprint(e, "this will group separately")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment