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.
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.
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() r.Use(nrgorilla.Middleware(app)) // All handlers and custom middlewares will be instrumented. The // transaction will be available in the Request's context. r.Use(MyCustomMiddleware) r.Handle("/", makeHandler("index")) http.ListenAndServe(":8000", r)
r := mux.NewRouter() r.Use(nrgorilla.Middleware(app)) // 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"))