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 ⇒ String?
Your Integration API Key.
-
#app_type ⇒ String?
The type of application executing the current code.
-
#app_version ⇒ String?
The current version of your application.
-
#breadcrumbs ⇒ Array<Breadcrumb>
The list of breadcrumbs attached to this report.
-
#context ⇒ String?
Additional context for this report.
-
#delivery_method ⇒ Symbol
The delivery method that will be used for this report.
-
#exceptions ⇒ Array<Hash>
The list of exceptions in this report.
-
#grouping_hash ⇒ String
All errors with the same grouping hash will be grouped in the Bugsnag app.
- #hostname ⇒ String
-
#meta_data ⇒ Hash
Arbitrary metadata attached to this report.
-
#raw_exceptions ⇒ Array<Exception>
The raw Exception instances for this report.
-
#release_stage ⇒ String?
The current stage of the release process, e.g.
-
#session ⇒ Hash
The session that active when this report was generated.
-
#severity ⇒ String
The severity of this report, e.g.
-
#unhandled ⇒ Boolean
readonly
Whether this report is for a handled or unhandled error.
-
#user ⇒ Hash
The current user when this report was generated.
Instance Method Summary collapse
-
#add_tab(name, value) ⇒ void
Add a new metadata tab to this notification.
-
#as_json ⇒ Hash
Builds and returns the exception payload for this notification.
-
#headers ⇒ Hash{String => String}
Returns the headers required for the notification.
-
#ignore! ⇒ void
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) ⇒ void
Removes a metadata tab from this notification.
-
#request_data ⇒ Hash
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.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bugsnag/report.rb', line 107 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 ⇒ String?
Your Integration API Key
29 30 31 |
# File 'lib/bugsnag/report.rb', line 29 def api_key @api_key end |
#app_type ⇒ String?
The type of application executing the current code
34 35 36 |
# File 'lib/bugsnag/report.rb', line 34 def app_type @app_type end |
#app_version ⇒ String?
The current version of your application
38 39 40 |
# File 'lib/bugsnag/report.rb', line 38 def app_version @app_version end |
#breadcrumbs ⇒ Array<Breadcrumb>
The list of breadcrumbs attached to this report
42 43 44 |
# File 'lib/bugsnag/report.rb', line 42 def @breadcrumbs end |
#context ⇒ String?
Additional context for this report
50 51 52 |
# File 'lib/bugsnag/report.rb', line 50 def context @context end |
#delivery_method ⇒ Symbol
The delivery method that will be used for this report
55 56 57 |
# File 'lib/bugsnag/report.rb', line 55 def delivery_method @delivery_method end |
#exceptions ⇒ Array<Hash>
The list of exceptions in this report
59 60 61 |
# File 'lib/bugsnag/report.rb', line 59 def exceptions @exceptions end |
#grouping_hash ⇒ String
All errors with the same grouping hash will be grouped in the Bugsnag app
72 73 74 |
# File 'lib/bugsnag/report.rb', line 72 def grouping_hash @grouping_hash end |
#hostname ⇒ String
63 64 65 |
# File 'lib/bugsnag/report.rb', line 63 def hostname @hostname end |
#meta_data ⇒ Hash
Arbitrary metadata attached to this report
76 77 78 |
# File 'lib/bugsnag/report.rb', line 76 def @meta_data end |
#raw_exceptions ⇒ Array<Exception>
The raw Exception instances for this report
81 82 83 |
# File 'lib/bugsnag/report.rb', line 81 def raw_exceptions @raw_exceptions end |
#release_stage ⇒ String?
The current stage of the release process, e.g. ‘development’, production’
86 87 88 |
# File 'lib/bugsnag/report.rb', line 86 def release_stage @release_stage end |
#session ⇒ Hash
The session that active when this report was generated
91 92 93 |
# File 'lib/bugsnag/report.rb', line 91 def session @session end |
#severity ⇒ String
The severity of this report, e.g. ‘error’, ‘warning’
95 96 97 |
# File 'lib/bugsnag/report.rb', line 95 def severity @severity end |
#unhandled ⇒ Boolean (readonly)
Whether this report is for a handled or unhandled error
24 25 26 |
# File 'lib/bugsnag/report.rb', line 24 def unhandled @unhandled end |
#user ⇒ Hash
The current user when this report was generated
103 104 105 |
# File 'lib/bugsnag/report.rb', line 103 def user @user end |
Instance Method Details
#add_tab(name, value) ⇒ void
This method returns an undefined value.
Add a new metadata tab to this notification.
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/bugsnag/report.rb', line 138 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 ⇒ Hash
Builds and returns the exception payload for this notification.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/bugsnag/report.rb', line 166 def as_json # Build the payload's exception event payload_event = { app: { version: app_version, releaseStage: release_stage, type: app_type }, breadcrumbs: .map(&:to_h), context: context, device: { hostname: hostname, runtimeVersions: runtime_versions }, exceptions: exceptions, groupingHash: grouping_hash, metaData: , session: session, severity: severity, severityReason: severity_reason, unhandled: @unhandled, user: user } 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 ⇒ Hash{String => String}
Returns the headers required for the notification.
208 209 210 211 212 213 214 |
# File 'lib/bugsnag/report.rb', line 208 def headers { "Bugsnag-Api-Key" => api_key, "Bugsnag-Payload-Version" => CURRENT_PAYLOAD_VERSION, "Bugsnag-Sent-At" => Time.now.utc.iso8601(3) } end |
#ignore! ⇒ void
This method returns an undefined value.
Tells the client this report should not be sent.
236 237 238 |
# File 'lib/bugsnag/report.rb', line 236 def ignore! @should_ignore = true end |
#ignore? ⇒ Boolean
Whether this report should be ignored and not sent.
220 221 222 |
# File 'lib/bugsnag/report.rb', line 220 def ignore? @should_ignore end |
#remove_tab(name) ⇒ void
This method returns an undefined value.
Removes a metadata tab from this notification.
156 157 158 159 160 |
# File 'lib/bugsnag/report.rb', line 156 def remove_tab(name) return if name.nil? .delete(name) end |
#request_data ⇒ Hash
Data set on the configuration to be attached to every error notification.
228 229 230 |
# File 'lib/bugsnag/report.rb', line 228 def request_data configuration.request_data end |
#summary ⇒ Hash
Generates a summary to be attached as a breadcrumb
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/bugsnag/report.rb', line 244 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 |