github.com/tuingking/flamingo@v0.0.0-20220403134817-2796ae0e84ca/infra/newrelic/newrelic.go (about) 1 package newrelic 2 3 import ( 4 "os" 5 "time" 6 7 "github.com/newrelic/go-agent/v3/integrations/nrlogrus" 8 nr "github.com/newrelic/go-agent/v3/newrelic" 9 "github.com/sirupsen/logrus" 10 ) 11 12 type NewRelic interface { 13 StartTransaction(name string) *nr.Transaction 14 RecordCustomEvent(eventType string, params map[string]interface{}) 15 RecordCustomMetric(name string, value float64) 16 WaitForConnection(timeout time.Duration) error 17 Shutdown(timeout time.Duration) 18 } 19 20 type Config struct { 21 AppName string 22 LicenseKey string 23 Output *os.File 24 } 25 26 func Init(cfg Config) NewRelic { 27 app, err := nr.NewApplication( 28 nr.ConfigAppName(cfg.AppName), 29 nr.ConfigLicense(cfg.LicenseKey), 30 nr.ConfigDebugLogger(cfg.Output), 31 func(config *nr.Config) { 32 logrus.SetLevel(logrus.DebugLevel) 33 config.Logger = nrlogrus.StandardLogger() 34 }, 35 ) 36 if err != nil { 37 logrus.Panicf("unable to create New Relic Application, err= %s", err) 38 } 39 40 return app 41 }