From 1d05fa5ef95fbee182123693db9fa4eed663e42b Mon Sep 17 00:00:00 2001 From: Michi Hoffmann Date: Wed, 13 Sep 2023 14:42:13 +0200 Subject: [PATCH] fix: Guard against a nil client when setting the SDK identifer (#715) --- echo/sentryecho.go | 4 +++- fasthttp/sentryfasthttp.go | 4 +++- gin/sentrygin.go | 4 +++- http/sentryhttp.go | 4 +++- iris/sentryiris.go | 4 +++- martini/sentrymartini.go | 4 +++- negroni/sentrynegroni.go | 4 +++- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/echo/sentryecho.go b/echo/sentryecho.go index 91ddde453..46fe96526 100644 --- a/echo/sentryecho.go +++ b/echo/sentryecho.go @@ -53,7 +53,9 @@ func (h *handler) handle(next echo.HandlerFunc) echo.HandlerFunc { hub = sentry.CurrentHub().Clone() } - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } hub.Scope().SetRequest(ctx.Request()) ctx.Set(valuesKey, hub) diff --git a/fasthttp/sentryfasthttp.go b/fasthttp/sentryfasthttp.go index 56c907ebe..f6b6787af 100644 --- a/fasthttp/sentryfasthttp.go +++ b/fasthttp/sentryfasthttp.go @@ -62,7 +62,9 @@ func (h *Handler) Handle(handler fasthttp.RequestHandler) fasthttp.RequestHandle // context.Context but requires string keys. hub := sentry.CurrentHub().Clone() - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } scope := hub.Scope() scope.SetRequest(convert(ctx)) diff --git a/gin/sentrygin.go b/gin/sentrygin.go index bfc78415f..387699109 100644 --- a/gin/sentrygin.go +++ b/gin/sentrygin.go @@ -58,7 +58,9 @@ func (h *handler) handle(c *gin.Context) { ctx = sentry.SetHubOnContext(ctx, hub) } - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } var transactionName string var transactionSource sentry.TransactionSource diff --git a/http/sentryhttp.go b/http/sentryhttp.go index 05b9432b5..2fb5a9f90 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -90,7 +90,9 @@ func (h *Handler) handle(handler http.Handler) http.HandlerFunc { ctx = sentry.SetHubOnContext(ctx, hub) } - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } options := []sentry.SpanOption{ sentry.WithOpName("http.server"), diff --git a/iris/sentryiris.go b/iris/sentryiris.go index a06e8ec9f..c70784090 100644 --- a/iris/sentryiris.go +++ b/iris/sentryiris.go @@ -55,7 +55,9 @@ func (h *handler) handle(ctx iris.Context) { hub = sentry.CurrentHub().Clone() } - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } hub.Scope().SetRequest(ctx.Request()) ctx.Values().Set(valuesKey, hub) diff --git a/martini/sentrymartini.go b/martini/sentrymartini.go index 8ff7e4f96..425289fd0 100644 --- a/martini/sentrymartini.go +++ b/martini/sentrymartini.go @@ -50,7 +50,9 @@ func (h *handler) handle(rw http.ResponseWriter, r *http.Request, ctx martini.Co hub = sentry.CurrentHub().Clone() } - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } hub.Scope().SetRequest(r) ctx.Map(hub) diff --git a/negroni/sentrynegroni.go b/negroni/sentrynegroni.go index 09a12fec2..1e94fa37a 100644 --- a/negroni/sentrynegroni.go +++ b/negroni/sentrynegroni.go @@ -51,7 +51,9 @@ func (h *handler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.H hub = sentry.CurrentHub().Clone() } - hub.Client().SetSDKIdentifier(sdkIdentifier) + if client := hub.Client(); client != nil { + client.SetSDKIdentifier(sdkIdentifier) + } hub.Scope().SetRequest(r) ctx = sentry.SetHubOnContext(