Go / Gin

Instrument Gin APIs.

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

Gin 1.12SDK 0.1.0 · Go 1.25+Production ready
01

Go module

Install one adapter.

Go Core is installed automatically as a dependency.

Terminalbash
go get github.com/pryznar/apirelio-gin@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"),
})

router := gin.New()
router.Use(authenticationMiddleware())
router.Use(gin.Recovery())
router.Use(apireliogin.Middleware(client, apireliogin.Options{}))
Middleware order

Authentication should establish the account first. Keep gin.Recovery() outside Apirelio so recorded panics continue through Gin's normal recovery chain.

03

B2B context

Resolve stable business identifiers.

Resolvers run after the route handler. Return internal account and API-client identifiers; do not use email addresses, tokens or other personal data.

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

Scope

Keep only relevant routes.

Route optionsgo
apireliogin.Options{
    IncludeRoutes: []string{"/api/**"},
    ExcludeRoutes: []string{"/api/health", "/api/internal/**"},
    APIVersionHeader: "X-API-Version",
}

Patterns are exact paths or bounded prefixes ending 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.