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

user data missing on uncaught exception #195

Closed
crussell52 opened this issue Nov 15, 2019 · 11 comments · Fixed by #242
Closed

user data missing on uncaught exception #195

crussell52 opened this issue Nov 15, 2019 · 11 comments · Fixed by #242

Comments

@crussell52
Copy link

sdk: sentry-electron 1.0
platform: mac-os, linux (appImage)

Description

After setting user.id and a tag using configureScope(), unhandled exception does not report user info, but reports tag.

To distill, this, I turned off all integration and inspected scope during Process.unhandledException event and found user info absent.

Repro

const {app} = require('electron');
const Sentry = require('@sentry/electron');

Sentry.init({
    dsn: myDSN,
    debug: true,
    defaultIntegrations: false
});

Sentry.configureScope((scope) => {
    scope.setUser({id: 'johndoe'});
    scope.setTag("foo", "bar");
    console.log('configureScope', scope._user, scope._tags); // OK!
});

Sentry.withScope(scope => {
    console.log('withScope', scope._user, scope._tags); // OK !!
});

process.on('uncaughtException', (e) => {
    Sentry.withScope((scope) => {
        console.log('uncaughtException', scope._user, scope._tags); // USER gone!
        app.exit();
    })
});

setTimeout(() => junk(), 10000);
@crussell52
Copy link
Author

While working with #196 , I found some extra clues:

  • During uncaughtException handling, the on-disk scope (userData/sentry/scope_v2.json) appears to be used instead of the in-memory scope.
  • The on-disk scope does not include user data set via configureScope() but it does include some version of the tag data set at the same time.

@crussell52
Copy link
Author

Any progress on this. Can't move forward with sentry as a solution with this pending.
:(

@HazAT
Copy link
Member

HazAT commented Dec 17, 2019

I hope I find some time to take a look at this, we gladly accept PRs fixing this if you find time yourself.

Thanks for reporting!

@crussell52
Copy link
Author

@HazAT Have you found time to circle back to this?

I opened PR #210 with an e2e test that checks for user data. The test obviously fails. I believe the test is valid, but I could be wrong.

@jjustin3
Copy link

jjustin3 commented Jan 31, 2020

Here is the problematic line.

When laying the code out like this:

const { init } = require('@sentry/electron/dist/main');
const Sentry = require('@sentry/electron');

init({ ... });

Sentry.setUser({ ... }); // or even Sentry.configureScope( ... )

_this.rehydrateScope() (within the link above) is called asynchronously. What this means is that the Sentry.setUser({ ... }) line that follows after the initialization executes before the scope is rehydrated by the stored-off scope_v2.json file. This means that the user info (or any context info for that matter) will be overwritten after being set.

If there is exists async functionality within the init({ ... }) call, it should be made asynchronous imho or at least the docs should detail as much.

edit I managed to get this working by making the scope configuration asynchronous as well, allowing for the _this.rehydrateScope() call to fire first:

const { init } = require('@sentry/electron/dist/main');
const Sentry = require('@sentry/electron');

init({ ... });

setImmediate(() => {
    Sentry.setUser({ ... });
});

Again, this should work with any scope-modifying functionality (e.g. Sentry.configureScope( ... )). Hopefully this helps somebody out. Took me a long time to diagnose the issue.

@crussell52
Copy link
Author

@jjustin3 Thanks for the workaround. Also for digging deep enough to validate that I wasn't going crazy -- with no movement on this ticket for so long I thought maybe I was doing something very wrong 😳

If init() is doing async work, it seems like we should have some mechanism to know when it is safe to do post-init operations (event, callback, promise, etc).

I'm going to try your workaround Monday... definitely concerned that this problem is sensitive to timing conditions that would make it unreliable (or break it in future versions) but it is the best option for now!

@crussell52
Copy link
Author

@HazAT Any movement on this?

@douglassllc
Copy link

Thanks to @jjustin3 and @crussell52 for the deep dive on this issue.

@HazAT
Copy link
Member

HazAT commented Jul 14, 2020

The linked PR fixes this:

Output of the repro:

configureScope { id: 'johndoe' } { foo: 'bar' }
withScope { id: 'johndoe' } { foo: 'bar' }
...
uncaughtException { id: 'johndoe' } { foo: 'bar' }
✨  Done in 10.39s.

@lailo
Copy link

lailo commented Nov 24, 2023

I'm having exactly this issue with "@sentry/electron": "^4.11.0". If I initialize Sentry and set the user in the same file, then it works. However, if the set user is done in another place later, the user data is never sent with the error. Does someone have a solution for this?

@timfish
Copy link
Collaborator

timfish commented Nov 24, 2023

Can you open a new issue with example code that reproduces the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants