nrfiber

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigNoticeErrorEnabled

func ConfigNoticeErrorEnabled(enabled bool) *config

func ConfigStatusCodeIgnored added in v0.2.0

func ConfigStatusCodeIgnored(statusCode []int) *config

func FromContext

func FromContext(c *fiber.Ctx) *newrelic.Transaction

FromContext returns the Transaction from the context if present, and nil otherwise.

func Middleware

func Middleware(app *newrelic.Application, configs ...*config) fiber.Handler

Middleware creates Fiber middleware that instruments requests.

app := fiber.New()
// Add the nrfiber middleware before other middlewares or routes:
app.Use(nrfiber.Middleware(app))

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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