Sentry-javascript: Directly instantiated Hub+Client don't use integrations/send integration data

Created on 23 Nov 2018  路  4Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [x] @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!

Most helpful comment

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!

All 4 comments

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.

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!

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

@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

Was this page helpful?
0 / 5 - 0 ratings