Connect FastHTTP to Bugsink
When a FastHTTP 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 automatic panic capture for a FastHTTP server. You’ll wrap an existing request handler with the SDK middleware, 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
Add the open-source Sentry SDK’s FastHTTP integration to your module. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project:
go get github.com/getsentry/sentry-go/fasthttpgo get github.com/getsentry/sentry-go/fasthttp
Initialize the SDK
Import the base SDK and FastHTTP integration alongside the framework:
"github.com/getsentry/sentry-go" sentryfasthttp "github.com/getsentry/sentry-go/fasthttp" "github.com/valyala/fasthttp""github.com/getsentry/sentry-go" sentryfasthttp "github.com/getsentry/sentry-go/fasthttp" "github.com/valyala/fasthttp"
Initialize the SDK before starting the server. 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
Wrap the request handler
FastHTTP does not provide panic recovery itself. Wrap the application handler
with the SDK, then put your own recovery handler around it. Repanic reports
the panic before passing it outward so your recovery code can still choose the
HTTP response:
sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{ Repanic: true, }) address := ":" + getenv("PORT", "8080") log.Printf("Inventory application listening on %s", address) log.Fatal(fasthttp.ListenAndServe( address, recoverWithErrorResponse(sentryHandler.Handle(router)), ))sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{ Repanic: true, }) address := ":" + getenv("PORT", "8080") log.Printf("Inventory application listening on %s", address) log.Fatal(fasthttp.ListenAndServe( address, recoverWithErrorResponse(sentryHandler.Handle(router)), ))
If your application already has recovery middleware, keep it as the outer wrapper in the same way.
Trigger a handler panic
There is no Bugsink call inside the router. To verify the setup, its checkout branch panics with an error value when the requested product is missing:
case strings.HasPrefix(path, "/checkout/"): sku := strings.TrimPrefix(path, "/checkout/") if _, exists := inventory[sku]; !exists { panic(ProductNotFound{SKU: sku}) } context.Response.Header.SetContentType("application/json") json.NewEncoder(context).Encode(map[string]string{"reserved": sku})case strings.HasPrefix(path, "/checkout/"): sku := strings.TrimPrefix(path, "/checkout/") if _, exists := inventory[sku]; !exists { panic(ProductNotFound{SKU: sku}) } context.Response.Header.SetContentType("application/json") json.NewEncoder(context).Encode(map[string]string{"reserved": 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 the server as usual, then request a product that does not exist:
go run . :::bash curl http://127.0.0.1:8080/checkout/fasthttp-missinggo run . :::bash curl http://127.0.0.1:8080/checkout/fasthttp-missing
The recovery handler returns HTTP 500 and the SDK 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 router frame and includes the GET request.
main.ProductNotFound
That’s it: panics from the wrapped FastHTTP handler will now be reported to Bugsink. The router remains ordinary application code while the integration adds its panic stack and request context.
For handled errors, messages, tags, structured context, and breadcrumbs, continue with the Go guide.
