Skip to content

HTTP integration guide

Typical installation time: 5 minutes

Hi there! You’ve found Honeybadger’s guide to Go error tracking for applications using the net/http package. Once installed, Honeybadger will automatically report panics from your HTTP handlers.

To install, grab the package from GitHub:

Terminal window
go get github.com/honeybadger-io/honeybadger-go

Then add an import to your application code:

import "github.com/honeybadger-io/honeybadger-go"

Configure your API key using honeybadger.Configure:

honeybadger.Configure(honeybadger.Configuration{APIKey: "PROJECT_API_KEY"})

You can also configure Honeybadger via the HONEYBADGER_API_KEY environment variable. See Configuration for more options.

To automatically report panics which happen during an HTTP request, wrap your http.Handler function with honeybadger.Handler:

log.Fatal(http.ListenAndServe(":8080", honeybadger.Handler(handler)))

Request data such as cookies and params will automatically be reported with errors which happen inside honeybadger.Handler. Make sure you recover from panics after Honeybadger’s Handler has been executed to ensure all panics are reported.

When a panic occurs inside honeybadger.Handler, the following request data is automatically included in the error report:

  • Request URL and method
  • URL query parameters
  • Form data (if parsed)
  • HTTP headers (as CGI variables)
  • Cookies

For manually reported errors, pass the request to include this data:

func myHandler(w http.ResponseWriter, r *http.Request) {
if err := doSomething(); err != nil {
honeybadger.Notify(err, r)
}
}

See Reporting errors for more options.

To verify that your installation is working, you can trigger a test panic in one of your HTTP handlers:

func testHandler(w http.ResponseWriter, r *http.Request) {
panic("Testing Honeybadger!")
}

Visit the route that triggers this handler, then check your Honeybadger dashboard for the error.