Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SDK Name According Framework being used #694

Merged
merged 10 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
cleptric marked this conversation as resolved.
Show resolved Hide resolved
}

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
8 changes: 8 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,3 +713,11 @@ func TestCustomMaxSpansProperty(t *testing.T) {

assertEqual(t, properClient.Options().MaxSpans, 3000)
}

func TestSDKIdentifier(t *testing.T) {
client, _, _ := setupClientTest()
assertEqual(t, client.GetSDKIdentifier(), "sentry.go")

client.SetSDKIdentifier("sentry.go.test")
assertEqual(t, client.GetSDKIdentifier(), "sentry.go.test")
}
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 @@
"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,8 +52,11 @@
if hub == nil {
hub = sentry.CurrentHub().Clone()
}

hub.Client().SetSDKIdentifier(sdkIdentifier)

hub.Scope().SetRequest(ctx.Request())
ctx.Set(valuesKey, hub)

Check warning on line 59 in echo/sentryecho.go

View check run for this annotation

Codecov / codecov/patch

echo/sentryecho.go#L56-L59

Added lines #L56 - L59 were not covered by tests
defer h.recoverWithSentry(hub, ctx.Request())
return next(ctx)
}
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 @@
"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 @@
if hub == nil {
hub = sentry.CurrentHub().Clone()
}

hub.Client().SetSDKIdentifier(sdkIdentifier)

Check warning on line 54 in martini/sentrymartini.go

View check run for this annotation

Codecov / codecov/patch

martini/sentrymartini.go#L53-L54

Added lines #L53 - L54 were not covered by tests
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 @@
"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 @@
if hub == nil {
hub = sentry.CurrentHub().Clone()
}

hub.Client().SetSDKIdentifier(sdkIdentifier)

Check warning on line 55 in negroni/sentrynegroni.go

View check run for this annotation

Codecov / codecov/patch

negroni/sentrynegroni.go#L54-L55

Added lines #L54 - L55 were not covered by tests
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
Loading