Skip to content

Commit 1b564cd

Browse files
committed
fix: Call setupOnce in integrations
1 parent 6de1805 commit 1b564cd

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API, getCurrentHub, logger } from '@sentry/core';
2-
import { Integration, Severity } from '@sentry/types';
2+
import { Breadcrumb, Integration, SentryBreadcrumbHint, Severity } from '@sentry/types';
33
import { isFunction, isString } from '@sentry/utils/is';
44
import { getEventDescription, getGlobalObject, parseUrl } from '@sentry/utils/misc';
55
import { deserialize, fill } from '@sentry/utils/object';
@@ -27,7 +27,7 @@ function addSentryBreadcrumb(serializedData: string): void {
2727
try {
2828
const event: { [key: string]: any } = deserialize(serializedData);
2929

30-
getCurrentHub().addBreadcrumb(
30+
Breadcrumbs.addBreadcrumb(
3131
{
3232
category: 'sentry',
3333
event_id: event.event_id,
@@ -113,7 +113,7 @@ export class Breadcrumbs implements Integration {
113113
breadcrumbData.level = Severity.Error;
114114
}
115115

116-
getCurrentHub().addBreadcrumb(breadcrumbData, {
116+
Breadcrumbs.addBreadcrumb(breadcrumbData, {
117117
input: args,
118118
result,
119119
});
@@ -156,7 +156,7 @@ export class Breadcrumbs implements Integration {
156156
}
157157
}
158158

159-
getCurrentHub().addBreadcrumb(breadcrumbData, {
159+
Breadcrumbs.addBreadcrumb(breadcrumbData, {
160160
input: args,
161161
level,
162162
});
@@ -230,7 +230,7 @@ export class Breadcrumbs implements Integration {
230230
.apply(global, args)
231231
.then((response: Response) => {
232232
fetchData.status_code = response.status;
233-
getCurrentHub().addBreadcrumb(
233+
Breadcrumbs.addBreadcrumb(
234234
{
235235
category: 'fetch',
236236
data: fetchData,
@@ -244,7 +244,7 @@ export class Breadcrumbs implements Integration {
244244
return response;
245245
})
246246
.catch((error: Error) => {
247-
getCurrentHub().addBreadcrumb(
247+
Breadcrumbs.addBreadcrumb(
248248
{
249249
category: 'fetch',
250250
data: fetchData,
@@ -295,7 +295,7 @@ export class Breadcrumbs implements Integration {
295295
from = parsedFrom.relative;
296296
}
297297

298-
getCurrentHub().addBreadcrumb({
298+
Breadcrumbs.addBreadcrumb({
299299
category: 'navigation',
300300
data: {
301301
from,
@@ -404,7 +404,7 @@ export class Breadcrumbs implements Integration {
404404
} catch (e) {
405405
/* do nothing */
406406
}
407-
getCurrentHub().addBreadcrumb(
407+
Breadcrumbs.addBreadcrumb(
408408
{
409409
category: 'xhr',
410410
data: xhr.__sentry_xhr__,
@@ -447,6 +447,13 @@ export class Breadcrumbs implements Integration {
447447
},
448448
);
449449
}
450+
451+
public static addBreadcrumb(breadcrumb: Breadcrumb, hint?: SentryBreadcrumbHint): void {
452+
if (getCurrentHub().getIntegration('Breadcrumbs')) {
453+
getCurrentHub().addBreadcrumb(breadcrumb, hint);
454+
}
455+
}
456+
450457
/**
451458
* Instrument browser built-ins w/ breadcrumb capturing
452459
* - Console API

packages/browser/src/integrations/reportingobserver.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureMessage, withScope } from '@sentry/core';
1+
import { captureMessage, getCurrentHub, withScope } from '@sentry/core';
22
import { Integration } from '@sentry/types';
33
import { getGlobalObject } from '@sentry/utils/misc';
44
import { supportsReportingObserver } from '@sentry/utils/supports';
@@ -92,6 +92,9 @@ export class ReportingObserver implements Integration {
9292
* @inheritDoc
9393
*/
9494
public handler(reports: Report[]): void {
95+
if (!getCurrentHub().getIntegration(this.name)) {
96+
return;
97+
}
9598
for (const report of reports) {
9699
withScope(scope => {
97100
scope.setExtra('url', report.url);

packages/browser/src/integrations/useragent.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export class UserAgent implements Integration {
1515
* @inheritDoc
1616
*/
1717
public setupOnce(): void {
18-
if (getCurrentHub().getIntegration(this.name)) {
19-
configureScope(scope => {
20-
scope.addEventProcessor(async (event: SentryEvent) => {
18+
configureScope(scope => {
19+
scope.addEventProcessor(async (event: SentryEvent) => {
20+
if (getCurrentHub().getIntegration(this.name)) {
2121
if (!global.navigator || !global.location) {
2222
return event;
2323
}
@@ -32,8 +32,9 @@ export class UserAgent implements Integration {
3232
...event,
3333
request,
3434
};
35-
});
35+
}
36+
return event;
3637
});
37-
}
38+
});
3839
}
3940
}

packages/core/src/integrations/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export interface IntegrationIndex {
2424
*/
2525
export function setupIntegrations<O extends Options>(options: O): IntegrationIndex {
2626
const integrations: IntegrationIndex = {};
27-
let integrationsToInstall = options.defaultIntegrations === false ? [] : [...options.defaultIntegrations];
28-
if (Array.isArray(integrationsToInstall)) {
29-
const providedIntegrationsNames = integrationsToInstall.map(i => i.name);
27+
let integrationsToInstall = (options.defaultIntegrations && [...options.defaultIntegrations]) || [];
28+
if (Array.isArray(options.integrations)) {
29+
const providedIntegrationsNames = options.integrations.map(i => i.name);
3030
integrationsToInstall = [
3131
// Leave only unique integrations, that were not overridden with provided integrations with the same name
3232
...integrationsToInstall.filter(integration => providedIntegrationsNames.indexOf(integration.name) === -1),
@@ -39,10 +39,10 @@ export function setupIntegrations<O extends Options>(options: O): IntegrationInd
3939
// Just in case someone will return non-array from a `itegrations` callback
4040
if (Array.isArray(integrationsToInstall)) {
4141
integrationsToInstall.forEach(integration => {
42+
integrations[name] = integration;
4243
if (installedIntegrations.indexOf(integration.name) !== -1) {
4344
return;
4445
}
45-
integrations[name] = integration;
4646
try {
4747
if (integration.setupOnce) {
4848
// TODO remove

packages/core/src/integrations/pluggable/debug.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ export class Debug implements Integration {
3333
* @inheritDoc
3434
*/
3535
public install(): void {
36-
if (getCurrentHub().getIntegration(this.name)) {
37-
configureScope(scope => {
38-
scope.addEventProcessor(async (event: SentryEvent, hint?: SentryEventHint) => {
36+
configureScope(scope => {
37+
scope.addEventProcessor(async (event: SentryEvent, hint?: SentryEventHint) => {
38+
if (getCurrentHub().getIntegration(this.name)) {
3939
// tslint:disable:no-console
4040
// tslint:disable:no-debugger
41-
4241
if (this.options.debugger) {
4342
debugger;
4443
}
@@ -54,9 +53,9 @@ export class Debug implements Integration {
5453
console.log(hint);
5554
}
5655
}
57-
return event;
58-
});
56+
}
57+
return event;
5958
});
60-
}
59+
});
6160
}
6261
}

packages/core/src/integrations/pluggable/rewriteframes.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ export class RewriteFrames implements Integration {
4343
* @inheritDoc
4444
*/
4545
public install(): void {
46-
if (getCurrentHub().getIntegration(this.name)) {
47-
getCurrentHub().configureScope((scope: Scope) => {
48-
scope.addEventProcessor(async event => this.process(event));
46+
getCurrentHub().configureScope((scope: Scope) => {
47+
scope.addEventProcessor(async event => {
48+
if (getCurrentHub().getIntegration(this.name)) {
49+
return this.process(event);
50+
}
51+
return event;
4952
});
50-
}
53+
});
5154
}
5255

5356
/** JSDoc */

0 commit comments

Comments
 (0)