Connect Negroni to Bugsink
When a Negroni handler panics, Bugsink shows you the error, the application frame that raised it, and the HTTP request that reached the handler.
This guide covers the initial setup and Negroni’s automatic capture of downstream panics. You’ll add the SDK middleware to an existing Negroni 3 application, then make one request fail to confirm that it reaches Bugsink.
To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the SDK
The current integration uses Negroni 3. In an existing Negroni 3 module, add the open-source SDK integration:
go get github.com/getsentry/sentry-go/negronigo get github.com/getsentry/sentry-go/negroni
Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project.
Initialize the SDK
Import the base SDK and Negroni integration where you assemble the middleware stack:
"github.com/getsentry/sentry-go" sentrynegroni "github.com/getsentry/sentry-go/negroni" "github.com/urfave/negroni/v3""github.com/getsentry/sentry-go" sentrynegroni "github.com/getsentry/sentry-go/negroni" "github.com/urfave/negroni/v3"
Initialize the SDK before creating the application. Reading the DSN from the environment keeps it out of source control:
err := sentry.Init(sentry.ClientOptions{ Dsn: os.Getenv("SENTRY_DSN"), }) if err != nil { log.Fatal(err) } defer sentry.Flush(5 * time.Second)err := sentry.Init(sentry.ClientOptions{ Dsn: os.Getenv("SENTRY_DSN"), }) if err != nil { log.Fatal(err) } defer sentry.Flush(5 * time.Second)
Set SENTRY_DSN in the environment where the service runs:
export SENTRY_DSN=https://key@bugsink.example/1export SENTRY_DSN=https://key@bugsink.example/1
Add the Negroni middleware
Create Negroni with its recovery middleware, then add the SDK middleware.
The SDK captures the panic and request; Repanic passes it outward so
Negroni’s recovery handler still controls the HTTP 500 response:
application := negroni.New(negroni.NewRecovery()) application.Use(sentrynegroni.New(sentrynegroni.Options{ Repanic: true, }))application := negroni.New(negroni.NewRecovery()) application.Use(sentrynegroni.New(sentrynegroni.Options{ Repanic: true, }))
Add the application’s final handler after those middleware layers.
Trigger a handler panic
There is no Bugsink call inside a handler. To verify the setup, this checkout handler panics with an error value when the requested product is missing:
func checkout(response http.ResponseWriter, request *http.Request) { sku := request.PathValue("sku") if _, exists := inventory[sku]; !exists { panic(ProductNotFound{SKU: sku}) } response.Header().Set("Content-Type", "application/json") fmt.Fprintf(response, `{"reserved":%q}`, sku) }func checkout(response http.ResponseWriter, request *http.Request) { sku := request.PathValue("sku") if _, exists := inventory[sku]; !exists { panic(ProductNotFound{SKU: sku}) } response.Header().Set("Content-Type", "application/json") fmt.Fprintf(response, `{"reserved":%q}`, sku) }
The error value gives the SDK an exception type and panic stack. A plain string panic becomes a fatal message without a stack by default.
Start Negroni as usual, then request a product that does not exist:
go run . :::bash curl http://127.0.0.1:8080/checkout/negroni-missinggo run . :::bash curl http://127.0.0.1:8080/checkout/negroni-missing
Negroni returns HTTP 500 and the middleware reports the panic.
See the error in Bugsink
Open your Bugsink project and select the new main.ProductNotFound issue. Its
event identifies the failing checkout handler and includes the GET request.
main.ProductNotFound
That’s it: panics from downstream Negroni handlers will now be reported to Bugsink. The handler stays ordinary application code while the middleware adds its panic stack and request context.
For handled errors, messages, tags, structured context, and breadcrumbs, continue with the Go guide.
