From 8dfe03632f1cedb262f107f31a35f75976034541 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 9 Aug 2023 11:53:33 +0200 Subject: [PATCH] Set SDK Name According Framework being used --- client.go | 13 ++++++++++++- echo/sentryecho.go | 6 ++++++ fasthttp/sentryfasthttp.go | 6 ++++++ gin/sentrygin.go | 6 ++++++ iris/sentryiris.go | 6 ++++++ logrus/logrusentry.go | 6 ++++++ martini/sentrymartini.go | 6 ++++++ negroni/sentrynegroni.go | 6 ++++++ sentry.go | 1 + 9 files changed, 55 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 6a93fc149..5971983f1 100644 --- a/client.go +++ b/client.go @@ -17,6 +17,9 @@ import ( "github.com/getsentry/sentry-go/internal/debug" ) +// The identifier of the SDK. +var sdkIdentifier = "sentry.go" + // maxErrorDepth is the maximum number of errors reported in a chain of errors. // This protects the SDK from an arbitrarily long chain of wrapped errors. // @@ -561,6 +564,14 @@ func (client *Client) EventFromCheckIn(checkIn *CheckIn, monitorConfig *MonitorC return event } +func (client *Client) SetSDKIdentifier(identifier string) { + sdkIdentifier = identifier +} + +func (client *Client) GetSDKIdentifier() string { + return sdkIdentifier +} + // reverse reverses the slice a in place. func reverse(a []Exception) { for i := len(a)/2 - 1; i >= 0; i-- { @@ -646,7 +657,7 @@ func (client *Client) prepareEvent(event *Event, hint *EventHint, scope EventMod event.Platform = "go" event.Sdk = SdkInfo{ - Name: SDKIdentifier, + Name: client.GetSDKIdentifier(), Version: SDKVersion, Integrations: client.listIntegrations(), Packages: []SdkPackage{{ diff --git a/echo/sentryecho.go b/echo/sentryecho.go index f9e9644a8..91ddde453 100644 --- a/echo/sentryecho.go +++ b/echo/sentryecho.go @@ -9,6 +9,9 @@ import ( "github.com/labstack/echo/v4" ) +// The identifier of the Echo SDK. +const sdkIdentifier = "sentry.go.echo" + const valuesKey = "sentry" type handler struct { @@ -49,6 +52,9 @@ func (h *handler) handle(next echo.HandlerFunc) echo.HandlerFunc { if hub == nil { hub = sentry.CurrentHub().Clone() } + + hub.Client().SetSDKIdentifier(sdkIdentifier) + hub.Scope().SetRequest(ctx.Request()) ctx.Set(valuesKey, hub) defer h.recoverWithSentry(hub, ctx.Request()) diff --git a/fasthttp/sentryfasthttp.go b/fasthttp/sentryfasthttp.go index 45760071d..56c907ebe 100644 --- a/fasthttp/sentryfasthttp.go +++ b/fasthttp/sentryfasthttp.go @@ -13,6 +13,9 @@ import ( "github.com/valyala/fasthttp" ) +// The identifier of the FastHTTP SDK. +const sdkIdentifier = "sentry.go.fasthttp" + type contextKey int const ContextKey = contextKey(1) @@ -58,6 +61,9 @@ func (h *Handler) Handle(handler fasthttp.RequestHandler) fasthttp.RequestHandle // standard net/http.Request and because fasthttp.RequestCtx implements // context.Context but requires string keys. hub := sentry.CurrentHub().Clone() + + hub.Client().SetSDKIdentifier(sdkIdentifier) + scope := hub.Scope() scope.SetRequest(convert(ctx)) scope.SetRequestBody(ctx.Request.Body()) diff --git a/gin/sentrygin.go b/gin/sentrygin.go index 98803cf7c..587a5960d 100644 --- a/gin/sentrygin.go +++ b/gin/sentrygin.go @@ -13,6 +13,9 @@ import ( "github.com/gin-gonic/gin" ) +// The identifier of the Gin SDK. +const sdkIdentifier = "sentry.go.gin" + const valuesKey = "sentry" type handler struct { @@ -54,6 +57,9 @@ func (h *handler) handle(c *gin.Context) { hub = sentry.CurrentHub().Clone() ctx = sentry.SetHubOnContext(ctx, hub) } + + hub.Client().SetSDKIdentifier(sdkIdentifier) + options := []sentry.SpanOption{ sentry.WithOpName("http.server"), sentry.ContinueFromRequest(c.Request), diff --git a/iris/sentryiris.go b/iris/sentryiris.go index 075cefee6..a06e8ec9f 100644 --- a/iris/sentryiris.go +++ b/iris/sentryiris.go @@ -12,6 +12,9 @@ import ( "github.com/kataras/iris/v12" ) +// The identifier of the Iris SDK. +const sdkIdentifier = "sentry.go.iris" + const valuesKey = "sentry" type handler struct { @@ -51,6 +54,9 @@ func (h *handler) handle(ctx iris.Context) { if hub == nil { hub = sentry.CurrentHub().Clone() } + + hub.Client().SetSDKIdentifier(sdkIdentifier) + hub.Scope().SetRequest(ctx.Request()) ctx.Values().Set(valuesKey, hub) defer h.recoverWithSentry(hub, ctx.Request()) diff --git a/logrus/logrusentry.go b/logrus/logrusentry.go index 0a3a72216..b4695f0c9 100644 --- a/logrus/logrusentry.go +++ b/logrus/logrusentry.go @@ -10,6 +10,9 @@ import ( "github.com/sirupsen/logrus" ) +// The identifier of the Logrus SDK. +const sdkIdentifier = "sentry.go.logrus" + // These default log field keys are used to pass specific metadata in a way that // Sentry understands. If they are found in the log fields, and the value is of // the expected datatype, it will be converted from a generic field, into Sentry @@ -52,6 +55,9 @@ func New(levels []logrus.Level, opts sentry.ClientOptions) (*Hook, error) { if err != nil { return nil, err } + + client.SetSDKIdentifier(sdkIdentifier) + return NewFromClient(levels, client), nil } diff --git a/martini/sentrymartini.go b/martini/sentrymartini.go index e8530b1ea..8ff7e4f96 100644 --- a/martini/sentrymartini.go +++ b/martini/sentrymartini.go @@ -9,6 +9,9 @@ import ( "github.com/go-martini/martini" ) +// The identifier of the Martini SDK. +const sdkIdentifier = "sentry.go.martini" + type handler struct { repanic bool waitForDelivery bool @@ -46,6 +49,9 @@ func (h *handler) handle(rw http.ResponseWriter, r *http.Request, ctx martini.Co if hub == nil { hub = sentry.CurrentHub().Clone() } + + hub.Client().SetSDKIdentifier(sdkIdentifier) + hub.Scope().SetRequest(r) ctx.Map(hub) defer h.recoverWithSentry(hub, r) diff --git a/negroni/sentrynegroni.go b/negroni/sentrynegroni.go index 8c4db4bd1..09a12fec2 100644 --- a/negroni/sentrynegroni.go +++ b/negroni/sentrynegroni.go @@ -9,6 +9,9 @@ import ( "github.com/urfave/negroni" ) +// The identifier of the Negroni SDK. +const sdkIdentifier = "sentry.go.negroni" + type handler struct { repanic bool waitForDelivery bool @@ -47,6 +50,9 @@ func (h *handler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.H if hub == nil { hub = sentry.CurrentHub().Clone() } + + hub.Client().SetSDKIdentifier(sdkIdentifier) + hub.Scope().SetRequest(r) ctx = sentry.SetHubOnContext( context.WithValue(ctx, sentry.RequestContextKey, r), diff --git a/sentry.go b/sentry.go index f5b3a6d1d..2d964e7e0 100644 --- a/sentry.go +++ b/sentry.go @@ -12,6 +12,7 @@ const Version = SDKVersion const SDKVersion = "0.23.0" // The identifier of the SDK. +// Deprecated: Use Client.GetSDKIdentifier() instead. const SDKIdentifier = "sentry.go" // apiVersion is the minimum version of the Sentry API compatible with the