rollbar 2.17.0 → 2.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/defaults.js +0 -1
- package/dist/rollbar.js +3810 -3556
- package/dist/rollbar.js.map +1 -1
- package/dist/rollbar.min.js +1 -1
- package/dist/rollbar.min.js.map +1 -1
- package/dist/rollbar.named-amd.js +3807 -3553
- package/dist/rollbar.named-amd.js.map +1 -1
- package/dist/rollbar.named-amd.min.js +1 -1
- package/dist/rollbar.named-amd.min.js.map +1 -1
- package/dist/rollbar.noconflict.umd.js +3807 -3553
- package/dist/rollbar.noconflict.umd.js.map +1 -1
- package/dist/rollbar.noconflict.umd.min.js +1 -1
- package/dist/rollbar.noconflict.umd.min.js.map +1 -1
- package/dist/rollbar.snippet.js +1 -1
- package/dist/rollbar.umd.js +3807 -3553
- package/dist/rollbar.umd.js.map +1 -1
- package/dist/rollbar.umd.min.js +1 -1
- package/dist/rollbar.umd.min.js.map +1 -1
- package/index.d.ts +2 -0
- package/package.json +1 -62
- package/src/api.js +13 -7
- package/src/browser/core.js +561 -0
- package/src/browser/defaults/scrubFields.js +59 -0
- package/src/browser/globalSetup.js +1 -41
- package/src/browser/rollbar.js +16 -544
- package/src/browser/shim.js +2 -1
- package/src/browser/telemetry.js +33 -17
- package/src/browser/transforms.js +28 -5
- package/src/browser/transport.js +13 -10
- package/src/browser/wrapGlobals.js +41 -0
- package/src/defaults.js +9 -0
- package/src/predicates.js +1 -0
- package/src/react-native/rollbar.js +9 -3
- package/src/react-native/transforms.js +7 -1
- package/src/react-native/transport.js +16 -10
- package/src/rollbar.js +9 -10
- package/src/scrub.js +93 -0
- package/src/server/rollbar.js +6 -2
- package/src/server/sourceMap/stackTrace.js +1 -2
- package/src/server/transforms.js +18 -4
- package/src/transforms.js +0 -1
- package/src/truncation.js +3 -2
- package/src/utility/traverse.js +38 -0
- package/src/utility.js +25 -107
- package/test/api.test.js +2 -0
- package/test/apiUtility.test.js +2 -1
- package/test/browser.core.test.js +555 -0
- package/test/browser.rollbar.test.js +116 -13
- package/test/browser.transforms.test.js +22 -2
- package/test/browser.transport.test.js +5 -2
- package/test/react-native.transport.test.js +5 -1
- package/test/server.transforms.test.js +70 -0
- package/test/truncation.test.js +2 -0
- package/test/utility.test.js +44 -13
package/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ declare namespace Rollbar {
|
|
|
41
41
|
export type Level = "debug" | "info" | "warning" | "error" | "critical";
|
|
42
42
|
export interface Configuration {
|
|
43
43
|
accessToken?: string;
|
|
44
|
+
addErrorContext?: boolean;
|
|
44
45
|
addRequestData?: (data: object, req: object) => void;
|
|
45
46
|
autoInstrument?: AutoInstrumentOptions;
|
|
46
47
|
captureEmail?: boolean;
|
|
@@ -57,6 +58,7 @@ declare namespace Rollbar {
|
|
|
57
58
|
exitOnUncaughtException?: boolean;
|
|
58
59
|
environment?: string;
|
|
59
60
|
filterTelemetry?: (e: TelemetryEvent) => boolean;
|
|
61
|
+
host?: string; // used in node only
|
|
60
62
|
hostBlackList?: string[];
|
|
61
63
|
hostWhiteList?: string[];
|
|
62
64
|
ignoredMessages?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollbar",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "http://github.com/rollbar/rollbar.js"
|
|
@@ -12,9 +12,7 @@
|
|
|
12
12
|
"types": "./index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"async": "~1.2.1",
|
|
15
|
-
"buffer-from": "~1.1.1",
|
|
16
15
|
"console-polyfill": "0.3.0",
|
|
17
|
-
"debug": "2.6.9",
|
|
18
16
|
"error-stack-parser": "^2.0.4",
|
|
19
17
|
"json-stringify-safe": "~5.0.0",
|
|
20
18
|
"lru-cache": "~2.2.1",
|
|
@@ -97,65 +95,6 @@
|
|
|
97
95
|
},
|
|
98
96
|
"defaults": {
|
|
99
97
|
"endpoint": "api.rollbar.com/api/1/item/",
|
|
100
|
-
"browser": {
|
|
101
|
-
"scrubFields": [
|
|
102
|
-
"pw",
|
|
103
|
-
"pass",
|
|
104
|
-
"passwd",
|
|
105
|
-
"password",
|
|
106
|
-
"secret",
|
|
107
|
-
"confirm_password",
|
|
108
|
-
"confirmPassword",
|
|
109
|
-
"password_confirmation",
|
|
110
|
-
"passwordConfirmation",
|
|
111
|
-
"access_token",
|
|
112
|
-
"accessToken",
|
|
113
|
-
"X-Rollbar-Access-Token",
|
|
114
|
-
"secret_key",
|
|
115
|
-
"secretKey",
|
|
116
|
-
"secretToken",
|
|
117
|
-
"cc-number",
|
|
118
|
-
"card number",
|
|
119
|
-
"cardnumber",
|
|
120
|
-
"cardnum",
|
|
121
|
-
"ccnum",
|
|
122
|
-
"ccnumber",
|
|
123
|
-
"cc num",
|
|
124
|
-
"creditcardnumber",
|
|
125
|
-
"credit card number",
|
|
126
|
-
"newcreditcardnumber",
|
|
127
|
-
"new credit card",
|
|
128
|
-
"creditcardno",
|
|
129
|
-
"credit card no",
|
|
130
|
-
"card#",
|
|
131
|
-
"card #",
|
|
132
|
-
"cc-csc",
|
|
133
|
-
"cvc",
|
|
134
|
-
"cvc2",
|
|
135
|
-
"cvv2",
|
|
136
|
-
"ccv2",
|
|
137
|
-
"security code",
|
|
138
|
-
"card verification",
|
|
139
|
-
"name on credit card",
|
|
140
|
-
"name on card",
|
|
141
|
-
"nameoncard",
|
|
142
|
-
"cardholder",
|
|
143
|
-
"card holder",
|
|
144
|
-
"name des karteninhabers",
|
|
145
|
-
"ccname",
|
|
146
|
-
"card type",
|
|
147
|
-
"cardtype",
|
|
148
|
-
"cc type",
|
|
149
|
-
"cctype",
|
|
150
|
-
"payment type",
|
|
151
|
-
"expiration date",
|
|
152
|
-
"expirationdate",
|
|
153
|
-
"expdate",
|
|
154
|
-
"cc-exp",
|
|
155
|
-
"ccmonth",
|
|
156
|
-
"ccyear"
|
|
157
|
-
]
|
|
158
|
-
},
|
|
159
98
|
"server": {
|
|
160
99
|
"scrubHeaders": [
|
|
161
100
|
"authorization",
|
package/src/api.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
var _ = require('./utility');
|
|
2
2
|
var helpers = require('./apiUtility');
|
|
3
|
-
var truncation = require('./truncation');
|
|
4
3
|
|
|
5
4
|
var defaultOptions = {
|
|
6
5
|
hostname: 'api.rollbar.com',
|
|
@@ -30,13 +29,14 @@ var defaultOptions = {
|
|
|
30
29
|
* protocol (optional): https
|
|
31
30
|
* }
|
|
32
31
|
*/
|
|
33
|
-
function Api(options,
|
|
32
|
+
function Api(options, transport, urllib, truncation, jsonBackup) {
|
|
34
33
|
this.options = options;
|
|
35
|
-
this.transport =
|
|
36
|
-
this.url =
|
|
37
|
-
this.
|
|
34
|
+
this.transport = transport;
|
|
35
|
+
this.url = urllib;
|
|
36
|
+
this.truncation = truncation;
|
|
37
|
+
this.jsonBackup = jsonBackup;
|
|
38
38
|
this.accessToken = options.accessToken;
|
|
39
|
-
this.transportOptions = _getTransport(options,
|
|
39
|
+
this.transportOptions = _getTransport(options, urllib);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -58,7 +58,13 @@ Api.prototype.postItem = function(data, callback) {
|
|
|
58
58
|
Api.prototype.buildJsonPayload = function(data, callback) {
|
|
59
59
|
var payload = helpers.buildPayload(this.accessToken, data, this.jsonBackup);
|
|
60
60
|
|
|
61
|
-
var stringifyResult
|
|
61
|
+
var stringifyResult;
|
|
62
|
+
if (this.truncation) {
|
|
63
|
+
stringifyResult = this.truncation.truncate(payload);
|
|
64
|
+
} else {
|
|
65
|
+
stringifyResult = _.stringify(payload)
|
|
66
|
+
}
|
|
67
|
+
|
|
62
68
|
if (stringifyResult.error) {
|
|
63
69
|
if (callback) {
|
|
64
70
|
callback(stringifyResult.error);
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
var Client = require('../rollbar');
|
|
2
|
+
var _ = require('../utility');
|
|
3
|
+
var API = require('../api');
|
|
4
|
+
var logger = require('./logger');
|
|
5
|
+
var globals = require('./globalSetup');
|
|
6
|
+
|
|
7
|
+
var Transport = require('./transport');
|
|
8
|
+
var urllib = require('./url');
|
|
9
|
+
|
|
10
|
+
var transforms = require('./transforms');
|
|
11
|
+
var sharedTransforms = require('../transforms');
|
|
12
|
+
var predicates = require('./predicates');
|
|
13
|
+
var sharedPredicates = require('../predicates');
|
|
14
|
+
var errorParser = require('../errorParser');
|
|
15
|
+
|
|
16
|
+
function Rollbar(options, client) {
|
|
17
|
+
this.options = _.handleOptions(defaultOptions, options);
|
|
18
|
+
this.options._configuredOptions = options;
|
|
19
|
+
var Telemeter = this.components.telemeter;
|
|
20
|
+
var Instrumenter = this.components.instrumenter;
|
|
21
|
+
var polyfillJSON = this.components.polyfillJSON;
|
|
22
|
+
this.wrapGlobals = this.components.wrapGlobals;
|
|
23
|
+
this.scrub = this.components.scrub;
|
|
24
|
+
var truncation = this.components.truncation;
|
|
25
|
+
|
|
26
|
+
var transport = new Transport(truncation);
|
|
27
|
+
var api = new API(this.options, transport, urllib, truncation);
|
|
28
|
+
if (Telemeter) {
|
|
29
|
+
this.telemeter = new Telemeter(this.options);
|
|
30
|
+
}
|
|
31
|
+
this.client = client || new Client(this.options, api, logger, this.telemeter, 'browser');
|
|
32
|
+
var gWindow = _gWindow();
|
|
33
|
+
var gDocument = (typeof document != 'undefined') && document;
|
|
34
|
+
this.isChrome = gWindow.chrome && gWindow.chrome.runtime; // check .runtime to avoid Edge browsers
|
|
35
|
+
this.anonymousErrorsPending = 0;
|
|
36
|
+
addTransformsToNotifier(this.client.notifier, this, gWindow);
|
|
37
|
+
addPredicatesToQueue(this.client.queue);
|
|
38
|
+
this.setupUnhandledCapture();
|
|
39
|
+
if (Instrumenter) {
|
|
40
|
+
this.instrumenter = new Instrumenter(this.options, this.client.telemeter, this, gWindow, gDocument);
|
|
41
|
+
this.instrumenter.instrument();
|
|
42
|
+
}
|
|
43
|
+
_.setupJSON(polyfillJSON);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var _instance = null;
|
|
47
|
+
Rollbar.init = function(options, client) {
|
|
48
|
+
if (_instance) {
|
|
49
|
+
return _instance.global(options).configure(options);
|
|
50
|
+
}
|
|
51
|
+
_instance = new Rollbar(options, client);
|
|
52
|
+
return _instance;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Rollbar.prototype.components = {};
|
|
56
|
+
|
|
57
|
+
Rollbar.setComponents = function(components) {
|
|
58
|
+
Rollbar.prototype.components = components;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function handleUninitialized(maybeCallback) {
|
|
62
|
+
var message = 'Rollbar is not initialized';
|
|
63
|
+
logger.error(message);
|
|
64
|
+
if (maybeCallback) {
|
|
65
|
+
maybeCallback(new Error(message));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Rollbar.prototype.global = function(options) {
|
|
70
|
+
this.client.global(options);
|
|
71
|
+
return this;
|
|
72
|
+
};
|
|
73
|
+
Rollbar.global = function(options) {
|
|
74
|
+
if (_instance) {
|
|
75
|
+
return _instance.global(options);
|
|
76
|
+
} else {
|
|
77
|
+
handleUninitialized();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
Rollbar.prototype.configure = function(options, payloadData) {
|
|
82
|
+
var oldOptions = this.options;
|
|
83
|
+
var payload = {};
|
|
84
|
+
if (payloadData) {
|
|
85
|
+
payload = {payload: payloadData};
|
|
86
|
+
}
|
|
87
|
+
this.options = _.handleOptions(oldOptions, options, payload);
|
|
88
|
+
this.options._configuredOptions = _.handleOptions(oldOptions._configuredOptions, options, payload);
|
|
89
|
+
this.client.configure(this.options, payloadData);
|
|
90
|
+
this.instrumenter && this.instrumenter.configure(this.options);
|
|
91
|
+
this.setupUnhandledCapture();
|
|
92
|
+
return this;
|
|
93
|
+
};
|
|
94
|
+
Rollbar.configure = function(options, payloadData) {
|
|
95
|
+
if (_instance) {
|
|
96
|
+
return _instance.configure(options, payloadData);
|
|
97
|
+
} else {
|
|
98
|
+
handleUninitialized();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
Rollbar.prototype.lastError = function() {
|
|
103
|
+
return this.client.lastError;
|
|
104
|
+
};
|
|
105
|
+
Rollbar.lastError = function() {
|
|
106
|
+
if (_instance) {
|
|
107
|
+
return _instance.lastError();
|
|
108
|
+
} else {
|
|
109
|
+
handleUninitialized();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
Rollbar.prototype.log = function() {
|
|
114
|
+
var item = this._createItem(arguments);
|
|
115
|
+
var uuid = item.uuid;
|
|
116
|
+
this.client.log(item);
|
|
117
|
+
return {uuid: uuid};
|
|
118
|
+
};
|
|
119
|
+
Rollbar.log = function() {
|
|
120
|
+
if (_instance) {
|
|
121
|
+
return _instance.log.apply(_instance, arguments);
|
|
122
|
+
} else {
|
|
123
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
124
|
+
handleUninitialized(maybeCallback);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
Rollbar.prototype.debug = function() {
|
|
129
|
+
var item = this._createItem(arguments);
|
|
130
|
+
var uuid = item.uuid;
|
|
131
|
+
this.client.debug(item);
|
|
132
|
+
return {uuid: uuid};
|
|
133
|
+
};
|
|
134
|
+
Rollbar.debug = function() {
|
|
135
|
+
if (_instance) {
|
|
136
|
+
return _instance.debug.apply(_instance, arguments);
|
|
137
|
+
} else {
|
|
138
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
139
|
+
handleUninitialized(maybeCallback);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
Rollbar.prototype.info = function() {
|
|
144
|
+
var item = this._createItem(arguments);
|
|
145
|
+
var uuid = item.uuid;
|
|
146
|
+
this.client.info(item);
|
|
147
|
+
return {uuid: uuid};
|
|
148
|
+
};
|
|
149
|
+
Rollbar.info = function() {
|
|
150
|
+
if (_instance) {
|
|
151
|
+
return _instance.info.apply(_instance, arguments);
|
|
152
|
+
} else {
|
|
153
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
154
|
+
handleUninitialized(maybeCallback);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
Rollbar.prototype.warn = function() {
|
|
159
|
+
var item = this._createItem(arguments);
|
|
160
|
+
var uuid = item.uuid;
|
|
161
|
+
this.client.warn(item);
|
|
162
|
+
return {uuid: uuid};
|
|
163
|
+
};
|
|
164
|
+
Rollbar.warn = function() {
|
|
165
|
+
if (_instance) {
|
|
166
|
+
return _instance.warn.apply(_instance, arguments);
|
|
167
|
+
} else {
|
|
168
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
169
|
+
handleUninitialized(maybeCallback);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Rollbar.prototype.warning = function() {
|
|
174
|
+
var item = this._createItem(arguments);
|
|
175
|
+
var uuid = item.uuid;
|
|
176
|
+
this.client.warning(item);
|
|
177
|
+
return {uuid: uuid};
|
|
178
|
+
};
|
|
179
|
+
Rollbar.warning = function() {
|
|
180
|
+
if (_instance) {
|
|
181
|
+
return _instance.warning.apply(_instance, arguments);
|
|
182
|
+
} else {
|
|
183
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
184
|
+
handleUninitialized(maybeCallback);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
Rollbar.prototype.error = function() {
|
|
189
|
+
var item = this._createItem(arguments);
|
|
190
|
+
var uuid = item.uuid;
|
|
191
|
+
this.client.error(item);
|
|
192
|
+
return {uuid: uuid};
|
|
193
|
+
};
|
|
194
|
+
Rollbar.error = function() {
|
|
195
|
+
if (_instance) {
|
|
196
|
+
return _instance.error.apply(_instance, arguments);
|
|
197
|
+
} else {
|
|
198
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
199
|
+
handleUninitialized(maybeCallback);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
Rollbar.prototype.critical = function() {
|
|
204
|
+
var item = this._createItem(arguments);
|
|
205
|
+
var uuid = item.uuid;
|
|
206
|
+
this.client.critical(item);
|
|
207
|
+
return {uuid: uuid};
|
|
208
|
+
};
|
|
209
|
+
Rollbar.critical = function() {
|
|
210
|
+
if (_instance) {
|
|
211
|
+
return _instance.critical.apply(_instance, arguments);
|
|
212
|
+
} else {
|
|
213
|
+
var maybeCallback = _getFirstFunction(arguments);
|
|
214
|
+
handleUninitialized(maybeCallback);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
Rollbar.prototype.buildJsonPayload = function(item) {
|
|
219
|
+
return this.client.buildJsonPayload(item);
|
|
220
|
+
};
|
|
221
|
+
Rollbar.buildJsonPayload = function() {
|
|
222
|
+
if (_instance) {
|
|
223
|
+
return _instance.buildJsonPayload.apply(_instance, arguments);
|
|
224
|
+
} else {
|
|
225
|
+
handleUninitialized();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
Rollbar.prototype.sendJsonPayload = function(jsonPayload) {
|
|
230
|
+
return this.client.sendJsonPayload(jsonPayload);
|
|
231
|
+
};
|
|
232
|
+
Rollbar.sendJsonPayload = function() {
|
|
233
|
+
if (_instance) {
|
|
234
|
+
return _instance.sendJsonPayload.apply(_instance, arguments);
|
|
235
|
+
} else {
|
|
236
|
+
handleUninitialized();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
Rollbar.prototype.setupUnhandledCapture = function() {
|
|
241
|
+
var gWindow = _gWindow();
|
|
242
|
+
|
|
243
|
+
if (!this.unhandledExceptionsInitialized) {
|
|
244
|
+
if (this.options.captureUncaught || this.options.handleUncaughtExceptions) {
|
|
245
|
+
globals.captureUncaughtExceptions(gWindow, this);
|
|
246
|
+
if (this.wrapGlobals && this.options.wrapGlobalEventHandlers) {
|
|
247
|
+
this.wrapGlobals(gWindow, this);
|
|
248
|
+
}
|
|
249
|
+
this.unhandledExceptionsInitialized = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (!this.unhandledRejectionsInitialized) {
|
|
253
|
+
if (this.options.captureUnhandledRejections || this.options.handleUnhandledRejections) {
|
|
254
|
+
globals.captureUnhandledRejections(gWindow, this);
|
|
255
|
+
this.unhandledRejectionsInitialized = true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
Rollbar.prototype.handleUncaughtException = function(message, url, lineno, colno, error, context) {
|
|
261
|
+
if (!this.options.captureUncaught && !this.options.handleUncaughtExceptions) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Chrome will always send 5+ arguments and error will be valid or null, not undefined.
|
|
266
|
+
// If error is undefined, we have a different caller.
|
|
267
|
+
if (this.options.inspectAnonymousErrors && this.isChrome && (error === null)) {
|
|
268
|
+
return 'anonymous';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
var item;
|
|
272
|
+
var stackInfo = _.makeUnhandledStackInfo(
|
|
273
|
+
message,
|
|
274
|
+
url,
|
|
275
|
+
lineno,
|
|
276
|
+
colno,
|
|
277
|
+
error,
|
|
278
|
+
'onerror',
|
|
279
|
+
'uncaught exception',
|
|
280
|
+
errorParser
|
|
281
|
+
);
|
|
282
|
+
if (_.isError(error)) {
|
|
283
|
+
item = this._createItem([message, error, context]);
|
|
284
|
+
item._unhandledStackInfo = stackInfo;
|
|
285
|
+
} else if (_.isError(url)) {
|
|
286
|
+
item = this._createItem([message, url, context]);
|
|
287
|
+
item._unhandledStackInfo = stackInfo;
|
|
288
|
+
} else {
|
|
289
|
+
item = this._createItem([message, context]);
|
|
290
|
+
item.stackInfo = stackInfo;
|
|
291
|
+
}
|
|
292
|
+
item.level = this.options.uncaughtErrorLevel;
|
|
293
|
+
item._isUncaught = true;
|
|
294
|
+
this.client.log(item);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Chrome only. Other browsers will ignore.
|
|
299
|
+
*
|
|
300
|
+
* Use Error.prepareStackTrace to extract information about errors that
|
|
301
|
+
* do not have a valid error object in onerror().
|
|
302
|
+
*
|
|
303
|
+
* In tested version of Chrome, onerror is called first but has no way
|
|
304
|
+
* to communicate with prepareStackTrace. Use a counter to let this
|
|
305
|
+
* handler know which errors to send to Rollbar.
|
|
306
|
+
*
|
|
307
|
+
* In config options, set inspectAnonymousErrors to enable.
|
|
308
|
+
*/
|
|
309
|
+
Rollbar.prototype.handleAnonymousErrors = function() {
|
|
310
|
+
if (!this.options.inspectAnonymousErrors || !this.isChrome) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
var r = this;
|
|
315
|
+
function prepareStackTrace(error, _stack) { // eslint-disable-line no-unused-vars
|
|
316
|
+
if (r.options.inspectAnonymousErrors) {
|
|
317
|
+
if (r.anonymousErrorsPending) {
|
|
318
|
+
// This is the only known way to detect that onerror saw an anonymous error.
|
|
319
|
+
// It depends on onerror reliably being called before Error.prepareStackTrace,
|
|
320
|
+
// which so far holds true on tested versions of Chrome. If versions of Chrome
|
|
321
|
+
// are tested that behave differently, this logic will need to be updated
|
|
322
|
+
// accordingly.
|
|
323
|
+
r.anonymousErrorsPending -= 1;
|
|
324
|
+
|
|
325
|
+
if (!error) {
|
|
326
|
+
// Not likely to get here, but calling handleUncaughtException from here
|
|
327
|
+
// without an error object would throw off the anonymousErrorsPending counter,
|
|
328
|
+
// so return now.
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Allow this to be tracked later.
|
|
333
|
+
error._isAnonymous = true;
|
|
334
|
+
|
|
335
|
+
// url, lineno, colno shouldn't be needed for these errors.
|
|
336
|
+
// If that changes, update this accordingly, using the unused
|
|
337
|
+
// _stack param as needed (rather than parse error.toString()).
|
|
338
|
+
r.handleUncaughtException(error.message, null, null, null, error);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Workaround to ensure stack is preserved for normal errors.
|
|
343
|
+
return error.stack;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// https://v8.dev/docs/stack-trace-api
|
|
347
|
+
try {
|
|
348
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
349
|
+
} catch (e) {
|
|
350
|
+
this.options.inspectAnonymousErrors = false;
|
|
351
|
+
this.error('anonymous error handler failed', e);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
Rollbar.prototype.handleUnhandledRejection = function(reason, promise) {
|
|
356
|
+
if (!this.options.captureUnhandledRejections && !this.options.handleUnhandledRejections) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
var message = 'unhandled rejection was null or undefined!';
|
|
361
|
+
if (reason) {
|
|
362
|
+
if (reason.message) {
|
|
363
|
+
message = reason.message;
|
|
364
|
+
} else {
|
|
365
|
+
var reasonResult = _.stringify(reason);
|
|
366
|
+
if (reasonResult.value) {
|
|
367
|
+
message = reasonResult.value;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
var context = (reason && reason._rollbarContext) || (promise && promise._rollbarContext);
|
|
372
|
+
|
|
373
|
+
var item;
|
|
374
|
+
if (_.isError(reason)) {
|
|
375
|
+
item = this._createItem([message, reason, context]);
|
|
376
|
+
} else {
|
|
377
|
+
item = this._createItem([message, reason, context]);
|
|
378
|
+
item.stackInfo = _.makeUnhandledStackInfo(
|
|
379
|
+
message,
|
|
380
|
+
'',
|
|
381
|
+
0,
|
|
382
|
+
0,
|
|
383
|
+
null,
|
|
384
|
+
'unhandledrejection',
|
|
385
|
+
'',
|
|
386
|
+
errorParser
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
item.level = this.options.uncaughtErrorLevel;
|
|
390
|
+
item._isUncaught = true;
|
|
391
|
+
item._originalArgs = item._originalArgs || [];
|
|
392
|
+
item._originalArgs.push(promise);
|
|
393
|
+
this.client.log(item);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
Rollbar.prototype.wrap = function(f, context, _before) {
|
|
397
|
+
try {
|
|
398
|
+
var ctxFn;
|
|
399
|
+
if(_.isFunction(context)) {
|
|
400
|
+
ctxFn = context;
|
|
401
|
+
} else {
|
|
402
|
+
ctxFn = function() { return context || {}; };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (!_.isFunction(f)) {
|
|
406
|
+
return f;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (f._isWrap) {
|
|
410
|
+
return f;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (!f._rollbar_wrapped) {
|
|
414
|
+
f._rollbar_wrapped = function () {
|
|
415
|
+
if (_before && _.isFunction(_before)) {
|
|
416
|
+
_before.apply(this, arguments);
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
return f.apply(this, arguments);
|
|
420
|
+
} catch(exc) {
|
|
421
|
+
var e = exc;
|
|
422
|
+
if (e && window._rollbarWrappedError !== e) {
|
|
423
|
+
if (_.isType(e, 'string')) {
|
|
424
|
+
e = new String(e);
|
|
425
|
+
}
|
|
426
|
+
e._rollbarContext = ctxFn() || {};
|
|
427
|
+
e._rollbarContext._wrappedSource = f.toString();
|
|
428
|
+
|
|
429
|
+
window._rollbarWrappedError = e;
|
|
430
|
+
}
|
|
431
|
+
throw e;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
f._rollbar_wrapped._isWrap = true;
|
|
436
|
+
|
|
437
|
+
if (f.hasOwnProperty) {
|
|
438
|
+
for (var prop in f) {
|
|
439
|
+
if (f.hasOwnProperty(prop) && prop !== '_rollbar_wrapped') {
|
|
440
|
+
f._rollbar_wrapped[prop] = f[prop];
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return f._rollbar_wrapped;
|
|
447
|
+
} catch (e) {
|
|
448
|
+
// Return the original function if the wrap fails.
|
|
449
|
+
return f;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
Rollbar.wrap = function(f, context) {
|
|
453
|
+
if (_instance) {
|
|
454
|
+
return _instance.wrap(f, context);
|
|
455
|
+
} else {
|
|
456
|
+
handleUninitialized();
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
Rollbar.prototype.captureEvent = function() {
|
|
461
|
+
var event = _.createTelemetryEvent(arguments);
|
|
462
|
+
return this.client.captureEvent(event.type, event.metadata, event.level);
|
|
463
|
+
};
|
|
464
|
+
Rollbar.captureEvent = function() {
|
|
465
|
+
if (_instance) {
|
|
466
|
+
return _instance.captureEvent.apply(_instance, arguments);
|
|
467
|
+
} else {
|
|
468
|
+
handleUninitialized();
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
// The following two methods are used internally and are not meant for public use
|
|
473
|
+
Rollbar.prototype.captureDomContentLoaded = function(e, ts) {
|
|
474
|
+
if (!ts) {
|
|
475
|
+
ts = new Date();
|
|
476
|
+
}
|
|
477
|
+
return this.client.captureDomContentLoaded(ts);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
Rollbar.prototype.captureLoad = function(e, ts) {
|
|
481
|
+
if (!ts) {
|
|
482
|
+
ts = new Date();
|
|
483
|
+
}
|
|
484
|
+
return this.client.captureLoad(ts);
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
/* Internal */
|
|
488
|
+
|
|
489
|
+
function addTransformsToNotifier(notifier, rollbar, gWindow) {
|
|
490
|
+
notifier
|
|
491
|
+
.addTransform(transforms.handleDomException)
|
|
492
|
+
.addTransform(transforms.handleItemWithError)
|
|
493
|
+
.addTransform(transforms.ensureItemHasSomethingToSay)
|
|
494
|
+
.addTransform(transforms.addBaseInfo)
|
|
495
|
+
.addTransform(transforms.addRequestInfo(gWindow))
|
|
496
|
+
.addTransform(transforms.addClientInfo(gWindow))
|
|
497
|
+
.addTransform(transforms.addPluginInfo(gWindow))
|
|
498
|
+
.addTransform(transforms.addBody)
|
|
499
|
+
.addTransform(sharedTransforms.addMessageWithError)
|
|
500
|
+
.addTransform(sharedTransforms.addTelemetryData)
|
|
501
|
+
.addTransform(sharedTransforms.addConfigToPayload)
|
|
502
|
+
.addTransform(transforms.addScrubber(rollbar.scrub))
|
|
503
|
+
.addTransform(sharedTransforms.userTransform(logger))
|
|
504
|
+
.addTransform(sharedTransforms.addConfiguredOptions)
|
|
505
|
+
.addTransform(sharedTransforms.addDiagnosticKeys)
|
|
506
|
+
.addTransform(sharedTransforms.itemToPayload);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function addPredicatesToQueue(queue) {
|
|
510
|
+
queue
|
|
511
|
+
.addPredicate(sharedPredicates.checkLevel)
|
|
512
|
+
.addPredicate(predicates.checkIgnore)
|
|
513
|
+
.addPredicate(sharedPredicates.userCheckIgnore(logger))
|
|
514
|
+
.addPredicate(sharedPredicates.urlIsNotBlacklisted(logger))
|
|
515
|
+
.addPredicate(sharedPredicates.urlIsWhitelisted(logger))
|
|
516
|
+
.addPredicate(sharedPredicates.messageIsIgnored(logger));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
Rollbar.prototype.loadFull = function() {
|
|
520
|
+
logger.info('Unexpected Rollbar.loadFull() called on a Notifier instance. This can happen when Rollbar is loaded multiple times.');
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
Rollbar.prototype._createItem = function(args) {
|
|
524
|
+
return _.createItem(args, logger, this);
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
function _getFirstFunction(args) {
|
|
528
|
+
for (var i = 0, len = args.length; i < len; ++i) {
|
|
529
|
+
if (_.isFunction(args[i])) {
|
|
530
|
+
return args[i];
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function _gWindow() {
|
|
537
|
+
return ((typeof window != 'undefined') && window) || ((typeof self != 'undefined') && self);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
var defaults = require('../defaults');
|
|
541
|
+
var scrubFields = require('./defaults/scrubFields');
|
|
542
|
+
|
|
543
|
+
var defaultOptions = {
|
|
544
|
+
version: defaults.version,
|
|
545
|
+
scrubFields: scrubFields.scrubFields,
|
|
546
|
+
logLevel: defaults.logLevel,
|
|
547
|
+
reportLevel: defaults.reportLevel,
|
|
548
|
+
uncaughtErrorLevel: defaults.uncaughtErrorLevel,
|
|
549
|
+
endpoint: defaults.endpoint,
|
|
550
|
+
verbose: false,
|
|
551
|
+
enabled: true,
|
|
552
|
+
transmit: true,
|
|
553
|
+
sendConfig: false,
|
|
554
|
+
includeItemsInTelemetry: true,
|
|
555
|
+
captureIp: true,
|
|
556
|
+
inspectAnonymousErrors: true,
|
|
557
|
+
ignoreDuplicateErrors: true,
|
|
558
|
+
wrapGlobalEventHandlers: false
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
module.exports = Rollbar;
|