This is a creation in Article, where the information may have evolved or changed.
The newrelic is a very useful monitoring platform. Request analysis, data transactions, machine health, error alarm and other functions, and the strength of the segmentation is fine enough, in addition to expensive, others are very good. In fact, good service is worth the price.
Newrelic to the major language framework support is very perfect, the support of Golang is not bad. However, the official website provides examples only for net/http. For the gin currently in use, still need a hack. Fortunately gin is elegant enough. Here's a look at registering Newrelic with gin development.
Install Newrelic's official Golang package first:
go get -u -v github.com/newrelic/go-agent
Then write a middleware, for the request before the hook, that is, register to Newrelic, the code is relatively simple, as follows:
Package Mainimport ("Net/http" "Github.com/gin-gonic/gin" "Github.com/newrelic/go-agent") func Newreli Cmiddleware (AppName string, key string) gin. Handlerfunc {if appName = = "" | | Key = = "" {return func (c *gin. Context) {}} config: = Newrelic. Newconfig (AppName, key) app, err: = Newrelic. Newapplication (config) if err! = Nil {panic (err)} return func (C *gin. Context) {txn: = App. StartTransaction (C.request.url.path, C.writer, c.request) defer txn. End () C.next ()}}func main () {router: = gin. Default () router. Use (Newrelicmiddleware ("App-name", "App-key")) router. GET ("/", Func (c *gin. Context) {c.string (http. Statusok, "It Works")}) router. Run ()}