From f01d5f7579a718965151377a460a2e28df492b82 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 13 Sep 2023 14:18:09 +0200 Subject: [PATCH 1/2] fix: Guard against a nil client when setting the SDK identifer --- 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..7265d429f 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..f1821970e 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..841d58474 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..23d1ba778 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..c0f116abc 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..1fa7d6914 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..28457886c 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( From 158e053ed4dcb96352ee582daa69ed4cabed16c1 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 13 Sep 2023 14:21:21 +0200 Subject: [PATCH 2/2] Derp --- echo/sentryecho.go | 2 +- fasthttp/sentryfasthttp.go | 2 +- gin/sentrygin.go | 2 +- http/sentryhttp.go | 2 +- iris/sentryiris.go | 2 +- martini/sentrymartini.go | 2 +- negroni/sentrynegroni.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/echo/sentryecho.go b/echo/sentryecho.go index 7265d429f..46fe96526 100644 --- a/echo/sentryecho.go +++ b/echo/sentryecho.go @@ -53,7 +53,7 @@ func (h *handler) handle(next echo.HandlerFunc) echo.HandlerFunc { hub = sentry.CurrentHub().Clone() } - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) } diff --git a/fasthttp/sentryfasthttp.go b/fasthttp/sentryfasthttp.go index f1821970e..f6b6787af 100644 --- a/fasthttp/sentryfasthttp.go +++ b/fasthttp/sentryfasthttp.go @@ -62,7 +62,7 @@ func (h *Handler) Handle(handler fasthttp.RequestHandler) fasthttp.RequestHandle // context.Context but requires string keys. hub := sentry.CurrentHub().Clone() - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) } diff --git a/gin/sentrygin.go b/gin/sentrygin.go index 841d58474..387699109 100644 --- a/gin/sentrygin.go +++ b/gin/sentrygin.go @@ -58,7 +58,7 @@ func (h *handler) handle(c *gin.Context) { ctx = sentry.SetHubOnContext(ctx, hub) } - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) } diff --git a/http/sentryhttp.go b/http/sentryhttp.go index 23d1ba778..2fb5a9f90 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -90,7 +90,7 @@ func (h *Handler) handle(handler http.Handler) http.HandlerFunc { ctx = sentry.SetHubOnContext(ctx, hub) } - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) } diff --git a/iris/sentryiris.go b/iris/sentryiris.go index c0f116abc..c70784090 100644 --- a/iris/sentryiris.go +++ b/iris/sentryiris.go @@ -55,7 +55,7 @@ func (h *handler) handle(ctx iris.Context) { hub = sentry.CurrentHub().Clone() } - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) } diff --git a/martini/sentrymartini.go b/martini/sentrymartini.go index 1fa7d6914..425289fd0 100644 --- a/martini/sentrymartini.go +++ b/martini/sentrymartini.go @@ -50,7 +50,7 @@ func (h *handler) handle(rw http.ResponseWriter, r *http.Request, ctx martini.Co hub = sentry.CurrentHub().Clone() } - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) } diff --git a/negroni/sentrynegroni.go b/negroni/sentrynegroni.go index 28457886c..1e94fa37a 100644 --- a/negroni/sentrynegroni.go +++ b/negroni/sentrynegroni.go @@ -51,7 +51,7 @@ func (h *handler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.H hub = sentry.CurrentHub().Clone() } - if client := hub.Client(); client == nil { + if client := hub.Client(); client != nil { client.SetSDKIdentifier(sdkIdentifier) }