doc.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Package bugsnag captures errors in real-time and reports them to Bugsnag (http://bugsnag.com).
  3. Using bugsnag-go is a three-step process.
  4. 1. As early as possible in your program configure the notifier with your APIKey. This sets up
  5. handling of panics that would otherwise crash your app.
  6. func init() {
  7. bugsnag.Configure(bugsnag.Configuration{
  8. APIKey: "YOUR_API_KEY_HERE",
  9. })
  10. }
  11. 2. Add bugsnag to places that already catch panics. For example you should add it to the HTTP server
  12. when you call ListenAndServer:
  13. http.ListenAndServe(":8080", bugsnag.Handler(nil))
  14. If that's not possible, for example because you're using Google App Engine, you can also wrap each
  15. HTTP handler manually:
  16. http.HandleFunc("/" bugsnag.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
  17. ...
  18. })
  19. 3. To notify Bugsnag of an error that is not a panic, pass it to bugsnag.Notify. This will also
  20. log the error message using the configured Logger.
  21. if err != nil {
  22. bugsnag.Notify(err)
  23. }
  24. For detailed integration instructions see https://bugsnag.com/docs/notifiers/go.
  25. Configuration
  26. The only required configuration is the Bugsnag API key which can be obtained by clicking "Settings"
  27. on the top of https://bugsnag.com/ after signing up. We also recommend you set the ReleaseStage,
  28. AppType, and AppVersion if these make sense for your deployment workflow.
  29. RawData
  30. If you need to attach extra data to Bugsnag notifications you can do that using
  31. the rawData mechanism. Most of the functions that send errors to Bugsnag allow
  32. you to pass in any number of interface{} values as rawData. The rawData can
  33. consist of the Severity, Context, User or MetaData types listed below, and
  34. there is also builtin support for *http.Requests.
  35. bugsnag.Notify(err, bugsnag.SeverityError)
  36. If you want to add custom tabs to your bugsnag dashboard you can pass any value in as rawData,
  37. and then process it into the event's metadata using a bugsnag.OnBeforeNotify() hook.
  38. bugsnag.Notify(err, account)
  39. bugsnag.OnBeforeNotify(func (e *bugsnag.Event, c *bugsnag.Configuration) {
  40. for datum := range e.RawData {
  41. if account, ok := datum.(Account); ok {
  42. e.MetaData.Add("account", "name", account.Name)
  43. e.MetaData.Add("account", "url", account.URL)
  44. }
  45. }
  46. })
  47. If necessary you can pass Configuration in as rawData, or modify the Configuration object passed
  48. into OnBeforeNotify hooks. Configuration passed in this way only affects the current notification.
  49. */
  50. package bugsnag