Go / Fiber

Instrument Fiber APIs.

Capture resolved Fiber route templates, customer context, returned errors and panics through fail-safe middleware.

Fiber v2SDK 0.1.0 · Go 1.23+Production ready
01

Go module

Install one adapter.

Go Core is installed automatically as a dependency.

Terminalbash
go get github.com/pryznar/apirelio-fiber@v0.1.0
02

Middleware

Register after authentication.

main.gogo
client := apirelio.New(apirelio.Config{
    APIKey:      os.Getenv("APIRELIO_API_KEY"),
    Endpoint:    "https://apirelio.com",
    Service:     "billing-api",
    Environment: apirelio.EnvironmentProduction,
    Release:     os.Getenv("APP_RELEASE"),
})

app := fiber.New()
app.Use(authenticationMiddleware())
app.Use(recover.New())
app.Use(apireliofiber.Middleware(client, apireliofiber.Options{}))
Middleware order

Authentication should establish the account first. Keep Fiber's recover middleware outside Apirelio so recorded panics continue through the normal recovery chain.

03

B2B context

Resolve stable business identifiers.

Resolvers run after downstream handlers. Return internal account and API-client identifiers; do not attach email addresses, tokens or other personal data.

Customer and application resolversgo
app.Use(apireliofiber.Middleware(client, apireliofiber.Options{
    ResolveCustomer: func(ctx *fiber.Ctx) *apirelio.Customer {
        account, ok := ctx.Locals("account").(*Account)
        if !ok {
            return nil
        }
        return &apirelio.Customer{
            ID: account.ID, Name: account.Name, Plan: account.Plan,
        }
    },
    ResolveApplication: func(ctx *fiber.Ctx) *apirelio.Application {
        return &apirelio.Application{ID: ctx.Get("X-Client-ID")}
    },
}))
04

Outcomes

Preserve errors, narrow the scope.

Error and route optionsgo
apireliofiber.Options{
    IncludeRoutes: []string{"/api/**"},
    ExcludeRoutes: []string{"/api/health", "/api/internal/**"},
    ResolveErrorCode: func(ctx *fiber.Ctx, err error) string {
        return stableErrorCode(err)
    },
}

Returned *fiber.Error values retain their HTTP status. Panics are recorded as 500 and re-thrown. Route patterns are exact or end in /**; exclusions always win.

05

Lifecycle

Flush within a deadline.

Application shutdowngo
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if err := client.Shutdown(shutdownCtx); err != nil {
    log.Printf("Apirelio shutdown: %v", err)
}

The middleware only enqueues. Go Core batches outside the request path and retries transient delivery failures. Resolver, capture and transport failures never replace the customer response.

Privacy boundary

Request and response bodies, query strings, credentials, cookies, email addresses and client IP addresses are never included.