Skip to content

Commit

Permalink
Configure airbrake to notify on panic (#163)
Browse files Browse the repository at this point in the history
Airbrake allows to send data when a panic is detected on server startup
  • Loading branch information
agbpatro authored Apr 18, 2024
1 parent 03528fd commit d30d947
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

_ "go.uber.org/automaxprocs"

"github.com/airbrake/gobrake/v5"
"github.com/teslamotors/fleet-telemetry/config"
logrus "github.com/teslamotors/fleet-telemetry/logger"
"github.com/teslamotors/fleet-telemetry/server/airbrake"
Expand Down Expand Up @@ -34,17 +35,21 @@ func main() {
}()
}

panic(startServer(config, logger))
airbrakeNotifier, _, err := config.CreateAirbrakeNotifier(logger)
if err != nil {
panic(err)
}
if airbrakeNotifier != nil {
defer airbrakeNotifier.NotifyOnPanic()
defer airbrakeNotifier.Close()
}
panic(startServer(config, airbrakeNotifier, logger))
}

func startServer(config *config.Config, logger *logrus.Logger) (err error) {
func startServer(config *config.Config, airbrakeNotifier *gobrake.Notifier, logger *logrus.Logger) (err error) {
logger.ActivityLog("starting_server", nil)
registry := streaming.NewSocketRegistry()

airbrakeNotifier, _, err := config.CreateAirbrakeNotifier(logger)
if err != nil {
return err
}
airbrakeHandler := airbrake.NewAirbrakeHandler(airbrakeNotifier)

if config.StatusPort > 0 {
Expand Down

0 comments on commit d30d947

Please sign in to comment.