Skip to content

Integrations don't work when using Sentry Client directly #2329

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
akaSybe opened this issue Nov 28, 2019 · 5 comments
Closed
4 of 8 tasks

Integrations don't work when using Sentry Client directly #2329

akaSybe opened this issue Nov 28, 2019 · 5 comments

Comments

@akaSybe
Copy link

akaSybe commented Nov 28, 2019

Package + Version

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

Version:

5.9.1

Description

I followed instruction how to use Sentry Client directly: https://github.com/getsentry/sentry-docs/blob/master/src/collections/_documentation/platforms/javascript/advance-settings.md.

My Sentry initialization looks like this:

  const options = {
    dsn: "MY_SENTRY_DSN",
    release: "x.x.x",
    environment: "production",
    integrations: [...Sentry.defaultIntegrations],
  };
  const client = new Sentry.BrowserClient(options);
  this.hub = new Sentry.Hub(client);
  ...
  ...
  // later in code
  this.hub.captureMessage("Hello");

Bug
Integrations don't work, they don't enhance event

Reason
– On every event, integration's globalEventProcessor called (e.g UserAgent integration): source code
– Sentry looks if current hub has integration (e.g UserAgent): source code
– Sentry looks for current hub: source code
– Sentry checks if there is window.__SENTRY__.huband fails: source code
– Sentry creates new hub without client passed as parameter to Hub constructor: source code
hub.getIntegration method returns null cause there is no client: source code
– integration skipped cause hub doesn't have current integration :(

@akaSybe
Copy link
Author

akaSybe commented Nov 28, 2019

as a workaround I should add this line to make integrations work:

window.__SENTRY__.hub = this.hub;

but it doesn't look like right solution

@kamilogorek
Copy link
Contributor

@akaSybe you missed the last part of the documentation https://github.com/getsentry/sentry-docs/blob/master/src/collections/_documentation/platforms/javascript/advance-settings.md#dealing-with-integrations

this.hub.run(currentHub => {
  currentHub.captureMessage("Hello");
});

@akaSybe
Copy link
Author

akaSybe commented Nov 29, 2019

Ohh, okay, it'll cover explicit error capturing:

this.hub.captureMessage("Hello");

but I guess errors catched on global level (window.onerror) still won't be enhanced by integrations, though need to check it

@kamilogorek
Copy link
Contributor

That is correct. In order for global handlers to work with integrations as well, there has to be initialized global instance as well.

@rhcarvalho
Copy link
Contributor

Closing as this seems to be solved.

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

3 participants