Skip to main content
Version: Next

New Relic

Release Discord Test

New Relic support for Fiber.

Compatible with Fiber v3.

Go version support

We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.

Install

go get -u github.com/gofiber/fiber/v3
go get -u github.com/gofiber/contrib/v3/newrelic

Signature

newrelic.New(config newrelic.Config) fiber.Handler

Config

PropertyTypeDescriptionDefault
LicensestringRequired - New Relic License Key""
AppNamestringNew Relic Application Namefiber-api
EnabledboolEnable/Disable New Relicfalse
TransportTypestringCan be HTTP or HTTPS (Deprecated)"HTTP"
ApplicationApplicationExisting New Relic Appnil
ErrorStatusCodeHandlerfunc(c fiber.Ctx, err error) intIf you want to change newrelic status code, you can use it.DefaultErrorStatusCodeHandler
Nextfunc(c fiber.Ctx) boolNext defines a function to skip this middleware when returned true.nil

Usage

package main

import (
"github.com/gofiber/fiber/v3"
middleware "github.com/gofiber/contrib/v3/newrelic"
)

func main() {
app := fiber.New()

app.Get("/", func(ctx fiber.Ctx) error {
return ctx.SendStatus(200)
})

cfg := middleware.Config{
License: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
AppName: "MyCustomApi",
Enabled: true,
}

app.Use(middleware.New(cfg))

app.Listen(":8080")
}

Usage with existing New Relic application

package main

import (
"github.com/gofiber/fiber/v3"
middleware "github.com/gofiber/contrib/v3/newrelic"
nr "github.com/newrelic/go-agent/v3/newrelic"
)

func main() {
nrApp, err := nr.NewApplication(
nr.ConfigAppName("MyCustomApi"),
nr.ConfigLicense("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
nr.ConfigEnabled(true),
)

app := fiber.New()

app.Get("/", func(ctx fiber.Ctx) error {
return ctx.SendStatus(200)
})

app.Get("/foo", func(ctx fiber.Ctx) error {
txn := middleware.FromContext(ctx)
segment := txn.StartSegment("foo segment")
defer segment.End()

// do foo

return nil
})

cfg := middleware.Config{
Application: nrApp,
}

app.Use(middleware.New(cfg))

app.Listen(":8080")
}