Skip to content

Commit 3164dc3

Browse files
author
Mike Heffner
authored
Merge pull request #105 from netlify/chore/bugsnag-updates
Bugsnag updates
2 parents 5300ae7 + 98c1031 commit 3164dc3

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require (
44
github.com/BurntSushi/toml v0.3.1
55
github.com/bitly/go-simplejson v0.5.0 // indirect
66
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
7-
github.com/bugsnag/bugsnag-go v1.5.1
7+
github.com/bugsnag/bugsnag-go v1.5.3
88
github.com/bugsnag/panicwrap v1.2.0 // indirect
99
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
1010
github.com/go-chi/chi v4.0.2+incompatible

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
1111
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
1212
github.com/bugsnag/bugsnag-go v1.5.1 h1:NnfkWPiRGJlUg6s5mRlsbudWcW/B/eGFSad98JxitaU=
1313
github.com/bugsnag/bugsnag-go v1.5.1/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
14+
github.com/bugsnag/bugsnag-go v1.5.3 h1:yeRUT3mUE13jL1tGwvoQsKdVbAsQx9AJ+fqahKveP04=
15+
github.com/bugsnag/bugsnag-go v1.5.3/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
1416
github.com/bugsnag/panicwrap v1.2.0 h1:OzrKrRvXis8qEvOkfcxNcYbOd2O7xXS2nnKMEMABFQA=
1517
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
1618
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=

nconf/args.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ type RootArgs struct {
1414
}
1515

1616
func (args *RootArgs) Setup(config interface{}, version string) (logrus.FieldLogger, error) {
17-
// first load the logger
18-
logConfig := &struct {
19-
Log *LoggingConfig
17+
// first load the logger and BugSnag config
18+
rootConfig := &struct {
19+
Log *LoggingConfig
20+
BugSnag *BugSnagConfig
2021
}{}
21-
if err := LoadFromEnv(args.Prefix, args.EnvFile, logConfig); err != nil {
22+
if err := LoadFromEnv(args.Prefix, args.EnvFile, rootConfig); err != nil {
2223
return nil, errors.Wrap(err, "Failed to load the logging configuration")
2324
}
2425

25-
log, err := ConfigureLogging(logConfig.Log)
26+
log, err := ConfigureLogging(rootConfig.Log)
2627
if err != nil {
2728
return nil, errors.Wrap(err, "Failed to create the logger")
2829
}
@@ -31,6 +32,10 @@ func (args *RootArgs) Setup(config interface{}, version string) (logrus.FieldLog
3132
}
3233
log = log.WithField("version", version)
3334

35+
if err := SetupBugSnag(rootConfig.BugSnag, version); err != nil {
36+
return nil, errors.Wrap(err, "Failed to configure bugsnag")
37+
}
38+
3439
if config != nil {
3540
// second load the config for this project
3641
if err := LoadFromEnv(args.Prefix, args.EnvFile, config); err != nil {

nconf/bugsnag.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@ import (
99
type BugSnagConfig struct {
1010
Environment string
1111
APIKey string `envconfig:"api_key"`
12+
LogHook bool `envconfig:"log_hook"`
1213
}
1314

14-
func AddBugSnagHook(config *BugSnagConfig) error {
15+
func SetupBugSnag(config *BugSnagConfig, version string) error {
1516
if config == nil || config.APIKey == "" {
1617
return nil
1718
}
1819

1920
bugsnag.Configure(bugsnag.Configuration{
2021
APIKey: config.APIKey,
2122
ReleaseStage: config.Environment,
23+
AppVersion: version,
2224
PanicHandler: func() {}, // this is to disable panic handling. The lib was forking and restarting the process (causing races)
2325
})
24-
hook, err := logrus_bugsnag.NewBugsnagHook()
25-
if err != nil {
26-
return err
26+
27+
if config.LogHook {
28+
hook, err := logrus_bugsnag.NewBugsnagHook()
29+
if err != nil {
30+
return err
31+
}
32+
logrus.AddHook(hook)
33+
logrus.Debug("Added bugsnag log hook")
2734
}
28-
logrus.AddHook(hook)
29-
logrus.Debug("Added bugsnag hook")
35+
3036
return nil
3137
}

nconf/logging.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"os"
55
"time"
66

7-
"github.com/pkg/errors"
87
"github.com/sirupsen/logrus"
98
)
109

@@ -16,8 +15,6 @@ type LoggingConfig struct {
1615
TSFormat string `mapstructure:"ts_format" json:"ts_format"`
1716
Fields map[string]interface{} `mapstructure:"fields" json:"fields"`
1817
UseNewLogger bool `mapstructure:"use_new_logger",split_words:"true"`
19-
20-
BugSnag *BugSnagConfig
2118
}
2219

2320
func ConfigureLogging(config *LoggingConfig) (*logrus.Entry, error) {
@@ -55,10 +52,6 @@ func ConfigureLogging(config *LoggingConfig) (*logrus.Entry, error) {
5552
logger.Debug("Set log level to: " + logger.GetLevel().String())
5653
}
5754

58-
if err := AddBugSnagHook(config.BugSnag); err != nil {
59-
return nil, errors.Wrap(err, "Failed to configure bugsnag")
60-
}
61-
6255
f := logrus.Fields{}
6356
for k, v := range config.Fields {
6457
f[k] = v

0 commit comments

Comments
 (0)