...

Source file src/github.com/gin-gonic/contrib/newrelic/newrelic.go

Documentation: github.com/gin-gonic/contrib/newrelic

     1  package newrelic
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gin-gonic/gin"
     7  	metrics "github.com/yvasiyarov/go-metrics"
     8  	"github.com/yvasiyarov/gorelic"
     9  )
    10  
    11  var agent *gorelic.Agent
    12  
    13  func NewRelic(license string, appname string, verbose bool) gin.HandlerFunc {
    14  	agent = gorelic.NewAgent()
    15  	agent.NewrelicLicense = license
    16  
    17  	agent.HTTPTimer = metrics.NewTimer()
    18  	agent.CollectHTTPStat = true
    19  	agent.Verbose = verbose
    20  
    21  	agent.NewrelicName = appname
    22  	agent.Run()
    23  
    24  	return func(c *gin.Context) {
    25  		startTime := time.Now()
    26  		c.Next()
    27  		agent.HTTPTimer.UpdateSince(startTime)
    28  	}
    29  }
    30  

View as plain text