← All platforms

net/http error tracking

The standard library is enough for plenty of Go servers. Add Sentry’s net/http wrapper and keep their error reports on your Telebugs server.

~/hoofnotes  go get github.com/getsentry/sentry-go/http
~/hoofnotes  nvim error_tracking.go main.go
package main
import "github.com/getsentry/sentry-go"
func initErrorTracking() error {
return sentry.Init(sentry.ClientOptions{
// Copy the complete Telebugs DSN, key and path included.
Dsn: "YOUR_TELEBUGS_DSN",
})
}
package main
import (
"time"
"github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http"
"net/http"
)
func main() {
if err := initErrorTracking(); err != nil {
panic(err)
}
defer sentry.Flush(2 * time.Second)
handler := sentryhttp.New(sentryhttp.Options{
Repanic: true,
})
http.Handle("/notes", handler.Handle(notesHandler))
http.ListenAndServe(":3000", nil)
}
~/hoofnotes  go run .

Space pauses or resumes. R replays. Escape shows the complete setup.

Hang on, I already use Sentry

Keep sentry-go and change its destination to your Telebugs DSN. Your error reports stay on your server. You don’t need a Sentry account.

Do I need a web framework?

No. The SDK wraps an ordinary http.Handler or http.HandlerFunc. Keep your standard-library server and report the panics that happen during requests.

What about errors I return instead of panicking?

Go errors are values. Report one explicitly with CaptureException when it matters. A middleware connection doesn’t automatically turn every returned error into a report.