Manually instantiated Hub with provided client instance, shouldn't require additional bindClient call to setup integrations
See original GitHub issue- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
- Provide a link to the affected event from your Sentry account: https://sentry.io/organizations/ada/issues/1612951359/?environment=development&project=1410309&query=is%3Aunresolved
Package + Version
-
@sentry/browser
-
@sentry/node
-
raven-js
-
raven-node
(raven for node) - other:
Version:
5.15.4
Description
As per the Advance Usage docs, I am trying to manage several instances of Sentry. I am developing a widget and would like to use Sentry without it conflicting with the host page.
Creating new instances BrowserClient
and Hub
classes seems to be a great way to do that, but I can’t get it to work with my integrations. I found a similar issue https://github.com/getsentry/sentry-javascript/issues/2329, however it was resolved by using hub.run(...)
. This does not work for me.
There was another thread https://github.com/getsentry/sentry-javascript/issues/1764 as well, but the provided solution involves setting the new hub to the current global hub with getCurrentHub().bindClient(client);
. This works, but it seems to defeat the point of what I’m trying to accomplish since I don’t want to modify any globals that might interfere with the host page.
My code looks like this:
const { Hub, BrowserClient, defaultIntegrations } = Sentry;
const client = new BrowserClient({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
integrations: defaultIntegrations
});
const hub = new Hub(client);
// ...Later
hub.run((currentHub) => {
currentHub.captureException(error);
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Thanks @mcaballeropinto and @kamilogorek. The above makes sense. I am using the
Client
directly, and leveragingsetupIntegrations
should give me most of what I need for the time being.Thanks for the feedback @mcaballeropinto. @NicHaley the comments above are correct. You need to manually bind the client to the new hub as well
hub.bindClient(client)
. This looks like an oversight on our end, as it’s a very rarely used feature. I’ll rename this issue to more descriptive one and mark it as a bug.