Skip to content

SetUser does not work when called after starting a span #1009

Description

@OrkhanAlikhanov

I have this code:

func SetUserProfile(ctx context.Context, profile *models.UserProfile) error {
	span := sentry.StartSpan(ctx, "method", sentry.WithDescription("SetUserProfile"))
	defer span.Finish()

	ctx = span.Context()

	err := setProfile(profile)
	if err != nil {
		return err
	}

	sentry.ConfigureScope(func(scope *sentry.Scope) {
		scope.SetUser(sentry.User{
			ID:       profile.ID,
			Email:    profile.Email,
			Username: profile.Username,
			Name:     profile.FullName,
		})
	})

	return nil
}

But it doesn't set user when I call sentry.StartSpan in it:

func run() {
    tr := sentry.StartTransaction(context.Background(), "Command: run")
    defer tr.Finish()
    ctx := tr.Context()

    // ... 

    SetUserProfile(ctx, profile)

    // ...
     
    if err != nil {
        sentry.CaptureError(err) // no user reported
    }
}

After debugging it looks like it happens because StartSpan pushes new scope and SetUser is called on that not at the root scope.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugIssue type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions