-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add instructions for adding initial scope when using BrowserClient #5345
Comments
Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️ |
Just ran into this. I was migrating code from using It's not a huge deal as the suggested workaround works, but it does lead to some unnecessary confusion and debugging. |
I think the underlying issue here is that we restructured As for setting an initial scope in a direct hub/client scenario, the code snippet from @yuval-sentry shows how to do it correctly, namely pass it to the Hub constructor (also, see my repro how to fully initialize a client as this is missing in the snippet). |
I did some more digging as to why we actually have this option and it seems to be only present in the JS SDK (i.e. is not part of our unified SDK API) because our Electron SDK needs it: getsentry/sentry-javascript#3544 and @timfish can you confirm that a) we still need this option for Electron and b) moving it from |
In the Electron SDK we support native crash reporting via two integrations.
Some customers prefer Customers wanted a means to attach metadata to these native events and from what I remember, import { init, Integrations } from '@sentry/electron/main';
init({
dsn: "__DSN__",
integrations: [Integrations.ElectronMinidump()],
initialScope: {
user: { id: "12345" },
}
}); I can't speak for Sentry React-Native, but if I was going to add this feature now, specifically for the Electron SDK, I would make it a constructor parameter of the integration rather than part of init({
dsn: "__DSN__",
integrations: [Integrations.ElectronMinidump({
initialScope: {
user: { id: "12345" },
}
})],
}); |
Seems like they deprecated this option already getsentry/sentry-react-native#1925
Sounds even better 😅 |
I'll open a tracking issue in the Electron repo for this! |
I've just done some testing and it's not quite as simple as moving the To match the previous behaviour you'd need to do something like this: const initialScope = { user: { id: "12345" }};
init({
dsn: "__DSN__",
integrations: [Integrations.ElectronMinidump({ initialScope })],
});
getCurrentHub().setUser(initialScope.user); I'm not sure if we should remove this since other SDKs have started implementing it and it's use is widespread since the alternative is quite verbose. |
Since we changed a bunch of things around this, I am going to close this. If this is still an issue, please feel free to reopen! |
Core or SDK?
Platform/SDK
Which part? Which one?
Javascript
Description
Per our client:
"The real problem here is that BrowserClient accepts an initialScope parameter in its constructor and in its TypeScript types but does not actually do anything with it, leading to confusion. This is likely something that should be fixed by either not accepting the initialScope parameter in BrowserClient, or by actually acting on the initialScope parameter.
Once I looked at the source code and discovered that initialScope does nothing, I figured out the rest.
At least documenting this solution for capturing user sessions with BrowserClient on the docs site would be helpful."
Suggested Solution
Add a reference for when using BrowserClient with a code sample like this one:
The text was updated successfully, but these errors were encountered: