Skip to content

Instantly share code, notes, and snippets.

@ianomad
Last active September 15, 2016 16:29
Show Gist options
  • Save ianomad/4bb66617316836131e2f62e3d0abfdbd to your computer and use it in GitHub Desktop.
Save ianomad/4bb66617316836131e2f62e3d0abfdbd to your computer and use it in GitHub Desktop.
Sample negroni and newrelic go-agent integration
package main
import (
"fmt"
"net/http"
"github.com/newrelic/go-agent"
"github.com/urfave/negroni"
)
func main() {
config := newrelic.NewConfig("Your Application Name", "__YOUR_NEW_RELIC_LICENSE_KEY__")
app, err := newrelic.NewApplication(config)
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
})
n := negroni.Classic() // Includes some default middlewares
n.Use(negroni.HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
tx := app.StartTransaction(fmt.Sprint("%s - %s", r.Method, r.URL.Path), rw, r)
defer tx.End()
next(rw, r)
}))
n.UseHandler(mux)
http.ListenAndServe(":3000", n)
}
@mikegleasonjr
Copy link

Newrelic is warning users of this method about the explosion of the transaction names. For me, I verify if the response is OK (200) to end the transaction, otherwise I abort it to not log it. Just an info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment