sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

setUser not work after upgade to 8.54.0

Open kingnight opened this issue 2 months ago • 9 comments

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

8.54.0

Xcode Version

16.4.0

Did it work on previous versions?

No response

Steps to Reproduce

be sure to set SentrySDK.setUser(user) after SentrySDK.start

Expected Result

SentrySDK.setUser(user) work

Actual Result

no date set successfully

Are you willing to submit a PR?

No response

kingnight avatar Nov 24 '25 02:11 kingnight

COCOA-1010

linear[bot] avatar Nov 24 '25 02:11 linear[bot]

@kingnight, do I understand correctly that you call setUser before SentrySDK.start, and it doesn't work, and you expect it to work? If yes, that's kind of per design. You have to start the SDK before interacting with it.

philipphofmann avatar Nov 24 '25 07:11 philipphofmann

@philipphofmann no, my code calling sequence has not changed,first SentrySDK.start,then setUser, only update sdk version. By the way, in order to speed up launch time ,I call SentrySDK.start on non-main thread, but when call setUser , SentrySDK.start has finished, this point has checked

kingnight avatar Nov 24 '25 10:11 kingnight

OK, I don't understand what exactly you mean by

no date set successfully

Please explain in more detail, @kingnight

philipphofmann avatar Nov 24 '25 13:11 philipphofmann

That indicates that after upgrading the SDK from version 8.48.0 to 8.54.0, the Sentry backend fails to detect the custom user data I added using setUser. When using SDK version 8.48.0, this worked fine. Can I downgrade the SDK version in the production app ? Will the downgrade cause any database issues within the SDK?

kingnight avatar Nov 25 '25 01:11 kingnight

Can I downgrade the SDK version in the production app ?

Yes, between these versions, it should be possible without issues.

I just tried this with one of our sample apps, and it works correctly.

let user = User(userId: "philipp")
user.email = "[email protected]"
SentrySDK.setUser(user) 
Image

I'm unsure what the problem is. Please be a bit more specific and tell us how exactly you call the API, what info you put on there, and what worked before and what doesn't work anymore, ideally with screenshots, @kingnight.

philipphofmann avatar Nov 26 '25 15:11 philipphofmann

@philipphofmann I have find out the reason ,

If I use 'SentrySDK.start` in no-main thread( in order to speed up launch time )

DispatchQueue.global(qos: .utility).async{
            SentrySDK.start { options in
              // code 
             print("SentrySDK.start finished")
            }
}

Then call

print("SentrySDK.setUser")
SentrySDK.setUser(user)

console log out

SentrySDK.start finished

....

SentrySDK.setUser

setUser will not be set succefully.

But if I use it on the main thread "SentrySDK.start ", then call SentrySDK.setUser(user),it 's ok

Or delay several seconds, then call SentrySDK.setUser(user),it 's ok too

The main reason remains the issue of timing for setUser(user) .

kingnight avatar Nov 28 '25 02:11 kingnight

Ah there's a race condition happening in that case. Yes, we need to fix this. Thanks for the info, @kingnight.

philipphofmann avatar Nov 28 '25 09:11 philipphofmann

@philipphofmann Thank you for your patience.

kingnight avatar Nov 28 '25 10:11 kingnight