Add support for crash reporting via sentry and change the send_crash_reports key
This commit is contained in:
parent
b8dff783e1
commit
d88764aa34
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
// commands
|
||||
"github.com/apex/log"
|
||||
"github.com/getsentry/raven-go"
|
||||
|
||||
_ "github.com/ooni/probe-cli/internal/cli/geoip"
|
||||
_ "github.com/ooni/probe-cli/internal/cli/info"
|
||||
|
@ -16,14 +15,15 @@ import (
|
|||
_ "github.com/ooni/probe-cli/internal/cli/version"
|
||||
|
||||
"github.com/ooni/probe-cli/internal/cli/app"
|
||||
"github.com/ooni/probe-cli/internal/crashreport"
|
||||
)
|
||||
|
||||
func main() {
|
||||
raven.SetDSN("https://cb4510e090f64382ac371040c19b2258:8448daeebfa643c289ef398f8645980b@sentry.io/1234954")
|
||||
|
||||
err := app.Run()
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
log.WithError(err).Fatal("main exit")
|
||||
crashreport.CapturePanicAndWait(func() {
|
||||
err := app.Run()
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
log.WithError(err).Fatal("main exit")
|
||||
}, nil)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/internal/crashreport"
|
||||
"github.com/ooni/probe-cli/utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -39,6 +41,10 @@ func ParseConfig(b []byte) (*Config, error) {
|
|||
if err := c.Validate(); err != nil {
|
||||
return nil, errors.Wrap(err, "validating")
|
||||
}
|
||||
if c.Advanced.SendCrashReports == false {
|
||||
log.Info("Disabling crash reporting.")
|
||||
crashreport.Disabled = true
|
||||
}
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
|
|
@ -110,17 +110,17 @@ type Notifications struct {
|
|||
|
||||
// Sharing settings
|
||||
type Sharing struct {
|
||||
IncludeIP bool `json:"include_ip"`
|
||||
IncludeASN bool `json:"include_asn"`
|
||||
IncludeGPS bool `json:"include_gps"`
|
||||
UploadResults bool `json:"upload_results"`
|
||||
SendCrashReports bool `json:"send_crash_reports"`
|
||||
IncludeIP bool `json:"include_ip"`
|
||||
IncludeASN bool `json:"include_asn"`
|
||||
IncludeGPS bool `json:"include_gps"`
|
||||
UploadResults bool `json:"upload_results"`
|
||||
}
|
||||
|
||||
// Advanced settings
|
||||
type Advanced struct {
|
||||
IncludeCountry bool `json:"include_country"`
|
||||
UseDomainFronting bool `json:"use_domain_fronting"`
|
||||
SendCrashReports bool `json:"send_crash_reports"`
|
||||
}
|
||||
|
||||
// AutomatedTesting settings
|
||||
|
|
6
config/testdata/valid-config.json
vendored
6
config/testdata/valid-config.json
vendored
|
@ -7,8 +7,7 @@
|
|||
"include_ip": false,
|
||||
"include_asn": true,
|
||||
"include_gps": true,
|
||||
"upload_results": true,
|
||||
"send_crash_reports": true
|
||||
"upload_results": true
|
||||
},
|
||||
"notifications": {
|
||||
"enabled": true,
|
||||
|
@ -58,6 +57,7 @@
|
|||
},
|
||||
"advanced": {
|
||||
"include_country": true,
|
||||
"use_domain_fronting": false
|
||||
"use_domain_fronting": false,
|
||||
"send_crash_reports": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
"include_asn": true,
|
||||
"include_gps": true,
|
||||
"upload_results": true,
|
||||
"send_crash_reports": true
|
||||
},
|
||||
"notifications": {
|
||||
"enabled": true,
|
||||
|
@ -58,6 +57,7 @@
|
|||
},
|
||||
"advanced": {
|
||||
"include_country": true,
|
||||
"use_domain_fronting": false
|
||||
"use_domain_fronting": false,
|
||||
"send_crash_reports": true
|
||||
},
|
||||
}
|
||||
|
|
47
internal/crashreport/crashreport.go
Normal file
47
internal/crashreport/crashreport.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package crashreport
|
||||
|
||||
import (
|
||||
"github.com/getsentry/raven-go"
|
||||
)
|
||||
|
||||
// Disabled flag is used to globally disable crash reporting and make all the
|
||||
// crash reporting logic a no-op.
|
||||
var Disabled = false
|
||||
|
||||
// CapturePanic is a wrapper around raven.CapturePanic that becomes a noop if
|
||||
// `Disabled` is set to true.
|
||||
func CapturePanic(f func(), tags map[string]string) (interface{}, string) {
|
||||
if Disabled == true {
|
||||
return nil, ""
|
||||
}
|
||||
return raven.CapturePanic(f, tags)
|
||||
}
|
||||
|
||||
// CapturePanicAndWait is a wrapper around raven.CapturePanicAndWait that becomes a noop if
|
||||
// `Disabled` is set to true.
|
||||
func CapturePanicAndWait(f func(), tags map[string]string) (interface{}, string) {
|
||||
if Disabled == true {
|
||||
return nil, ""
|
||||
}
|
||||
return raven.CapturePanicAndWait(f, tags)
|
||||
}
|
||||
|
||||
// CaptureError is a wrapper around raven.CaptureError
|
||||
func CaptureError(err error, tags map[string]string) string {
|
||||
if Disabled == true {
|
||||
return ""
|
||||
}
|
||||
return raven.CaptureError(err, tags)
|
||||
}
|
||||
|
||||
// CaptureErrorAndWait is a wrapper around raven.CaptureErrorAndWait
|
||||
func CaptureErrorAndWait(err error, tags map[string]string) string {
|
||||
if Disabled == true {
|
||||
return ""
|
||||
}
|
||||
return raven.CaptureErrorAndWait(err, tags)
|
||||
}
|
||||
|
||||
func init() {
|
||||
raven.SetDSN("https://cb4510e090f64382ac371040c19b2258:8448daeebfa643c289ef398f8645980b@sentry.io/1234954")
|
||||
}
|
|
@ -127,10 +127,10 @@ func Onboarding(config *config.Config) error {
|
|||
config.Lock()
|
||||
config.InformedConsent = true
|
||||
config.Advanced.IncludeCountry = settings.IncludeCountry
|
||||
config.Advanced.SendCrashReports = settings.SendCrashReports
|
||||
config.Sharing.IncludeIP = settings.IncludeIP
|
||||
config.Sharing.IncludeASN = settings.IncludeNetwork
|
||||
config.Sharing.UploadResults = settings.UploadResults
|
||||
config.Sharing.SendCrashReports = settings.SendCrashReports
|
||||
config.Unlock()
|
||||
|
||||
if err := config.Write(); err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user