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

Integrations not called with BrowserClient

Open s-yagues opened this issue 3 years ago • 16 comments

  • [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
});

s-yagues avatar Feb 19 '21 12:02 s-yagues

+1

yyoyo avatar Mar 08 '21 13:03 yyoyo

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 avatar Mar 08 '21 15:03 kamilogorek

@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

fizz3r avatar Mar 08 '21 16:03 fizz3r

@kamilogorek What is the current timeframe for release of v7?

ghost avatar Mar 08 '21 19:03 ghost

@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 avatar Mar 16 '21 16:03 kamilogorek

@kamilogorek Any updates for this? What will be the behaviour if app with mainHub will be unmounted?

BeInLife avatar Dec 10 '21 13:12 BeInLife

Hi.

any news on this ?

thanks,

yyoyo avatar Jan 24 '22 15:01 yyoyo

@yyoyo I can share my solution with you later on Seems like it works so far

BeInLife avatar Jan 24 '22 15:01 BeInLife

@yyoyo I can share my solution with you later on Seems like it works so far

Yes Please !

yyoyo avatar Jan 25 '22 15:01 yyoyo

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

xuzhanhh avatar Jan 29 '22 02:01 xuzhanhh

@BeInLife If you have any sort of solution, can you maybe share it? ❤️

Macavity avatar Feb 18 '22 10:02 Macavity

@BeInLife If you have any sort of solution, can you maybe share it? ❤️

Yea, will do later tonight Forgot about it 🙄

BeInLife avatar Feb 18 '22 11:02 BeInLife

@BeInLife when you find time any solution would be highly appreciated!

PaulKujawa avatar Mar 11 '22 09:03 PaulKujawa

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 avatar Mar 11 '22 09:03 BeInLife

@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...

jbarker47 avatar Jul 12 '22 17:07 jbarker47

@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.

BeInLife avatar Jul 12 '22 18:07 BeInLife

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.

giladv avatar Oct 05 '22 22:10 giladv

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

smeubank avatar Dec 30 '22 13:12 smeubank

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)

adriandmitroca avatar Jan 24 '23 16:01 adriandmitroca