From 578a12529cec1934376f727b262fcd2403bb9597 Mon Sep 17 00:00:00 2001 From: Jakub Date: Wed, 23 Nov 2022 13:13:25 +0100 Subject: [PATCH] GODT-2137: set sentry sync transport. --- go.mod | 4 ++-- go.sum | 4 ++++ internal/sentry/reporter.go | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 0cb1de2a..7cf1cd94 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead github.com/emersion/go-smtp v0.15.1-0.20221021114529-49b17434419d github.com/fatih/color v1.13.0 - github.com/getsentry/sentry-go v0.13.0 + github.com/getsentry/sentry-go v0.15.0 github.com/go-resty/resty/v2 v2.7.0 github.com/goccy/go-json v0.9.11 github.com/godbus/dbus v4.1.0+incompatible @@ -79,7 +79,7 @@ require ( github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect - github.com/go-playground/validator/v10 v10.11.0 // indirect + github.com/go-playground/validator/v10 v10.11.1 // indirect github.com/gofrs/uuid v4.3.0+incompatible // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index f1c9c79d..1d03151d 100644 --- a/go.sum +++ b/go.sum @@ -142,6 +142,8 @@ github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:r github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/getsentry/sentry-go v0.13.0 h1:20dgTiUSfxRB/EhMPtxcL9ZEbM1ZdR+W/7f7NWD+xWo= github.com/getsentry/sentry-go v0.13.0/go.mod h1:EOsfu5ZdvKPfeHYV6pTVQnsjfp30+XA7//UooKNumH0= +github.com/getsentry/sentry-go v0.15.0 h1:CP9bmA7pralrVUedYZsmIHWpq/pBtXTSew7xvVpfLaA= +github.com/getsentry/sentry-go v0.15.0/go.mod h1:RZPJKSw+adu8PBNygiri/A98FqVr2HtRckJk9XVxJ9I= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -162,6 +164,8 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw= github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= +github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= diff --git a/internal/sentry/reporter.go b/internal/sentry/reporter.go index 61533576..b4a23c5e 100644 --- a/internal/sentry/reporter.go +++ b/internal/sentry/reporter.go @@ -26,6 +26,7 @@ import ( "time" "github.com/ProtonMail/proton-bridge/v3/internal/constants" + "github.com/ProtonMail/proton-bridge/v3/pkg/restarter" "github.com/getsentry/sentry-go" "github.com/sirupsen/logrus" ) @@ -33,10 +34,14 @@ import ( var skippedFunctions = []string{} //nolint:gochecknoglobals func init() { //nolint:gochecknoinits + sentrySyncTransport := sentry.NewHTTPSyncTransport() + sentrySyncTransport.Timeout = time.Second * 3 + if err := sentry.Init(sentry.ClientOptions{ Dsn: constants.DSNSentry, Release: constants.Revision, BeforeSend: EnhanceSentryEvent, + Transport: sentrySyncTransport, }); err != nil { logrus.WithError(err).Error("Failed to initialize sentry options") } @@ -75,7 +80,10 @@ func NewReporter(appName, appVersion string, identifier Identifier) *Reporter { func (r *Reporter) ReportException(i interface{}) error { SkipDuringUnwind() - return r.ReportExceptionWithContext(i, make(map[string]interface{})) + return r.ReportExceptionWithContext(i, map[string]interface{}{ + "build": constants.BuildTime, + "crash": os.Getenv(restarter.BridgeCrashCount), + }) } func (r *Reporter) ReportMessage(msg string) error { @@ -128,7 +136,11 @@ func (r *Reporter) scopedReport(context map[string]interface{}, doReport func()) sentry.WithScope(func(scope *sentry.Scope) { SkipDuringUnwind() scope.SetTags(tags) - scope.SetContexts(context) + if len(context) != 0 { + scope.SetContexts( + map[string]map[string]interface{}{"bridge": context}, + ) + } doReport() })