Skip to content

New Relic Go Agent integration package for Fiber

License

Notifications You must be signed in to change notification settings

ichizero/nrfiber

Repository files navigation

nrfiber

nrfiber is one of New Relic Go Agent integration packages. It instruments inbound requests through the Fiber framework.

Go Reference Go Report Card

🚀 Install

go get -u github.com/ichizero/nrfiber

🧐 Usage

package main

import (
	"log"
	"net/http"

	"github.com/gofiber/fiber/v2"
	"github.com/ichizero/nrfiber"
	"github.com/newrelic/go-agent/v3/newrelic"
)

func main() {
	nrApp, err := newrelic.NewApplication(
		newrelic.ConfigEnabled(true),
		newrelic.ConfigAppName("nrfiber-example"),
		newrelic.ConfigLicense("license-key"),
	)
	if err != nil {
		log.Fatal(err)
	}

	app := fiber.New()
	app.Use(nrfiber.Middleware(nrApp))

	app.Post("/echo", func(c *fiber.Ctx) error {
		return c.Status(http.StatusOK).Send(c.Request().Body())
	})

	if err := app.Listen(":8000"); err != nil {
		log.Fatal(err)
	}
}