Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

[breaking] Swtich to Sentry exception logging #37

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ secrets:
`-y`, `--yes` assume "yes" to all prompts and run non-interactively

## Monitoring
Configure [Airbrake](https://airbrake.io/) for rotator by setting the `ENV`, `AIRBRAKE_PROJECT_ID`, and `AIRBRAKE_PROJECT_KEY` environment variables.
Configure [Sentry](https://getsentry.com/) for rotator by setting the `ENV`, `SENTRY_DSN` environment variables.

## Sources
All sources must have the following fields in addition to any source-specific fields:
Expand Down
56 changes: 20 additions & 36 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package cmd

import (
"os"
"strconv"
"time"

"github.com/airbrake/gobrake"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -18,54 +18,38 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
airbrake, err := setUpAirbrake()
sentryEnabled, err := setUpSentry()
if err != nil {
logrus.Warn(errors.Wrap(err, "unable to set up Airbrake notifier"))
} else {
defer func(airbrake *gobrake.Notifier) {
if err := airbrake.Close(); err != nil {
logrus.Error(errors.Wrap(err, "unable to close Airbrake notifier"))
}
}(airbrake)
defer airbrake.NotifyOnPanic()
logrus.Warn(errors.Wrap(err, "unable to set up Sentry notifier"))
} else if sentryEnabled {
defer sentry.Flush(time.Second * 5)
defer sentry.Recover()
}

if err := rootCmd.Execute(); err != nil {
if airbrake != nil {
airbrake.Notify(err, nil)
airbrake.Flush()
if sentryEnabled {
sentry.CaptureException(err)
sentry.Flush(time.Second * 5)
}
logrus.Fatal(err)
}
}

// reference: https://github.com/chanzuckerberg/mergebot/blob/fa0c67c2363f5f9e5a432a116ee82a294a9e5eea/cmd/run.go
func setUpAirbrake() (*gobrake.Notifier, error) {
func setUpSentry() (bool, error) {
env := os.Getenv("ENV")
if env == "" {
return nil, errors.New("please set the ENV variable to the name of the current execution environment (dev, stage, prod, etc)")
}
airEnv := os.Getenv("AIRBRAKE_PROJECT_ID")
airbrakeProjectID, err := strconv.ParseInt(airEnv, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "unable to parse AIRBRAKE_PROJECT_ID variable to int64")
return false, errors.New("please set the ENV variable to the name of the current execution environment (dev, stage, prod, etc)")
}
sentryDsn := os.Getenv("SENTRY_DSN")

var airbrake *gobrake.Notifier
if airbrakeProjectID != 0 {
airbrakeProjectKey := os.Getenv("AIRBRAKE_PROJECT_KEY")
if airbrakeProjectKey == "" {
return nil, errors.New("If you set AIRBRAKE_PROJECT_ID, you need to also set AIRBRAKE_PROJECT_KEY")
}
airbrake = gobrake.NewNotifierWithOptions(&gobrake.NotifierOptions{
ProjectId: airbrakeProjectID,
ProjectKey: airbrakeProjectKey,
if sentryDsn != "" {
err := sentry.Init(sentry.ClientOptions{
Dsn: sentryDsn,
Environment: env,
})
airbrake.AddFilter(func(notice *gobrake.Notice) *gobrake.Notice {
notice.Context["environment"] = env
return notice
})
if err != nil {
return false, errors.Wrap(err, "sentry initialization failed")
}
}
return airbrake, nil
return true, nil
}
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ module github.com/chanzuckerberg/rotator
go 1.13

require (
github.com/airbrake/gobrake v3.7.4+incompatible
github.com/aws/aws-sdk-go v1.25.14
github.com/caio/go-tdigest v2.3.0+incompatible // indirect
github.com/chanzuckerberg/go-misc v0.0.0-20191016143922-52a18771c2dc
github.com/fatih/color v1.7.0
github.com/getsentry/sentry-go v0.3.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/uuid v1.1.1
github.com/hashicorp/go-multierror v1.0.0
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/leesper/go_rng v0.0.0-20190531154944-a612b043e353 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/pkg/errors v0.8.1
github.com/segmentio/go-prompt v1.2.1-0.20161017233205-f0d19b6901ad // build fails otherwise
github.com/shuheiktgw/go-travis v0.2.4
Expand Down
114 changes: 77 additions & 37 deletions go.sum

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions vendor/github.com/airbrake/gobrake/.travis.yml

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/github.com/airbrake/gobrake/LICENSE

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/airbrake/gobrake/Makefile

This file was deleted.

84 changes: 0 additions & 84 deletions vendor/github.com/airbrake/gobrake/README.md

This file was deleted.

74 changes: 0 additions & 74 deletions vendor/github.com/airbrake/gobrake/code_hunk.go

This file was deleted.

Loading