From 213051c20f09fc91bf64c6828f9bf71f3f05fb48 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Fri, 2 Aug 2024 01:08:55 +0530 Subject: [PATCH] feat: add sentry reporting --- cmd/server/main.go | 13 +++++++++---- internal/nostr/nostr.go | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index a91aba6..408a7cb 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -10,6 +10,7 @@ import ( echologrus "github.com/davrux/echo-logrus/v4" "github.com/getsentry/sentry-go" + sentryecho "github.com/getsentry/sentry-go/echo" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" ddEcho "gopkg.in/DataDog/dd-trace-go.v1/contrib/labstack/echo.v4" @@ -24,16 +25,21 @@ func main() { logrus.Fatalf("Failed to initialize service: %v", err) } + e := echo.New() + e.HideBanner = true + echologrus.Logger = svc.Logger + e.Use(echologrus.Middleware()) + if svc.Cfg.SentryDSN != "" { if err = sentry.Init(sentry.ClientOptions{ Dsn: svc.Cfg.SentryDSN, }); err != nil { - logrus.Error(err) + svc.Logger.WithError(err).Error("Failed to init Sentry") } + defer sentry.Flush(2 * time.Second) + e.Use(sentryecho.New(sentryecho.Options{})) } - echologrus.Logger = svc.Logger - e := echo.New() if svc.Cfg.DatadogAgentUrl != "" { tracer.Start(tracer.WithService("http-nostr")) defer tracer.Stop() @@ -47,7 +53,6 @@ func main() { e.POST("/publish", svc.PublishHandler) e.POST("/subscriptions", svc.SubscriptionHandler) e.DELETE("/subscriptions/:id", svc.StopSubscriptionHandler) - e.Use(echologrus.Middleware()) //start Echo server go func() { diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index b70492e..ad2f981 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -792,10 +792,10 @@ func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscr "client_pubkey": clientPubkey, "relay_url": subscription.RelayUrl, }).Info("Received response event") - if (subscription.RequestEvent != nil) { - subscription.RequestEvent.ResponseReceivedAt = time.Now() - svc.db.Save(&subscription.RequestEvent) - } + + subscription.RequestEvent.ResponseReceivedAt = time.Now() + svc.db.Save(&subscription.RequestEvent) + responseEvent := ResponseEvent{ NostrId: event.ID, Content: event.Content,