sentry-javascript
sentry-javascript copied to clipboard
Integrations not called with BrowserClient
- [x] Review the documentation: https://docs.sentry.io/
- [x] Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- [x] Use the latest release: https://github.com/getsentry/sentry-javascript/releases
- [ ] Provide a link to the affected event from your Sentry account
Package + Version
- [x]
@sentry/browser
Version:
6.2.0
Description
We've changed our sentry browser client from using the global instance to use a separate instance with 'BrowserClientand
Hub` and integrations don't seem to be called anymore, since the Breadcrumbs, userAgent, etc data is not being sent as before. We use the default integrations. This is our init code:
import * as Sentry from "@sentry/browser";
const client = new Sentry.BrowserClient({
dsn: "%%dsn%%",
release: '%%library_version%%',
dist: '%%build_number%%',
environment: process.env.NODE_ENV,
integrations: [...Sentry.defaultIntegrations]
});
const hub = new Sentry.Hub(client);
console.log(hub.getClient()._integrations) // We can see integration instances
Our previous init was the following and integrations were working with no problem:
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "%%dsn%%",
release: '%%library_version%%',
dist: '%%build_number%%',
environment: process.env.NODE_ENV
});
+1
import * as Sentry from "@sentry/browser";
const client = new Sentry.BrowserClient({
dsn: "%%dsn%%",
release: '%%library_version%%',
dist: '%%build_number%%',
environment: process.env.NODE_ENV,
integrations: [...Sentry.defaultIntegrations]
});
const hub = new Sentry.Hub(client);
// This call is missing.
Sentry.makeMain(hub);
Unfortunately, right now you need to register the Hub so that integrations can detect it. We are reworking integrations in the next major release so they will not rely on the globally registered hub.
@kamilogorek, how can we currently prevent this call makeMain
if we have multiple instances of Sentry running in the same application? Similar to this issue: https://github.com/getsentry/sentry-javascript/issues/2783
Thanks
@kamilogorek What is the current timeframe for release of v7?
@kamilogorek, how can we currently prevent this call makeMain if we have multiple instances of Sentry running in the same application? Similar to this issue: #2783
There's no way to make integrations work for multiple clients currently, sorry.
@kamilogorek What is the current timeframe for release of v7?
Q2 21', I don't have any more specific date yet.
@kamilogorek Any updates for this?
What will be the behaviour if app with mainHub
will be unmounted?
Hi.
any news on this ?
thanks,
@yyoyo I can share my solution with you later on Seems like it works so far
@yyoyo I can share my solution with you later on Seems like it works so far
Yes Please !
Any update for this issue? I want to use different BrowserClient and makeMain when switching to different pages which using module federation. But seems not work even sending an error automatically with Sentry.defaultIntegrations
@BeInLife If you have any sort of solution, can you maybe share it? ❤️
@BeInLife If you have any sort of solution, can you maybe share it? ❤️
Yea, will do later tonight Forgot about it 🙄
@BeInLife when you find time any solution would be highly appreciated!
import * as Sentry from "@sentry/browser";
let oldHub;
const client = new Sentry.BrowserClient({
dsn: "%%dsn%%",
release: '%%library_version%%',
dist: '%%build_number%%',
environment: process.env.NODE_ENV,
integrations: [...Sentry.defaultIntegrations]
});
const hub = new Sentry.Hub(client);
// This call is missing.
oldHub = Sentry.makeMain(hub);
And when your app is unmounting, call
Sentry.makeMain(oldHub);
@PaulKujawa @Macavity @yyoyo
Sorry for delay
@BeInLife Unfortunately using Sentry.makeMain(hub)
replaces the old hub... this means that only one hub / client can be active on a single page at any given time... Not sure if this has been resolved yet in v7+ but in earlier versions this was simply not possible...
@BeInLife Unfortunately using
Sentry.makeMain(hub)
replaces the old hub... this means that only one hub / client can be active on a single page at any given time... Not sure if this has been resolved yet in v7+ but in earlier versions this was simply not possible...
That's correct, but that's the only way to work if you have multiple micro frontends on the same page. U need to set the main one and handle errors manually for others.
Hey, Any news regarding this issue? Our company has moved to a micro FE architecture and this limitation means we cannot work with sentry anymore.
https://github.com/getsentry/sentry-javascript/discussions/5217
An example repo is linked with this discussion. It also helps us if you anyone facing challenges with MFEs could post on that discussion so we can collect more information
I've been doing some testing with this.
Debug
integration is catching errors correctly, but it never reaches beforeSend
stage (which is required before sending to Sentry), even if the hub is set to main one. So this means that majority of events aren't logged in Sentry.
What works and lands in Sentry? CaptureConsole
integration.
What doesn't work and doesn't reach beforeSend stage? TryCatch
integration, GlobalHandler
integrations (major ones)