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

bugfix: ensure sentry username/id values are correct #406

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 12 additions & 7 deletions internal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,24 @@ func RequestContext(ctx context.Context) context.Context {
}

// add the user ID to this request context. Need to have called RequestContext first.
func SetRequestContextUserID(ctx context.Context, userID, deviceID string) {
func AssociateUserIDWithRequest(ctx context.Context, userID, deviceID string) context.Context {
d := ctx.Value(ctxData)
if d == nil {
return
return ctx
}
da := d.(*data)
da.userID = userID
da.deviceID = deviceID
if hub := sentry.GetHubFromContext(ctx); hub != nil {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetUser(sentry.User{Username: userID})
})
}
hub := sentry.GetHubFromContext(ctx)
if hub == nil {
// Basing the sentry-wrangling on the sentry-go net/http integration, see e.g.
// https://github.com/getsentry/sentry-go/blob/02e712a638c40cd9701ad52d5d1309d65d556ef9/http/sentryhttp.go#L84
hub = sentry.CurrentHub().Clone()
}
hub.ConfigureScope(func(scope *sentry.Scope) {
scope.SetUser(sentry.User{Username: userID, ID: deviceID})
})
return sentry.SetHubOnContext(ctx, hub)
}

func SetConnBufferInfo(ctx context.Context, bufferLen, nextLen, bufferCap int) {
Expand Down
5 changes: 1 addition & 4 deletions sync2/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,7 @@ func (p *poller) Poll(since string) {
// caller and passed down?
hub := sentry.CurrentHub().Clone()
hub.ConfigureScope(func(scope *sentry.Scope) {
scope.SetUser(sentry.User{Username: p.userID})
scope.SetContext(internal.SentryCtxKey, map[string]interface{}{
"device_id": p.deviceID,
})
scope.SetUser(sentry.User{Username: p.userID, ID: p.deviceID})
})
ctx := sentry.SetHubOnContext(context.Background(), hub)

Expand Down
2 changes: 1 addition & 1 deletion sync3/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (h *SyncLiveHandler) setupConnection(req *http.Request, cancel context.Canc
Str("device", token.DeviceID).
Str("conn", syncReq.ConnID).
Logger()
internal.SetRequestContextUserID(req.Context(), token.UserID, token.DeviceID)
req = req.WithContext(internal.AssociateUserIDWithRequest(req.Context(), token.UserID, token.DeviceID))
internal.Logf(req.Context(), "setupConnection", "identified access token as user=%s device=%s", token.UserID, token.DeviceID)

// Record the fact that we've recieved a request from this token
Expand Down
Loading