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.
-
#breadcrumbs ⇒ Object
Returns the value of attribute breadcrumbs.
-
#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.
-
#runtime_versions ⇒ Object
Returns the value of attribute runtime_versions.
-
#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.
-
#summary ⇒ Hash
Generates a summary to be attached as a breadcrumb.
Constructor Details
#initialize(exception, passed_configuration, auto_notify = false) ⇒ Report
Initializes a new report from an exception.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bugsnag/report.rb', line 44 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. = [] self.delivery_method = configuration.delivery_method self.hostname = configuration.hostname self.runtime_versions = configuration.runtime_versions.dup 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 |
#breadcrumbs ⇒ Object
Returns the value of attribute breadcrumbs.
26 27 28 |
# File 'lib/bugsnag/report.rb', line 26 def @breadcrumbs end |
#configuration ⇒ Object
Returns the value of attribute configuration.
27 28 29 |
# File 'lib/bugsnag/report.rb', line 27 def configuration @configuration end |
#context ⇒ Object
Returns the value of attribute context.
28 29 30 |
# File 'lib/bugsnag/report.rb', line 28 def context @context end |
#delivery_method ⇒ Object
Returns the value of attribute delivery_method.
29 30 31 |
# File 'lib/bugsnag/report.rb', line 29 def delivery_method @delivery_method end |
#exceptions ⇒ Object
Returns the value of attribute exceptions.
30 31 32 |
# File 'lib/bugsnag/report.rb', line 30 def exceptions @exceptions end |
#grouping_hash ⇒ Object
Returns the value of attribute grouping_hash.
33 34 35 |
# File 'lib/bugsnag/report.rb', line 33 def grouping_hash @grouping_hash end |
#hostname ⇒ Object
Returns the value of attribute hostname.
31 32 33 |
# File 'lib/bugsnag/report.rb', line 31 def hostname @hostname end |
#meta_data ⇒ Object
Returns the value of attribute meta_data.
34 35 36 |
# File 'lib/bugsnag/report.rb', line 34 def @meta_data end |
#raw_exceptions ⇒ Object
Returns the value of attribute raw_exceptions.
35 36 37 |
# File 'lib/bugsnag/report.rb', line 35 def raw_exceptions @raw_exceptions end |
#release_stage ⇒ Object
Returns the value of attribute release_stage.
36 37 38 |
# File 'lib/bugsnag/report.rb', line 36 def release_stage @release_stage end |
#runtime_versions ⇒ Object
Returns the value of attribute runtime_versions.
32 33 34 |
# File 'lib/bugsnag/report.rb', line 32 def runtime_versions @runtime_versions end |
#session ⇒ Object
Returns the value of attribute session.
37 38 39 |
# File 'lib/bugsnag/report.rb', line 37 def session @session end |
#severity ⇒ Object
Returns the value of attribute severity.
38 39 40 |
# File 'lib/bugsnag/report.rb', line 38 def severity @severity end |
#severity_reason ⇒ Object
Returns the value of attribute severity_reason.
39 40 41 |
# File 'lib/bugsnag/report.rb', line 39 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.
40 41 42 |
# File 'lib/bugsnag/report.rb', line 40 def user @user end |
Instance Method Details
#add_tab(name, value) ⇒ Object
Add a new metadata tab to this notification.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bugsnag/report.rb', line 69 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.
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 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/bugsnag/report.rb', line 92 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, runtimeVersions: runtime_versions }, 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 filter_cleaner = Bugsnag::Cleaner.new(configuration.) payload_event[:metaData] = filter_cleaner.clean_object() payload_event[:breadcrumbs] = .map do || = .to_h [:metaData] = filter_cleaner.clean_object([:metaData]) end 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.
142 143 144 145 146 147 148 |
# File 'lib/bugsnag/report.rb', line 142 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.
164 165 166 |
# File 'lib/bugsnag/report.rb', line 164 def ignore! @should_ignore = true end |
#ignore? ⇒ Boolean
Whether this report should be ignored and not sent.
152 153 154 |
# File 'lib/bugsnag/report.rb', line 152 def ignore? @should_ignore end |
#remove_tab(name) ⇒ Object
Removes a metadata tab from this notification.
84 85 86 87 88 |
# File 'lib/bugsnag/report.rb', line 84 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.
158 159 160 |
# File 'lib/bugsnag/report.rb', line 158 def request_data configuration.request_data end |
#summary ⇒ Hash
Generates a summary to be attached as a breadcrumb
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/bugsnag/report.rb', line 172 def summary # Guard against the exceptions array being removed/changed or emptied here if exceptions.respond_to?(:first) && exceptions.first { :error_class => exceptions.first[:errorClass], :message => exceptions.first[:message], :severity => severity } else { :error_class => "Unknown", :severity => severity } end end |