From 788bb69614634d06ea87d34d33b0b364dc39f21b Mon Sep 17 00:00:00 2001 From: directduck Date: Thu, 23 Oct 2025 10:45:35 +0300 Subject: [PATCH] Update sentry hub usage --- README.md | 2 -- handler.go | 3 ++- middleware.go | 17 ----------------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 89050f9..46fe65a 100644 --- a/README.md +++ b/README.md @@ -161,8 +161,6 @@ arithsrvClient := arithsrv.NewClient(arithsrvUrl, appkit.NewHTTPClient("arithsrv - `DebugIDFromContext(ctx context.Context) uint64` - Retrieves debug ID from context - `NewSQLGroupContext(ctx context.Context, group string) context.Context` - Creates context with SQL group for debug logging - `SQLGroupFromContext(ctx context.Context) string` - Retrieves SQL group from context -- `NewSentryHubContext(ctx context.Context, sentryHub *sentry.Hub) context.Context` - Creates context with Sentry Hub -- `SentryHubFromContext(ctx context.Context) (*sentry.Hub, bool)` - Retrieves Sentry Hub from context - `NewIPContext(ctx context.Context, ip string) context.Context` - Creates context with IP address - `IPFromContext(ctx context.Context) string` - Retrieves IP address from context - `NewUserAgentContext(ctx context.Context, ua string) context.Context` - Creates context with User-Agent diff --git a/handler.go b/handler.go index 2fe4feb..d169435 100644 --- a/handler.go +++ b/handler.go @@ -6,6 +6,7 @@ import ( "slices" "strings" + "github.com/getsentry/sentry-go" sentryecho "github.com/getsentry/sentry-go/echo" "github.com/labstack/echo/v4" ) @@ -84,7 +85,7 @@ func EchoIPContext() echo.MiddlewareFunc { func applySentryHubToContext(c echo.Context) echo.Context { if hub := sentryecho.GetHubFromContext(c); hub != nil { req := c.Request() - c.SetRequest(req.WithContext(NewSentryHubContext(req.Context(), hub))) + c.SetRequest(req.WithContext(sentry.SetHubOnContext(req.Context(), hub))) } return c } diff --git a/middleware.go b/middleware.go index b2d60b7..1c235e9 100644 --- a/middleware.go +++ b/middleware.go @@ -2,8 +2,6 @@ package appkit import ( "context" - - "github.com/getsentry/sentry-go" ) const ( @@ -15,7 +13,6 @@ const ( ctxUserAgentKey contextKey = "userAgent" ctxCountryKey contextKey = "country" ctxNotificationKey string = "JSONRPC2-Notification" - ctxSentryHubKey contextKey = "sentryHub" debugIDCtx contextKey = "debugID" sqlGroupCtx contextKey = "sqlGroup" @@ -59,20 +56,6 @@ func SQLGroupFromContext(ctx context.Context) string { return r } -// NewSentryHubContext creates new context with Sentry Hub. -func NewSentryHubContext(ctx context.Context, sentryHub *sentry.Hub) context.Context { - if sentryHub == nil { - return ctx - } - return context.WithValue(ctx, ctxSentryHubKey, sentryHub) -} - -// SentryHubFromContext returns Sentry Hub from context. -func SentryHubFromContext(ctx context.Context) (*sentry.Hub, bool) { - r, ok := ctx.Value(ctxSentryHubKey).(*sentry.Hub) - return r, ok -} - // NewIPContext creates new context with IP. func NewIPContext(ctx context.Context, ip string) context.Context { return context.WithValue(ctx, ctxIPKey, ip)