Last active
September 15, 2016 16:29
-
-
Save ianomad/4bb66617316836131e2f62e3d0abfdbd to your computer and use it in GitHub Desktop.
Sample negroni and newrelic go-agent integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.