Skip to content

Directly instantiated Hub+Client don't use integrations/send integration data #1764

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

Closed
4 of 8 tasks
felixc opened this issue Nov 23, 2018 · 8 comments
Closed
4 of 8 tasks
Assignees

Comments

@felixc
Copy link

felixc commented Nov 23, 2018

Package + Version

  • @sentry/browser - 4.3.4
  • @sentry/node - N/A
  • raven-js - N/A
  • raven-node (raven for node) - N/A
  • other: - N/A

Version:

4.3.4

Description

When directly instantiating a Client and Hub following the instructions in https://docs.sentry.io/platforms/javascript/advance-settings/, the events reported do not show (in the web UI) any of the default integration data. For example, there are no breadcrumbs and no user-agent information.

Specifically, reporting events like this:

import { BrowserClient, Hub } from '@sentry/browser';

let sentry = new Hub(new BrowserClient({ dsn: '...' }));
sentry.captureException(...);

...produces events that in the web UI that have the basic exception info, but no breadcrumbs or user-agent info.

On the other hand, using the same DSN and reporting the same exception, but configured like this:

import * as Sentry from '@sentry/browser';

Sentry.init({ dsn: '...' });
Sentry.captureException(...);

...all the integration data is there.

Adding the debug: true parameter to the configuration in both cases shows that the custom Hub+Client do not print anything to the console about integrations being used, while the second (global) case does print the default list of integrations.

I also tried importing defaultIntegrations and passing integrations: defaultIntegrations when instantiating the BrowserClient, but it didn't change anything.

Any pointers would be greatly appreciated!

@HazAT
Copy link
Member

HazAT commented Nov 26, 2018

Hey, so here is a working example:
https://codesandbox.io/s/z3wyllkpq4

Hope this helps.

The thing that's missing is to make your new Hub the current global hub.
Using getCurrentHub instead of new Hub makes sure it works that way.

I am closing this if you are still having troubles let me know.

@HazAT HazAT self-assigned this Nov 26, 2018
@HazAT HazAT closed this as completed Nov 26, 2018
@felixc
Copy link
Author

felixc commented Nov 26, 2018

Thanks for the info!

Is the way Hubs work explained the docs somewhere? I'm concerned that using a "global" Hub may undo the point of using a custom Client; namely being able to send different events to different DSNs within the same web app. The instructions here https://docs.sentry.io/platforms/javascript/advance-settings/ say that this is the way "to be able to manage several Sentry instances without any conflicts between them", and they suggest creating your own Hub rather than using the global one.

Is using the global Hub with a custom Client still safe for use in a context where multiple Sentry instances are active within the same webapp? These are all within the same organization so it's "safe" if info like breadcrumbs "leak" between them, and of course any exception that bubbles up to the top level unhandled will go to whatever is the default, but can different teams within one org send exceptions to different DSNs using this mechanism?

Apologies if this is all in the docs somewhere; I scoured them pretty extensively but couldn't find details on this use case. Thanks again for your help!

@jacoor
Copy link

jacoor commented Nov 26, 2018

@kamilogorek @felixc @HazAT thank you all for this - I had the very same issue today.
I have trouble testing multiple endpoints - @felixc did you manage verifying it?

@daisy1754
Copy link

@HazAT Hi Daniel want to bump this thread, we want to use sentry in the context of our own library so ability to having separate sentry client while leveraging integration such as UserAgent would be great

@ghost
Copy link

ghost commented Feb 24, 2021

It looks like this has been an issue for a couple of years now without any resolution. It would be very helpful to have concrete guidance on how exactly to have multiple Hub / Client instances of Sentry running on a single web page that can each automatically log all unhandled exceptions for only their issues to their own DSN.

@vsashyn
Copy link

vsashyn commented Apr 7, 2021

Here is a doc link that I've found useful regarding this issue https://docs.sentry.io/platforms/javascript/troubleshooting/#using-a-client-directly .

@MickeyKay
Copy link

@vsashyn the doc you shared is great, thank you, however I'm still unclear on how this is meant to work without imperatively calling hub.run() 🤔 . In other words, what is the recommended approach for configuring more than one Sentry instance to passively (aka without imperatively calling run()) capture errors while preserving instance configuration (namely, sending errors to appropriate project in situations like the ones commonly cited in this and related issues re: running micro-apps/widgets within larger experiences?

For the record, calling hub.run() per the linked doc does indeed seem to ensure that all integrations are working properly. However, despite searching through the numerous related issues in this project on the topic of integrations not working across multiple Sentry instances, I cannot seem to find a workable solution.

Any help would be much appreciated, thanks!

@chrisbrooks
Copy link

@vsashyn the doc you shared is great, thank you, however I'm still unclear on how this is meant to work without imperatively calling hub.run() 🤔 . In other words, what is the recommended approach for configuring more than one Sentry instance to passively (aka without imperatively calling run()) capture errors while preserving instance configuration (namely, sending errors to appropriate project in situations like the ones commonly cited in this and related issues re: running micro-apps/widgets within larger experiences?

For the record, calling hub.run() per the linked doc does indeed seem to ensure that all integrations are working properly. However, despite searching through the numerous related issues in this project on the topic of integrations not working across multiple Sentry instances, I cannot seem to find a workable solution.

Any help would be much appreciated, thanks!

I just ended up using the example above. We have a single spa application which has a top level instance of sentry then for each micro app we need another instance. I just used this approach but honestly it seems a bit hacky and i'm not 100% sure why this is needed. https://codesandbox.io/s/z3wyllkpq4?file=/src/index.js.

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

No branches or pull requests

7 participants