Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.68 KB

README.md

File metadata and controls

57 lines (42 loc) · 1.68 KB

negroni-newrelic-go-agent

New Relic Go Agent middleware for negroni

New Relic has recently released a Go Agent in their APM module. Its currently in beta and in order to get started you can request for a beta token by filling the beta agreement form.

If you have microservice architecture using negroni and are looking for a middleware to attach new relic go agent to your existing stack of middlewares, then you can use negroni-newrelic-go-agent to achieve the same.

Usage

package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/codegangsta/negroni"
	newrelic "github.com/yadvendar/negroni-newrelic-go-agent"
)

func main() {
	r := http.NewServeMux()
	r.HandleFunc(`/`, func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, "success!\n")
	})

	n := negroni.New()
	config := newrelic.NewConfig("APP_SERVER_NAME", "NEWRELIC_LICENSE_KEY")
	config.BetaToken = "BETA_TOKEN" // this is valid only till go-agent is in beta
	config.Enabled = true
	newRelicMiddleware, err := newrelic.New(config)
	if err != nil {
		fmt.Println("Unable to initialize newrelic. Error=" + err.Error())
		os.Exit(0)
	}
	n.Use(newRelicMiddleware)
	n.UseHandler(r)

	n.Run(":3000")
}

See a running example.

Credits

New Relic Go Agent

License

See LICENSE.txt