From 529a4df65a71b92f08cd0e3a4f76305774599e6a Mon Sep 17 00:00:00 2001 From: Aditya Mukerjee Date: Mon, 12 Jun 2017 15:56:34 -0400 Subject: [PATCH] Report initialization errors to Sentry from main --- cmd/veneur/main.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/veneur/main.go b/cmd/veneur/main.go index 46bb7319d..824919202 100644 --- a/cmd/veneur/main.go +++ b/cmd/veneur/main.go @@ -2,8 +2,11 @@ package main import ( "flag" + "os" + "time" "github.com/Sirupsen/logrus" + "github.com/getsentry/raven-go" "github.com/stripe/veneur" "github.com/stripe/veneur/trace" ) @@ -27,9 +30,34 @@ func main() { if err != nil { logrus.WithError(err).Fatal("Error reading config file") } + server, err := veneur.NewFromConfig(conf) if err != nil { - logrus.WithError(err).Fatal("Could not initialize server") + e := err + + logrus.WithError(e).Error("Error initializing server") + var sentry *raven.Client + if conf.SentryDsn != "" { + sentry, err = raven.New(conf.SentryDsn) + if err != nil { + logrus.WithError(err).Error("Error initializing Sentry client") + } + } + + hostname, _ := os.Hostname() + + p := raven.NewPacket(e.Error()) + if hostname != "" { + p.ServerName = hostname + } + + _, ch := sentry.Capture(p, nil) + select { + case <-ch: + case <-time.After(10 * time.Second): + } + + logrus.WithError(e).Fatal("Could not initialize server") } defer func() { veneur.ConsumePanic(server.Sentry, server.Statsd, server.Hostname, recover())