Skip to content

Commit

Permalink
fix: Guard against a nil client when setting the SDK identifer (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Sep 13, 2023
1 parent 04ea85a commit 1d05fa5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion echo/sentryecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion fasthttp/sentryfasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion gin/sentrygin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion http/sentryhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 3 additions & 1 deletion iris/sentryiris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion martini/sentrymartini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion negroni/sentrynegroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1d05fa5

Please sign in to comment.