Current Version: 0.3
The bugsnag grails plugin integrates the bugsnag client into a grails application and automatically reports errors to the bugsnag service (www.bugsnag.com). Information reported includes a dump of the original request (headers, cookies, query string, original URL, grails environment, etc), the currently logged in user, and a stacktrace of the exception.
compile ":bugsnag:0.3"
- 0.3 - added support for 'notifyreleasestages' configuration option. updated to latest bugsnag java client (1.2.8)
- 0.2 - added metadata customization callback to bugsnagService, added optional extra data map to bugsnagService.notify, added session dump to report
- 0.1 - first release
Simply enabling the bugsnag plugin automatically configures error reporting capabilities. All uncaught exceptions will be reported to bugsnag.
Config.groovy
grails.plugin.bugsnag.enabled = true
grails.plugin.bugsnag.apikey = "<bugsnag API key>"
name | default | description |
---|---|---|
grails.plugin.bugsnag.enabled | false | enable or disables bugsnag. |
grails.plugin.bugsnag.apikey | (not set) | API Key provided by bugsnag to report to. |
In addition to automatic error reporting, the bugsnag plugin implements bugsnagService which can be used directly in your application to send notifications. The following is an example of how to use bugsnagService to report caught exceptions.
// in a controller class
def bugsnagService // autowired
// somewhere in a method
def index() {
try{
// something breaks
}
catch( excp ){
// handle exception
def mapOfExtraMetaData = [:] //
bugsnagService.notify(request,excp,mapOfExtraMetadData) // assumes you're calling from a controller where the request object is in scope
}
//... render something eventually
}
method name | description | parameters | returns |
---|---|---|---|
getConfiguredClient | Gets a fully configured Client object. |
|
com.bugsnag.Client object |
notify | sends a configured notification to bugsnag. |
|
nothing |
The bugsnagService has the ability to add user-defined metaData to reports. To use this feature, add the bugsnagService to BootStrap.groovy and assign a closure to the addMetadata property. In the closure, add code that assigns values to the provided metaData class instance. The addMetadata closure will be called everytime is notification is sent bugsnag.
def bugsnagService
def init = { servletContext ->
bugsnagService.addMetadata = { metaData ->
// do an inspection of the current application state
def customfield1 = "" // assign meaningful value
def customfield2 = "" // assign meaningful value
// add the values to the metadata
metaData.addToTab( "custom", "customfield1", customfield1 )
metaData.addToTab( "custom", "customfield2", customfield2 )
}
}
The plugin works by injecting a customized GrailsExceptionResolver into the application context (replacing the default object) which intercepts resolveException and reports using the bugsnagService before calling the superclass.
future versions will include the ability to customize the messages sent to bugsnag to include user defined code.