go-agent: github.com/newrelic/go-agent/v3/integrations/nrgorilla Index | Examples | Files | Directories

package nrgorilla

import "github.com/newrelic/go-agent/v3/integrations/nrgorilla"

Package nrgorilla instruments https://github.com/gorilla/mux applications.

Use this package to instrument inbound requests handled by a gorilla mux.Router. Use the nrgorilla.Middleware as the first middleware registered with your router.

Complete example: https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrgorilla/example/main.go



Package Files


func InstrumentRoutes Uses

func InstrumentRoutes(r *mux.Router, app *newrelic.Application) *mux.Router

InstrumentRoutes instruments requests through the provided mux.Router. Use this after the routes have been added to the router.

Deprecated: Use the newer and more complete Middleware method instead.

func Middleware Uses

func Middleware(app *newrelic.Application) mux.MiddlewareFunc

Middleware creates a new mux.MiddlewareFunc. When used, this middleware will create a transaction for each inbound request. The transaction will be available in the Request's context throughout the call chain, including in any other middlewares that are registered after this one. For this reason, it is important for this middleware to be registered first.

Note that mux.MiddlewareFuncs are not called for the NotFoundHandler or MethodNotAllowedHandler. To instrument these handlers, use newrelic.WrapHandle (https://godoc.org/github.com/newrelic/go-agent/v3/newrelic#WrapHandle).

Note that if you are moving from the now deprecated InstrumentRoutes to this Middleware, the reported time of your transactions may increase. This is expected and nothing to worry about. This method includes in the transaction total time request time that is spent in other custom middlewares whereas InstrumentRoutes does not.


r := mux.NewRouter()

// All handlers and custom middlewares will be instrumented.  The
// transaction will be available in the Request's context.
r.Handle("/", makeHandler("index"))

http.ListenAndServe(":8000", r)


r := mux.NewRouter()

// The NotFoundHandler and MethodNotAllowedHandler must be instrumented
// separately using newrelic.WrapHandle.  The second argument to
// newrelic.WrapHandle is used as the transaction name; the string returned
// from newrelic.WrapHandle should be ignored.
_, r.NotFoundHandler = newrelic.WrapHandle(app, "NotFoundHandler", makeHandler("not found"))
_, r.MethodNotAllowedHandler = newrelic.WrapHandle(app, "MethodNotAllowedHandler", makeHandler("method not allowed"))



Package nrgorilla imports 4 packages (graph) and is imported by 4 packages. Updated 2020-07-01. Refresh now. Tools for package owners.