mesuutt / nrfiber

NewRelic middleware for GoFiber

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nrfiber

Provides auto instrumentation for NewRelic and GoFiber.

Install

go get -u github.com/erkanzileli/nrfiber

Usage

Register the middleware and use created transaction to add another segments. Basic usage is below

package main

import (
	"github.com/erkanzileli/nrfiber"
	"github.com/gofiber/fiber/v2"
	"github.com/newrelic/go-agent/v3/newrelic"
	"log"
)

func main() {
	app := fiber.New()
	nr, err := newrelic.NewApplication(newrelic.ConfigEnabled(true), newrelic.ConfigAppName("demo"), newrelic.ConfigLicense("license-key"))
	if err != nil {
		log.Fatal(err)
	}

	// Add the nrfiber middleware before other middlewares or routes
	app.Use(nrfiber.Middleware(nr))

	// Use created transaction to create custom segments
	app.Get("/cart", func(ctx *fiber.Ctx) error {
		txn := nrfiber.FromContext(ctx)
		segment := txn.StartSegment("Price Calculation")
		defer segment.End()

		// calculate the price

		return nil
	})
	app.Listen(":3000")
}

Guides

Contributing

Feel free to add anything useful or fix something.

About

NewRelic middleware for GoFiber

License:Apache License 2.0


Languages

Language:Go 100.0%