← All platforms

Negroni error tracking

Your middleware has a place for error reporting. Add the Sentry Negroni handler and send panic reports to Telebugs on your own server.

~/hoofnotes  go get github.com/getsentry/sentry-go/negroni
~/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"
sentrynegroni "github.com/getsentry/sentry-go/negroni"
"net/http"
"github.com/urfave/negroni/v3"
)
func main() {
if err := initErrorTracking(); err != nil {
panic(err)
}
defer sentry.Flush(2 * time.Second)
app := negroni.Classic()
app.Use(sentrynegroni.New(sentrynegroni.Options{Repanic: true}))
app.UseHandler(mux)
http.ListenAndServe(":3000", app)
}
~/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.

Can I keep my existing mux?

Yes. Negroni’s Sentry middleware sits around your HTTP handler. Your router stays in place, and request panics can be reported before recovery handles them.

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.