-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Some browser integrations does not respect the Integration#setupOnce signature #1969
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
Comments
@ghostd Thanks for pointing this out, is this actually blocking you from using it, does the linter break or anything? So technically you are right but we don't need to do it. |
@HazAT My init code is (as described in the documentation): const client = new BrowserClient({
dsn: "https://[email protected]/XXXX",
release: `${guessVersion()}`,
environment: guessEnvironment(),
beforeSend: beforeSend,
});
hub = new Hub(client); I had to manually add the integrations to have it: import {BrowserClient, defaultIntegrations, Hub} from "@sentry/browser";
const client = new BrowserClient({
dsn: "https://[email protected]/XXXX",
defaultIntegrations: defaultIntegrations,
release: `${guessVersion()}`,
environment: guessEnvironment(),
beforeSend: beforeSend,
});
hub = new Hub(client); And now, the calls to I guess i missed something... i'm still digging |
|
Thanks, i tried that too. In both cases, the user agent data are not added. |
OK, that's strange, is it possible for you to go into
and replace it with:
|
Already tried ;) This does not resolve my issue. UserAgent.prototype.setupOnce = function (addGlobalEventProcessor, getCurrentHub) {
addGlobalEventProcessor(function (event) {
console.log("UserAgent integration current hub", getCurrentHub())
console.log("UserAgent integration ?", getCurrentHub().getIntegration(UserAgent))
if (getCurrentHub().getIntegration(UserAgent)) {
if (!global$4.navigator || !global$4.location) {
return event;
}
// HTTP Interface: https://docs.sentry.io/clientdev/interfaces/http/?platform=javascript
var request = event.request || {};
request.url = request.url || global$4.location.href;
request.headers = request.headers || {};
request.headers['User-Agent'] = global$4.navigator.userAgent;
return tslib_1.__assign({}, event, { request: request });
}
return event;
});
}; The second log returns: "UserAgent integration ? null" In |
Ohhh, I know that the problem is, Integrations only work if there is a Please make sure you do the following: import { makeMain } from "@sentry/hub";
// YOUR CODE
// after you have the hub instance
makeMain(hub); Hope this fixes it. |
Good catch! Thank you so much for this 'live' debug :) BTW, if i've several app/widgets into my HTML page, and can each call Edit: |
Sorry, that worked because i had a weird call; but with a clean node_modules, the makeMain call is not enough. Weirdly, if i add a log into
The event callback is not called, it looks like a timing issue. Edit: Edit2: |
@ghostd Sorry for about this, apparently this was always broken, it's not specific to If I may ask, what is the specific reason you want to have a client/hub with integrations running instead of using |
@HazAT i have pages which can contain several app/widgets (different framework, different release cycle, different source repository, and so on), and some of those will use Sentry to handle their errors. So, maybe i misunderstood the documentation, it seems each of these apps will need a dedicated Sentry instance to avoid conflicts. I followed the documentation. Am i wrong with this? |
No, you are right. So I have a working running example here, I hope this helps and sorry for the inconvenience: |
Thanks, i'm not at the office right now. I'll give a shot tomorrow morning. I'll let you know. |
That does not work. Here is a summary of my code : In a import * as Sentry from "@sentry/browser";
let hub;
export const installErrorHandler = () => {
console.log("Should be UserAgent", Sentry.defaultIntegrations[6])
const client = new Sentry.BrowserClient({
dsn: "https://[email protected]/123",
integrations: [Sentry.defaultIntegrations[6]],
release: guessRelease(),
environment: guessEnvironment(),
beforeSend: beforeSend,
});
hub = new Sentry.Hub(client);
// Sentry.getCurrentHub();
// makeMain(hub);
};
const beforeSend = (event, hint) => {
// event should contain a 'request' property with the user agent data
console.error('beforeSend', event, hint);
return null;
};
export const captureReactError = (error, errorInfo) => {
hub.run(currentHub => {
currentHub.withScope(scope => {
scope.setExtras(errorInfo);
currentHub.captureException(error);
});
});
};
componentDidCatch(error, info) {
this.setState({hasError: true});
captureReactError(error, info);
} If i uncomment |
Here are my last find. When the processors are added with |
I was able to find the issue, fixed it, |
Amazing, your commit exactly match my find :) Thanks |
👍 Thanks for helping me debugging this. |
|
It works with the export const captureReactError = (error, errorInfo) => {
hub.run(currentHub => {
currentHub.withScope(scope => {
scope.setExtras(errorInfo);
currentHub.captureException(error);
});
});
}; Thanks! |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
Description
Hi,
It seems the integration (provided by the browser package) does not implement the correct signature of
setupOnce
, eg:https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/globalhandlers.ts#L50
https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/useragent.ts#L22
https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/trycatch.ts#L172
https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/linkederrors.ts#L43
(maybe others)
Regards
The text was updated successfully, but these errors were encountered: