8000 fix: tracing integration build (#2083) · nshobayo/sentry-javascript@6a665a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a665a2

Browse files
authored
fix: tracing integration build (getsentry#2083)
1 parent 90949f3 commit 6a665a2

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 5.3.1
4+
5+
- [integrations] fix: Tracing integration CDN build.
6+
37
## 5.3.0
48

59
- [browser] fix: Remove `use_strict` from `@sentry/browser`

packages/integrations/src/tracing.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { consoleSandbox, fill, getGlobalObject, isMatchingPattern, supportsNativ
33

44
/** JSDoc */
55
interface TracingOptions {
6-
tracingOrigins: Array<string | RegExp>;
6+
tracingOrigins?: Array<string | RegExp>;
77
traceXHR?: boolean;
88
traceFetch?: boolean;
99
autoStartOnDomReady?: boolean;
@@ -35,7 +35,7 @@ export class Tracing implements Integration {
3535
*
3636
* @param _options TracingOptions
3737
*/
38-
public constructor(private readonly _options: TracingOptions) {
38+
public constructor(private readonly _options: TracingOptions = {}) {
3939
if (!Array.isArray(_options.tracingOrigins) || _options.tracingOrigins.length === 0) {
4040
consoleSandbox(() => {
4141
const defaultTracingOrigins = ['localhost', /^\//];
@@ -88,7 +88,7 @@ export class Tracing implements Integration {
8888
* JSDoc
8989
*/
9090
private _traceXHR(getCurrentHub: () => Hub): void {
91-
if (!('XMLHttpRequest' in global)) {
91+
if (!('XMLHttpRequest' in getGlobalObject<Window>())) {
9292
return;
9393
}
9494

@@ -116,11 +116,12 @@ export class Tracing implements Integration {
116116
function(this: XMLHttpRequest, ...args: any[]): void {
117117
// @ts-ignore
118118
const self = getCurrentHub().getIntegration(Tracing);
119-
if (self && self._xhrUrl) {
119+
if (self && self._xhrUrl && self._options.tracingOrigins) {
120+
const url = self._xhrUrl;
120121
const headers = getCurrentHub().traceHeaders();
121122
// tslint:disable-next-line: prefer-for-of
122123
const isWhitelisted = self._options.tracingOrigins.some((origin: string | RegExp) =>
123-
isMatchingPattern(self._xhrUrl, origin),
124+
isMatchingPattern(url, origin),
124125
);
125126

126127
if (isWhitelisted && this.setRequestHeader) {
@@ -148,12 +149,12 @@ export class Tracing implements Integration {
148149
return function(...args: any[]): void {
149150
// @ts-ignore
150151
const self = getCurrentHub().getIntegration(Tracing);
151-
if (self) {
152+
if (self && self._options.tracingOrigins) {
152153
const url = args[0] as string;
153154
const options = args[1] as { [key: string]: any };
154155

155156
let whiteListed = false;
156-
self._options.tracingOrigins.forEach((whiteListUrl: string) => {
157+
self._options.tracingOrigins.forEach((whiteListUrl: string | RegExp) => {
157158
if (!whiteListed) {
158159
whiteListed = isMatchingPattern(url, whiteListUrl);
159160
}
@@ -171,7 +172,7 @@ export class Tracing implements Integration {
171172
}
172173
}
173174
// tslint:disable-next-line: no-unsafe-any
174-
return originalFetch.apply(global, args);
175+
return originalFetch.apply(getGlobalObject<Window>(), args);
175176
};
176177
});
177178
// tslint:enable: only-arrow-functions

0 commit comments

Comments
 (0)
0