← All platforms

Gin error tracking

Gin can recover a panicking request. You’ll still want to know why it happened. The Sentry Gin middleware sends the report to your Telebugs server.

~/hoofnotes  go get github.com/getsentry/sentry-go/gin
~/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"
sentrygin "github.com/getsentry/sentry-go/gin"
"github.com/gin-gonic/gin"
)
func main() {
if err := initErrorTracking(); err != nil {
panic(err)
}
defer sentry.Flush(2 * time.Second)
app := gin.Default()
app.Use(sentrygin.New(sentrygin.Options{Repanic: true}))
registerNotesRoutes(app)
app.Run(":3000")
}
~/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 Gin recover and still send a report?

Yes. The Sentry middleware reports the panic, then lets Gin’s recovery handle the response. Use the request’s Sentry hub to include context when reporting handled errors too.

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.