Skip to content

Commit

Permalink
Set SDK Name According Framework being used
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Aug 9, 2023
1 parent cda691d commit 8dfe036
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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-- {
Expand Down Expand Up @@ -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{{
Expand Down
6 changes: 6 additions & 0 deletions echo/sentryecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions fasthttp/sentryfasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions gin/sentrygin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions iris/sentryiris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions logrus/logrusentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions martini/sentrymartini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions negroni/sentrynegroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8dfe036

Please sign in to comment.