github.com/lulzWill/go-agent@v2.1.2+incompatible/examples/_logrus/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "net/http" 7 "os" 8 9 newrelic "github.com/lulzWill/go-agent" 10 "github.com/lulzWill/go-agent/_integrations/nrlogrus" 11 "github.com/sirupsen/logrus" 12 ) 13 14 func mustGetEnv(key string) string { 15 if val := os.Getenv(key); "" != val { 16 return val 17 } 18 panic(fmt.Sprintf("environment variable %s unset", key)) 19 } 20 21 func main() { 22 cfg := newrelic.NewConfig("Logrus App", mustGetEnv("NEW_RELIC_LICENSE_KEY")) 23 logrus.SetLevel(logrus.DebugLevel) 24 cfg.Logger = nrlogrus.StandardLogger() 25 26 app, err := newrelic.NewApplication(cfg) 27 if nil != err { 28 fmt.Println(err) 29 os.Exit(1) 30 } 31 32 http.HandleFunc(newrelic.WrapHandleFunc(app, "/", func(w http.ResponseWriter, r *http.Request) { 33 io.WriteString(w, "hello world") 34 })) 35 36 http.ListenAndServe(":8000", nil) 37 }