forked from Silverfish/proton-bridge
Launcher, app/base, sentry, update service
This commit is contained in:
@ -19,28 +19,76 @@ package sentry
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/internal/constants"
|
||||
"github.com/getsentry/sentry-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
skippedFunctions = []string{} //nolint[gochecknoglobals]
|
||||
)
|
||||
var skippedFunctions = []string{} //nolint[gochecknoglobals]
|
||||
|
||||
// ReportSentryCrash reports a sentry crash.
|
||||
func ReportSentryCrash(clientID, appVersion, userAgent string, reportErr error) error {
|
||||
func init() { // nolint[noinit]
|
||||
if err := sentry.Init(sentry.ClientOptions{
|
||||
Dsn: constants.DSNSentry,
|
||||
Release: constants.Revision,
|
||||
BeforeSend: EnhanceSentryEvent,
|
||||
}); err != nil {
|
||||
logrus.WithError(err).Error("Failed to initialize sentry options")
|
||||
}
|
||||
|
||||
sentry.ConfigureScope(func(scope *sentry.Scope) {
|
||||
scope.SetFingerprint([]string{"{{ default }}"})
|
||||
})
|
||||
}
|
||||
|
||||
type userAgentProvider interface {
|
||||
GetUserAgent() string
|
||||
}
|
||||
|
||||
type Reporter struct {
|
||||
appName string
|
||||
appVersion string
|
||||
uap userAgentProvider
|
||||
}
|
||||
|
||||
// NewReporter creates new sentry reporter with appName and appVersion to report.
|
||||
func NewReporter(appName, appVersion string) *Reporter {
|
||||
return &Reporter{
|
||||
appName: appName,
|
||||
appVersion: appVersion,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reporter) SetUserAgentProvider(uap userAgentProvider) {
|
||||
r.uap = uap
|
||||
}
|
||||
|
||||
// Report reports a sentry crash with stacktrace from all goroutines.
|
||||
func (r *Reporter) Report(i interface{}) (err error) {
|
||||
SkipDuringUnwind()
|
||||
if reportErr == nil {
|
||||
|
||||
if os.Getenv("PROTONMAIL_ENV") == "dev" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// In case clientManager is not yet created we can get at least OS string.
|
||||
var userAgent string
|
||||
if r.uap != nil {
|
||||
userAgent = r.uap.GetUserAgent()
|
||||
} else {
|
||||
userAgent = runtime.GOOS
|
||||
}
|
||||
|
||||
reportErr := fmt.Errorf("recover: %v", i)
|
||||
|
||||
tags := map[string]string{
|
||||
"OS": runtime.GOOS,
|
||||
"Client": clientID,
|
||||
"Version": appVersion,
|
||||
"Client": r.appName,
|
||||
"Version": r.appVersion,
|
||||
"UserAgent": userAgent,
|
||||
"UserID": "",
|
||||
}
|
||||
@ -49,18 +97,17 @@ func ReportSentryCrash(clientID, appVersion, userAgent string, reportErr error)
|
||||
sentry.WithScope(func(scope *sentry.Scope) {
|
||||
SkipDuringUnwind()
|
||||
scope.SetTags(tags)
|
||||
eventID := sentry.CaptureException(reportErr)
|
||||
if eventID != nil {
|
||||
if eventID := sentry.CaptureException(reportErr); eventID != nil {
|
||||
reportID = string(*eventID)
|
||||
}
|
||||
})
|
||||
|
||||
if !sentry.Flush(time.Second * 10) {
|
||||
log.WithField("error", reportErr).Error("Failed to report sentry error")
|
||||
return errors.New("failed to report sentry error")
|
||||
}
|
||||
|
||||
log.WithField("error", reportErr).WithField("id", reportID).Warn("Sentry error reported")
|
||||
logrus.WithField("error", reportErr).WithField("id", reportID).Warn("Sentry error reported")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user