Skip to content

Gin middleware for tracking NewRelic Web Transactions

License

Notifications You must be signed in to change notification settings

takt-corp/gin-newrelic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NewRelic Middleware for Gin

Gin middleware for tracking NewRelic web requests.

    r := gin.New()

    appName := viper.GetString("NEW_RELIC_APP_NAME")
	licenseKey := viper.GetString("NEW_RELIC_LICENSE_KEY")

	app, err := newrelic.NewApplication(
		newrelic.ConfigAppName(appName),
		newrelic.ConfigLicense(licenseKey),
		newrelic.ConfigDistributedTracerEnabled(true),
		func(cfg *newrelic.Config) {
			cfg.ErrorCollector.RecordPanics = true
		},
	) 

    r.Use(ginnewrelic.NewRelicMiddleware(app))

    r.GET("/", func(c *gin.Context) {
        txn := newrelic.FromContext(c.Request.Context())

        // code...
    })