New Relic
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
| Property | Type | Description | Default |
|---|---|---|---|
| License | string | Required - New Relic License Key | "" |
| AppName | string | New Relic Application Name | fiber-api |
| Enabled | bool | Enable/Disable New Relic | false |
string | "HTTP" | ||
| Application | Application | Existing New Relic App | nil |
| ErrorStatusCodeHandler | func(c fiber.Ctx, err error) int | If you want to change newrelic status code, you can use it. | DefaultErrorStatusCodeHandler |
| Next | func(c fiber.Ctx) bool | Next 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")
}