Skip to content

Manually instantiated Hub with provided client instance, shouldn't require additional bindClient call to setup integrations #2541

@NicHaley

Description

@NicHaley

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 #2329, however it was resolved by using hub.run(...). This does not work for me.

There was another thread #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);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions