github.com/vseinstrumentiru/lego@v1.0.2/internal/lego/monitor/exporter/newrelic.go (about) 1 package exporter 2 3 import ( 4 "emperror.dev/emperror" 5 "github.com/gorilla/mux" 6 "github.com/newrelic/go-agent/v3/integrations/nrgorilla" 7 "github.com/newrelic/go-agent/v3/newrelic" 8 "github.com/vseinstrumentiru/lego/internal/lego" 9 ) 10 11 type nrLogErr struct { 12 log lego.LogErr 13 } 14 15 func (l nrLogErr) Error(msg string, context map[string]interface{}) { 16 l.log.Error(msg, context) 17 } 18 19 func (l nrLogErr) Warn(msg string, context map[string]interface{}) { 20 l.log.Warn(msg, context) 21 } 22 23 func (l nrLogErr) Info(msg string, context map[string]interface{}) { 24 l.log.Info(msg, context) 25 } 26 27 func (l nrLogErr) Debug(msg string, context map[string]interface{}) { 28 l.log.Debug(msg, context) 29 } 30 31 func (nrLogErr) DebugEnabled() bool { 32 return false 33 } 34 35 func NewRelicMiddleware(appName, key string, logErr lego.LogErr) mux.MiddlewareFunc { 36 app, err := newrelic.NewApplication( 37 newrelic.ConfigAppName(appName), 38 newrelic.ConfigLicense(key), 39 newrelic.ConfigLogger(nrLogErr{logErr}), 40 ) 41 42 if err != nil { 43 emperror.Panic(err) 44 } 45 46 return nrgorilla.Middleware(app) 47 }