Skip to content

Commit 5ac8b2b

Browse files
committed
Merge branch 'master' into apm
* master: release: 5.9.0 feat: Introduce mode option for global promise handler in node (getsentry#2312) release: 5.8.0 misc: 5.8.0 changelog update fix(utils/object): fix normalizing error from null (getsentry#2305) doc: Link to discord, not IRC (getsentry#2304) fix: Skip empty filename in frames and fallback to location chore: Linter auto-fixes misc: 5.8.0 changelog chore: replace several instances of any (getsentry#2264) feat: 429 http code handling in node/browser transports ref: Remove dom references from utils for old TS and env interop fix: Gracefuly handle incorrect input from onerror feat: Make sure that Debug integration is always setup as the last one # Conflicts: # lerna.json # packages/browser/package.json # packages/browser/src/version.ts # packages/core/package.json # packages/hub/package.json # packages/integrations/package.json # packages/minimal/package.json # packages/node/package.json # packages/node/src/version.ts # packages/utils/package.json # packages/utils/src/misc.ts
2 parents acecb4e + cd66199 commit 5ac8b2b

37 files changed

+627
-187
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
- [hub] feat: Add more span functions (#2161)
77
- [integrations] feat: Change `Tracing` integration (#2161)
88

9+
## 5.9.0
10+
11+
- [node] feat: Added `mode` option for `OnUnhandledRejection` integration that changes how we log errors and what we do with the process itself
12+
- [browser] ref: Both global handlers now always return `true` to call default implementations (error logging)
13+
14+
## 5.8.0
15+
16+
- [browser/node] feat: 429 http code handling in node/browser transports (#2300)
17+
- [core] feat: Make sure that Debug integration is always setup as the last one (#2285)
18+
- [browser] fix: Gracefuly handle incorrect input from onerror (#2302)
19+
- [utils] fix: Safer normalizing for input with `domain` key (#2305)
20+
- [utils] ref: Remove dom references from utils for old TS and env interop (#2303)
21+
922
## 5.7.1
1023

1124
- [core] ref: Use the smallest possible interface for our needs - `PromiseLike` (#2273)

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lerna": "3.4.0",
3-
"version": "5.8.0-beta.1",
3+
"version": "5.9.0",
44
"packages": "packages/*",
55
"ignore": "raven-*",
66
"npmClient": "yarn",

packages/browser/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/browser",
3-
"version": "5.8.0-beta.1",
3+
"version": "5.9.0",
44
"description": "Official Sentry SDK for browsers",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/browser",
@@ -16,9 +16,9 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/core": "5.8.0-beta.1",
20-
"@sentry/types": "5.8.0-beta.1",
21-
"@sentry/utils": "5.8.0-beta.1",
19+
"@sentry/core": "5.8.0",
20+
"@sentry/types": "5.7.1",
21+
"@sentry/utils": "5.8.0",
2222
"tslib": "^1.9.3"
2323
},
2424
"devDependencies": {

packages/browser/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { captureException, getCurrentHub, withScope } from '@sentry/core';
2-
import { Event as SentryEvent, Mechanism, WrappedFunction } from '@sentry/types';
2+
import { Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
33
import { addExceptionMechanism, addExceptionTypeValue, htmlTreeAsString, normalize } from '@sentry/utils';
44

55
const debounceDuration: number = 1000;
@@ -92,7 +92,7 @@ export function wrap(
9292
} catch (ex) {
9393
ignoreNextOnError();
9494

95-
withScope(scope => {
95+
withScope((scope: Scope) => {
9696
scope.addEventProcessor((event: SentryEvent) => {
9797
const processedEvent = { ...event };
9898

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export class Breadcrumbs implements Integration {
468468
});
469469

470470
if ('onreadystatechange' in xhr && typeof xhr.onreadystatechange === 'function') {
471-
fill(xhr, 'onreadystatechange', function(original: () => void): void {
471+
fill(xhr, 'onreadystatechange', function(original: () => void): Function {
472472
return wrap(
473473
original,
474474
{

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class GlobalHandlers implements Integration {
9292
if (self._oldOnErrorHandler) {
9393
return self._oldOnErrorHandler.apply(this, arguments);
9494
}
95-
return false;
95+
return true;
9696
}
9797

9898
const client = currentHub.getClient();
@@ -121,7 +121,7 @@ export class GlobalHandlers implements Integration {
121121
return self._oldOnErrorHandler.apply(this, arguments);
122122
}
123123

124-
return false;
124+
return true;
125125
};
126126

127127
this._onErrorHandlerInstalled = true;
@@ -152,7 +152,7 @@ export class GlobalHandlers implements Integration {
152152
if (self._oldOnUnhandledRejectionHandler) {
153153
return self._oldOnUnhandledRejectionHandler.apply(this, arguments);
154154
}
155-
return false;
155+
return true;
156156
}
157157

158158
const client = currentHub.getClient();
@@ -178,7 +178,7 @@ export class GlobalHandlers implements Integration {
178178
return self._oldOnUnhandledRejectionHandler.apply(this, arguments);
179179
}
180180

181-
return false;
181+
return true;
182182
};
183183

184184
this._onUnhandledRejectionHandlerInstalled = true;
@@ -240,13 +240,17 @@ export class GlobalHandlers implements Integration {
240240
event.exception.values[0].stacktrace = event.exception.values[0].stacktrace || {};
241241
event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames || [];
242242

243+
const colno = isNaN(parseInt(column, 10)) ? undefined : column;
244+
const lineno = isNaN(parseInt(line, 10)) ? undefined : line;
245+
const filename = isString(url) && url.length > 0 ? url : getLocationHref();
246+
243247
if (event.exception.values[0].stacktrace.frames.length === 0) {
244248
event.exception.values[0].stacktrace.frames.push({
245-
colno: column,
246-
filename: url || getLocationHref(),
249+
colno,
250+
filename,
247251
function: '?',
248252
in_app: true,
249-
lineno: line,
253+
lineno,
250254
});
251255
}
252256

packages/browser/src/sdk.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,5 @@ export function close(timeout?: number): PromiseLike<boolean> {
163163
* @returns The result of wrapped function call.
164164
*/
165165
export function wrap(fn: Function): any {
166-
// tslint:disable-next-line: no-unsafe-any
167-
return internalWrap(fn)();
166+
return internalWrap(fn)(); // tslint:disable-line:no-unsafe-any
168167
}
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import { Event, Response, Status } from '@sentry/types';
2-
import { getGlobalObject, supportsReferrerPolicy } from '@sentry/utils';
2+
import { getGlobalObject, logger, parseRetryAfterHeader, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';
33

44
import { BaseTransport } from './base';
55

66
const global = getGlobalObject<Window>();
77

88
/** `fetch` based transport */
99
export class FetchTransport extends BaseTransport {
10+
/** Locks transport after receiving 429 response */
11+
private _disabledUntil: Date = new Date(Date.now());
12+
1013
/**
1114
* @inheritDoc
1215
*/
1316
public sendEvent(event: Event): PromiseLike<Response> {
17+
if (new Date(Date.now()) < this._disabledUntil) {
18+
return Promise.reject({
19+
event,
20+
reason: `Transport locked till ${this._disabledUntil} due to too many requests.`,
21+
status: 429,
22+
});
23+
}
24+
1425
const defaultOptions: RequestInit = {
1526
body: JSON.stringify(event),
1627
method: 'POST',
@@ -22,9 +33,30 @@ export class FetchTransport extends BaseTransport {
2233
};
2334

2435
return this._buffer.add(
25-
global.fetch(this.url, defaultOptions).then(response => ({
26-
status: Status.fromHttpCode(response.status),
27-
})),
36+
new SyncPromise<Response>(async (resolve, reject) => {
37+
let response;
38+
try {
39+
response = await global.fetch(this.url, defaultOptions);
40+
} catch (err) {
41+
reject(err);
42+
return;
43+
}
44+
45+
const status = Status.fromHttpCode(response.status);
46+
47+
if (status === Status.Success) {
48+
resolve({ status });
49+
return;
50+
}
51+
52+
if (status === Status.RateLimit) {
53+
const now = Date.now();
54+
this._disabledUntil = new Date(now + parseRetryAfterHeader(now, response.headers.get('Retry-After')));
55+
logger.warn(`Too many requests, backing off till: ${this._disabledUntil}`);
56+
}
57+
58+
reject(response);
59+
}),
2860
);
2961
}
3062
}

packages/browser/src/transports/xhr.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { Event, Response, Status } from '@sentry/types';
2-
import { SyncPromise } from '@sentry/utils';
2+
import { logger, parseRetryAfterHeader, SyncPromise } from '@sentry/utils';
33

44
import { BaseTransport } from './base';
55

66
/** `XHR` based transport */
77
export class XHRTransport extends BaseTransport {
8+
/** Locks transport after receiving 429 response */
9+
private _disabledUntil: Date = new Date(Date.now());
10+
811
/**
912
* @inheritDoc
1013
*/
1114
public sendEvent(event: Event): PromiseLike<Response> {
15+
if (new Date(Date.now()) < this._disabledUntil) {
16+
return Promise.reject({
17+
event,
18+
reason: `Transport locked till ${this._disabledUntil} due to too many requests.`,
19+
status: 429,
20+
});
21+
}
22+
1223
return this._buffer.add(
1324
new SyncPromise<Response>((resolve, reject) => {
1425
const request = new XMLHttpRequest();
@@ -18,10 +29,17 @@ export class XHRTransport extends BaseTransport {
1829
return;
1930
}
2031

21-
if (request.status === 200) {
22-
resolve({
23-
status: Status.fromHttpCode(request.status),
24-
});
32+
const status = Status.fromHttpCode(request.status);
33+
34+
if (status === Status.Success) {
35+
resolve({ status });
36+
return;
37+
}
38+
39+
if (status === Status.RateLimit) {
40+
const now = Date.now();
41+
this._disabledUntil = new Date(now + parseRetryAfterHeader(now, request.getResponseHeader('Retry-After')));
42+
logger.warn(`Too many requests, backing off till: ${this._disabledUntil}`);
2543
}
2644

2745
reject(request);

packages/browser/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const SDK_NAME = 'sentry.javascript.browser';
2-
export const SDK_VERSION = '5.8.0-beta.1';
2+
export const SDK_VERSION = '5.9.0';

0 commit comments

Comments
 (0)