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.
Installing the package
Section titled “Installing the package”To install, grab the package from GitHub:
go get github.com/honeybadger-io/honeybadger-goThen add an import to your application code:
import "github.com/honeybadger-io/honeybadger-go"Configuring your API key
Section titled “Configuring your API key”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.
Enabling automatic panic reporting
Section titled “Enabling automatic panic reporting”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.
What data is captured
Section titled “What data is captured”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.
Testing your installation
Section titled “Testing your installation”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.
Next steps
Section titled “Next steps”- Learn how to report errors manually
- Add context to your errors
- Explore configuration options