Class: Bugsnag::Report
- Inherits:
-
Object
- Object
- Bugsnag::Report
- Defined in:
- lib/bugsnag/report.rb
Constant Summary collapse
- NOTIFIER_NAME =
"Ruby Bugsnag Notifier"
- NOTIFIER_VERSION =
Bugsnag::VERSION
- NOTIFIER_URL =
"https://www.bugsnag.com"
- UNHANDLED_EXCEPTION =
"unhandledException"
- UNHANDLED_EXCEPTION_MIDDLEWARE =
"unhandledExceptionMiddleware"
- ERROR_CLASS =
"errorClass"
- HANDLED_EXCEPTION =
"handledException"
- USER_SPECIFIED_SEVERITY =
"userSpecifiedSeverity"
- USER_CALLBACK_SET_SEVERITY =
"userCallbackSetSeverity"
- MAX_EXCEPTIONS_TO_UNWRAP =
5
- CURRENT_PAYLOAD_VERSION =
"4.0"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#app_type ⇒ Object
Returns the value of attribute app_type.
-
#app_version ⇒ Object
Returns the value of attribute app_version.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#context ⇒ Object
Returns the value of attribute context.
-
#delivery_method ⇒ Object
Returns the value of attribute delivery_method.
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#grouping_hash ⇒ Object
Returns the value of attribute grouping_hash.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#meta_data ⇒ Object
Returns the value of attribute meta_data.
-
#raw_exceptions ⇒ Object
Returns the value of attribute raw_exceptions.
-
#release_stage ⇒ Object
Returns the value of attribute release_stage.
-
#session ⇒ Object
Returns the value of attribute session.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#severity_reason ⇒ Object
Returns the value of attribute severity_reason.
-
#unhandled ⇒ Object
readonly
Returns the value of attribute unhandled.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#add_tab(name, value) ⇒ Object
Add a new metadata tab to this notification.
-
#as_json ⇒ Object
Builds and returns the exception payload for this notification.
-
#headers ⇒ Object
Returns the headers required for the notification.
-
#ignore! ⇒ Object
Tells the client this report should not be sent.
-
#ignore? ⇒ Boolean
Whether this report should be ignored and not sent.
-
#initialize(exception, passed_configuration, auto_notify = false) ⇒ Report
constructor
Initializes a new report from an exception.
-
#remove_tab(name) ⇒ Object
Removes a metadata tab from this notification.
-
#request_data ⇒ Object
Data set on the configuration to be attached to every error notification.
Constructor Details
#initialize(exception, passed_configuration, auto_notify = false) ⇒ Report
Initializes a new report from an exception.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bugsnag/report.rb', line 42 def initialize(exception, passed_configuration, auto_notify=false) @should_ignore = false @unhandled = auto_notify self.configuration = passed_configuration self.raw_exceptions = generate_raw_exceptions(exception) self.exceptions = generate_exception_list self.api_key = configuration.api_key self.app_type = configuration.app_type self.app_version = configuration.app_version self.delivery_method = configuration.delivery_method self.hostname = configuration.hostname self. = {} self.release_stage = configuration.release_stage self.severity = auto_notify ? "error" : "warning" self.severity_reason = auto_notify ? {:type => UNHANDLED_EXCEPTION} : {:type => HANDLED_EXCEPTION} self.user = {} end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
23 24 25 |
# File 'lib/bugsnag/report.rb', line 23 def api_key @api_key end |
#app_type ⇒ Object
Returns the value of attribute app_type.
24 25 26 |
# File 'lib/bugsnag/report.rb', line 24 def app_type @app_type end |
#app_version ⇒ Object
Returns the value of attribute app_version.
25 26 27 |
# File 'lib/bugsnag/report.rb', line 25 def app_version @app_version end |
#configuration ⇒ Object
Returns the value of attribute configuration.
26 27 28 |
# File 'lib/bugsnag/report.rb', line 26 def configuration @configuration end |
#context ⇒ Object
Returns the value of attribute context.
27 28 29 |
# File 'lib/bugsnag/report.rb', line 27 def context @context end |
#delivery_method ⇒ Object
Returns the value of attribute delivery_method.
28 29 30 |
# File 'lib/bugsnag/report.rb', line 28 def delivery_method @delivery_method end |
#exceptions ⇒ Object
Returns the value of attribute exceptions.
29 30 31 |
# File 'lib/bugsnag/report.rb', line 29 def exceptions @exceptions end |
#grouping_hash ⇒ Object
Returns the value of attribute grouping_hash.
31 32 33 |
# File 'lib/bugsnag/report.rb', line 31 def grouping_hash @grouping_hash end |
#hostname ⇒ Object
Returns the value of attribute hostname.
30 31 32 |
# File 'lib/bugsnag/report.rb', line 30 def hostname @hostname end |
#meta_data ⇒ Object
Returns the value of attribute meta_data.
32 33 34 |
# File 'lib/bugsnag/report.rb', line 32 def @meta_data end |
#raw_exceptions ⇒ Object
Returns the value of attribute raw_exceptions.
33 34 35 |
# File 'lib/bugsnag/report.rb', line 33 def raw_exceptions @raw_exceptions end |
#release_stage ⇒ Object
Returns the value of attribute release_stage.
34 35 36 |
# File 'lib/bugsnag/report.rb', line 34 def release_stage @release_stage end |
#session ⇒ Object
Returns the value of attribute session.
35 36 37 |
# File 'lib/bugsnag/report.rb', line 35 def session @session end |
#severity ⇒ Object
Returns the value of attribute severity.
36 37 38 |
# File 'lib/bugsnag/report.rb', line 36 def severity @severity end |
#severity_reason ⇒ Object
Returns the value of attribute severity_reason.
37 38 39 |
# File 'lib/bugsnag/report.rb', line 37 def severity_reason @severity_reason end |
#unhandled ⇒ Object (readonly)
Returns the value of attribute unhandled.
22 23 24 |
# File 'lib/bugsnag/report.rb', line 22 def unhandled @unhandled end |
#user ⇒ Object
Returns the value of attribute user.
38 39 40 |
# File 'lib/bugsnag/report.rb', line 38 def user @user end |
Instance Method Details
#add_tab(name, value) ⇒ Object
Add a new metadata tab to this notification.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bugsnag/report.rb', line 65 def add_tab(name, value) return if name.nil? if value.is_a? Hash [name] ||= {} [name].merge! value else ["custom"] = {} unless ["custom"] ["custom"][name.to_s] = value end end |
#as_json ⇒ Object
Builds and returns the exception payload for this notification.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/bugsnag/report.rb', line 88 def as_json # Build the payload's exception event payload_event = { app: { version: app_version, releaseStage: release_stage, type: app_type }, context: context, device: { hostname: hostname }, exceptions: exceptions, groupingHash: grouping_hash, session: session, severity: severity, severityReason: severity_reason, unhandled: @unhandled, user: user } # cleanup character encodings payload_event = Bugsnag::Cleaner.clean_object_encoding(payload_event) # filter out sensitive values in (and cleanup encodings) metaData payload_event[:metaData] = Bugsnag::Cleaner.new(configuration.).clean_object() payload_event.reject! {|k,v| v.nil? } # return the payload hash { :apiKey => api_key, :notifier => { :name => NOTIFIER_NAME, :version => NOTIFIER_VERSION, :url => NOTIFIER_URL }, :events => [payload_event] } end |
#headers ⇒ Object
Returns the headers required for the notification.
130 131 132 133 134 135 136 |
# File 'lib/bugsnag/report.rb', line 130 def headers { "Bugsnag-Api-Key" => api_key, "Bugsnag-Payload-Version" => CURRENT_PAYLOAD_VERSION, "Bugsnag-Sent-At" => Time.now().utc().strftime('%Y-%m-%dT%H:%M:%S') } end |
#ignore! ⇒ Object
Tells the client this report should not be sent.
152 153 154 |
# File 'lib/bugsnag/report.rb', line 152 def ignore! @should_ignore = true end |
#ignore? ⇒ Boolean
Whether this report should be ignored and not sent.
140 141 142 |
# File 'lib/bugsnag/report.rb', line 140 def ignore? @should_ignore end |
#remove_tab(name) ⇒ Object
Removes a metadata tab from this notification.
80 81 82 83 84 |
# File 'lib/bugsnag/report.rb', line 80 def remove_tab(name) return if name.nil? .delete(name) end |
#request_data ⇒ Object
Data set on the configuration to be attached to every error notification.
146 147 148 |
# File 'lib/bugsnag/report.rb', line 146 def request_data configuration.request_data end |