apmfiberv3

package module
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package apmfiberv3 is the Fiber v3 adapter for the apmcore Elastic APM instrumentation engine.

Fiber v3 has no upstream apmfiber module (only v2 is published by Elastic), so this package implements a minimal middleware that mirrors the v2 one: it starts an APM transaction on the underlying *fasthttp.RequestCtx, names it "<METHOD> <route-template>" after the handler chain runs, recovers panics, and captures bubbled errors.

All trace plumbing happens via c.RequestCtx(); APM stores the transaction there (matching the v2 behavior). Code that reads the transaction inside handlers/middlewares should use c.RequestCtx() too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureError

func CaptureError(c fiber.Ctx, err error)

CaptureError records err on the active APM transaction. Use it from handlers that map errors inline so the error still appears in Kibana.

func Labels

func Labels(cfg LabelsConfig) fiber.Handler

Labels returns a Fiber v3 middleware that publishes transaction labels based on cfg. Must run AFTER Middleware().

func Middleware

func Middleware(opts ...Option) fiber.Handler

Middleware returns a Fiber v3 handler that wraps each request in an APM transaction. Register it FIRST so subsequent middlewares observe the transaction on c.RequestCtx().

func SetLabel

func SetLabel(c fiber.Ctx, key, value string)

SetLabel publishes a single label on the active transaction. Useful for identifiers that only materialize after the handler ran.

func TxContextExtractor added in v0.7.0

func TxContextExtractor() txctxv3.ContextExtractor

TxContextExtractor returns a ContextExtractor for txctxv3.Middleware that inherits the Elastic APM transaction from the Fiber v3 request context. Supply it as the third argument to txctxv3.Middleware whenever apmfiberv3.Middleware is also in the chain.

Types

type LabelExtractor

type LabelExtractor func(c fiber.Ctx) map[string]string

LabelExtractor — see the apmfiber package for semantics. Returns label key/value pairs to attach to the transaction.

type LabelsConfig

type LabelsConfig struct {
	Headers       map[string]string
	BodyTarget    func() any
	BodyExtractor func(decoded any) map[string]string
	Extra         LabelExtractor
}

LabelsConfig mirrors apmfiber.LabelsConfig for Fiber v3.

type Option

type Option func(*config)

Option mutates middleware configuration. Mirrors the apmfiber v2 API.

func WithPanicPropagation

func WithPanicPropagation() Option

WithPanicPropagation makes the middleware re-panic after capturing the panic as an APM error (default is to swallow and respond 500).

func WithRequestIgnorer

func WithRequestIgnorer(fn apmfasthttp.RequestIgnorerFunc) Option

WithRequestIgnorer overrides the request-ignorer function used to skip tracing for matching requests (e.g. health checks).

func WithTracer

func WithTracer(t *apm.Tracer) Option

WithTracer overrides the tracer (default apm.DefaultTracer()).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL