In order to quickly understand and fix some errors, it is often helpful to send additional diagnostic data which is specific to that error.
The notify
and notifyError
functions accept a block to modify the error
report using a representation of the report which will be sent. Below are the
available options for modifying the report.
report
objectcontext
Set the context of the error report. This is normally the location of the error and should be populated automatically. Context is displayed in the dashboard prominently.
Bugsnag.notify(exception, block: { report in
report.context = "XYZMenuController"
})
depth
Set the number of frames discarded at the top of the stacktrace. By default, this value is the number of frames within Bugsnag’s library, but you can increase this number particularly if you have a single place to log errors and/or exceptions and wish to avoid grouping in that function.
func logError(err: NSError) {
Bugsnag.notifyError(err) { report in
// Increment the number of stackframes to discard
report.depth += 1
}
}
errorClass
The type of the error which generated the report. This should be populated automatically with the class name of the error.
Bugsnag.notify(exception, block: { report in
report.errorClass = "Authentication failed"
})
errorMessage
The message or description of the error which generated the report.
Bugsnag.notify(exception, block: { report in
report.errorMessage = "Username rejected by the auth server"
})
groupingHash
Sets the grouping hash of the error report. All errors with the same grouping hash are grouped together. This is an advanced usage of the library and mis-using it will cause your errors not to group properly in your dashboard.
Bugsnag.notify(exception, block: { report in
report.groupingHash = "unexpected-auth-failures"
})
metaData
The metaData
property is mapped to the metadata tabs on a reports in the
Bugsnag dashboard. Each top level key indicates an additional tab.
To attach additional diagnostic data to a report, use the addMetadata
method,
which merges added data into the existing metadata in a report.
Bugsnag.notify(exception, block: { report in
let meals = ["breakfast": "eggs and toast",
"lunch": "hamburger"]
report.addMetadata(meals, toTabWithName: "food")
// use addAttribute() to add an individual value
report.addAttribute("dessert", withValue: "cake", toTabWithName: "meals");
})
To edit and remove diagnostic data included in a report, edit the metaData
property directly.
Bugsnag.notify(exception, block: { report in
if var metadata = report.metaData as? [String: [String: Any]] {
if var supportInfo = metadata["support-info"] {
supportInfo.removeValue(forKey: "password")
metadata["support-info"] = supportInfo
}
report.metaData = metadata
}
})
releaseStage
The stage of development of the application currently running.
Bugsnag.notify(exception, block: { report in
report.releaseStage = "beta-group-23"
})
severity
A rating of how critical an error report is.
Bugsnag.notify(exception, block: { report in
report.severity = .error;
})