Go SDK SetUser() concurrency

Hello,

Is there a way in the Go SDK to set the user on a per-error basis? E.g. this code reports both errors having come from user1:

package main

import (
	"errors"
	"time"

	"github.com/getsentry/sentry-go"
)

func main() {
	sentry.Init(sentry.ClientOptions{
		Dsn: "***",
	})

	go runError()
	go runError2()

	time.Sleep(time.Second * 1)
	sentry.Flush(time.Second * 5)
}

func runError() {
	sentry.ConfigureScope(func(scope *sentry.Scope) {
		scope.SetUser(sentry.User{ID: "user1"})
	})
	sentry.CaptureException(errors.New("error1"))
}

func runError2() {
	sentry.ConfigureScope(func(scope *sentry.Scope) {
		scope.SetUser(sentry.User{ID: "user2"})
	})
	sentry.CaptureException(errors.New("error2"))
}
func runError() {
	sentry.WithScope(func(scope *sentry.Scope) {
		scope.SetUser(sentry.User{ID: "user1"})
		sentry.CaptureException(errors.New("error1"))
	})
}

func runError2() {
	sentry.WithScope(func(scope *sentry.Scope) {
		scope.SetUser(sentry.User{ID: "user2"})
		sentry.CaptureException(errors.New("error2"))
	})
}

This should do the job :slight_smile:

1 Like

@kamilogorek that works great, thank you!