rollbar 3.0.0-beta.5 → 3.0.0
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/.git-blame-ignore-revs +3 -1
- package/AGENTS.md +21 -0
- package/CONTRIBUTING.md +68 -73
- package/babel.config.json +7 -0
- package/bower.json +1 -1
- package/dist/plugins/jquery.min.js +1 -1
- package/dist/rollbar.cjs +2216 -2022
- package/dist/rollbar.js +6098 -5886
- package/dist/rollbar.js.map +1 -1
- package/dist/rollbar.min.cjs +1 -1
- package/dist/rollbar.min.cjs.LICENSE.txt +1 -1
- package/dist/rollbar.min.js +1 -1
- package/dist/rollbar.min.js.LICENSE.txt +1 -1
- package/dist/rollbar.min.js.map +1 -1
- package/dist/rollbar.named-amd.js +6097 -5886
- 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.LICENSE.txt +1 -1
- package/dist/rollbar.named-amd.min.js.map +1 -1
- package/dist/rollbar.noconflict.umd.js +6097 -5886
- 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.LICENSE.txt +1 -1
- package/dist/rollbar.noconflict.umd.min.js.map +1 -1
- package/dist/rollbar.replay.js +8123 -7924
- package/dist/rollbar.replay.js.map +1 -1
- package/dist/rollbar.replay.min.js +1 -1
- package/dist/rollbar.replay.min.js.LICENSE.txt +1 -1
- package/dist/rollbar.replay.min.js.map +1 -1
- package/dist/rollbar.replay.noconflict.umd.js +8122 -7924
- package/dist/rollbar.replay.noconflict.umd.js.map +1 -1
- package/dist/rollbar.replay.noconflict.umd.min.js +1 -1
- package/dist/rollbar.replay.noconflict.umd.min.js.LICENSE.txt +1 -1
- package/dist/rollbar.replay.noconflict.umd.min.js.map +1 -1
- package/dist/rollbar.replay.umd.js +8122 -7924
- package/dist/rollbar.replay.umd.js.map +1 -1
- package/dist/rollbar.replay.umd.min.js +1 -1
- package/dist/rollbar.replay.umd.min.js.LICENSE.txt +1 -1
- package/dist/rollbar.replay.umd.min.js.map +1 -1
- package/dist/rollbar.snippet.js +1 -1
- package/dist/rollbar.umd.js +6097 -5886
- package/dist/rollbar.umd.js.map +1 -1
- package/dist/rollbar.umd.min.js +1 -1
- package/dist/rollbar.umd.min.js.LICENSE.txt +1 -1
- package/dist/rollbar.umd.min.js.map +1 -1
- package/eslint.config.js +151 -0
- package/index.d.ts +45 -13
- package/package.json +26 -6
- package/src/api.js +130 -136
- package/src/apiUtility.js +2 -2
- package/src/browser/bundles/rollbar.snippet.js +1 -0
- package/src/browser/core.js +31 -42
- package/src/browser/domUtility.js +11 -17
- package/src/browser/globalSetup.js +3 -3
- package/src/browser/replay/checkoutWatchdog.js +104 -0
- package/src/browser/replay/recorder.d.ts +5 -2
- package/src/browser/replay/recorder.js +22 -4
- package/src/browser/replay/replay.js +8 -4
- package/src/browser/replay/replayPredicates.js +1 -1
- package/src/browser/rollbar.js +5 -4
- package/src/browser/rollbarReplay.js +6 -5
- package/src/browser/rollbarWrapper.js +2 -2
- package/src/browser/shim.js +15 -15
- package/src/browser/telemetry.js +26 -22
- package/src/browser/transforms.js +4 -4
- package/src/browser/transport/xhr.js +4 -4
- package/src/browser/transport.js +9 -10
- package/src/browser/wrapGlobals.js +3 -4
- package/src/defaults.js +1 -1
- package/src/errorParser.js +1 -1
- package/src/logger.js +1 -0
- package/src/notifier.js +102 -100
- package/src/predicates.js +3 -4
- package/src/rateLimiter.js +107 -104
- package/src/react-native/rollbar.js +9 -10
- package/src/react-native/transforms.js +4 -5
- package/src/react-native/transport.js +7 -7
- package/src/rollbar.js +7 -4
- package/src/scrub.js +16 -20
- package/src/server/locals.js +7 -7
- package/src/server/parser.js +9 -6
- package/src/server/rollbar.js +54 -49
- package/src/server/sourceMap/stackTrace.js +7 -6
- package/src/server/telemetry/urlHelpers.js +2 -1
- package/src/server/telemetry.js +10 -10
- package/src/server/transforms.js +10 -6
- package/src/server/transport.js +8 -7
- package/src/telemetry.js +22 -25
- package/src/tracing/tracer.js +2 -2
- package/src/tracing/tracing.js +2 -2
- package/src/truncation.js +6 -6
- package/src/utility/headers.js +4 -2
- package/src/utility/traverse.js +1 -1
- package/src/utility.js +111 -33
- package/tsconfig.json +16 -0
- package/tsconfig.test.json +10 -0
- package/{web-test-runner.config.mjs → web-test-runner.config.js} +10 -0
- package/{webpack.config.cjs → webpack.config.js} +39 -27
- package/.eslintrc +0 -27
- package/eslint.config.mjs +0 -33
- package/src/merge.js +0 -61
package/eslint.config.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import babelParser from '@babel/eslint-parser';
|
|
2
|
+
import js from '@eslint/js';
|
|
3
|
+
import { defineConfig } from 'eslint/config';
|
|
4
|
+
import chaiFriendly from 'eslint-plugin-chai-friendly';
|
|
5
|
+
import importPlugin from 'eslint-plugin-import';
|
|
6
|
+
import prettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
7
|
+
import unusedImports from 'eslint-plugin-unused-imports';
|
|
8
|
+
import globals from 'globals';
|
|
9
|
+
import ts from 'typescript-eslint';
|
|
10
|
+
|
|
11
|
+
const noUnusedVarsRule = [
|
|
12
|
+
'error',
|
|
13
|
+
{
|
|
14
|
+
argsIgnorePattern: '^_',
|
|
15
|
+
varsIgnorePattern: '^_',
|
|
16
|
+
caughtErrorsIgnorePattern: '^_',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export default defineConfig(
|
|
21
|
+
js.configs.recommended,
|
|
22
|
+
ts.configs.recommended,
|
|
23
|
+
ts.configs.stylistic,
|
|
24
|
+
prettierRecommended,
|
|
25
|
+
chaiFriendly.configs.recommendedFlat,
|
|
26
|
+
|
|
27
|
+
// all files
|
|
28
|
+
{
|
|
29
|
+
languageOptions: {
|
|
30
|
+
ecmaVersion: 2021,
|
|
31
|
+
sourceType: 'module',
|
|
32
|
+
},
|
|
33
|
+
plugins: {
|
|
34
|
+
import: importPlugin,
|
|
35
|
+
'unused-imports': unusedImports,
|
|
36
|
+
'chai-friendly': chaiFriendly,
|
|
37
|
+
},
|
|
38
|
+
rules: {
|
|
39
|
+
complexity: ['error', { max: 35 }],
|
|
40
|
+
eqeqeq: ['error', 'smart'],
|
|
41
|
+
'no-console': 'error',
|
|
42
|
+
'no-implicit-coercion': 'error',
|
|
43
|
+
'unused-imports/no-unused-imports': 'error',
|
|
44
|
+
'import/order': [
|
|
45
|
+
'warn',
|
|
46
|
+
{
|
|
47
|
+
alphabetize: {
|
|
48
|
+
order: 'asc',
|
|
49
|
+
caseInsensitive: true,
|
|
50
|
+
},
|
|
51
|
+
groups: [
|
|
52
|
+
'builtin',
|
|
53
|
+
'external',
|
|
54
|
+
'internal',
|
|
55
|
+
'parent',
|
|
56
|
+
'sibling',
|
|
57
|
+
'index',
|
|
58
|
+
],
|
|
59
|
+
'newlines-between': 'always',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
'no-unused-vars': noUnusedVarsRule,
|
|
63
|
+
'@typescript-eslint/no-unused-vars': noUnusedVarsRule,
|
|
64
|
+
'@typescript-eslint/no-empty-function': [
|
|
65
|
+
'error',
|
|
66
|
+
{ allow: ['arrowFunctions'] },
|
|
67
|
+
],
|
|
68
|
+
'@typescript-eslint/no-this-alias': [
|
|
69
|
+
'error',
|
|
70
|
+
{ allowDestructuring: true },
|
|
71
|
+
],
|
|
72
|
+
'chai-friendly/no-unused-expressions': [
|
|
73
|
+
'error',
|
|
74
|
+
{ allowShortCircuit: true },
|
|
75
|
+
],
|
|
76
|
+
|
|
77
|
+
// disabled for now
|
|
78
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
79
|
+
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-nocheck': false }],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// globals
|
|
84
|
+
{
|
|
85
|
+
files: ['test/**/*.[tj]s'],
|
|
86
|
+
languageOptions: { globals: { ...globals.mocha } },
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
files: ['src/**/*.[tj]s', 'test/**/*.[tj]s'],
|
|
90
|
+
languageOptions: { globals: { ...globals.browser } },
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
files: [
|
|
94
|
+
'src/server/**/*.[tj]s',
|
|
95
|
+
'src/react-native/**/*.[tj]s',
|
|
96
|
+
'test/**/server.*.[tj]s',
|
|
97
|
+
'scripts/**/*.[tj]s',
|
|
98
|
+
],
|
|
99
|
+
languageOptions: { globals: { ...globals.node } },
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
// js
|
|
103
|
+
{
|
|
104
|
+
files: ['**/*.js'],
|
|
105
|
+
languageOptions: {
|
|
106
|
+
sourceType: 'module',
|
|
107
|
+
parser: babelParser,
|
|
108
|
+
parserOptions: {
|
|
109
|
+
ecmaVersion: 2021,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
rules: {
|
|
113
|
+
strict: ['error', 'safe'],
|
|
114
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
// ts
|
|
119
|
+
{
|
|
120
|
+
files: ['**/*.ts'],
|
|
121
|
+
rules: {
|
|
122
|
+
'no-unused-vars': 'off',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
// cjs
|
|
127
|
+
{
|
|
128
|
+
files: ['**/*.cjs'],
|
|
129
|
+
languageOptions: { sourceType: 'commonjs' },
|
|
130
|
+
rules: {
|
|
131
|
+
strict: 'off',
|
|
132
|
+
'@typescript-eslint/no-require-imports': 'off',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// tests
|
|
137
|
+
{
|
|
138
|
+
files: ['test/**/*.[tj]s'],
|
|
139
|
+
rules: { '@typescript-eslint/no-empty-function': 'off' },
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// scripts
|
|
143
|
+
{
|
|
144
|
+
files: ['scripts/**/*.{js,cjs}'],
|
|
145
|
+
rules: { 'no-console': 'off' },
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
ignores: ['dist', 'examples', 'node_modules', 'vendor', 'coverage'],
|
|
150
|
+
},
|
|
151
|
+
);
|
package/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
export default Rollbar;
|
|
5
5
|
|
|
6
|
-
declare class Rollbar {
|
|
7
|
-
constructor(options?: Rollbar.Configuration);
|
|
6
|
+
declare class Rollbar implements Rollbar.Components {
|
|
7
|
+
constructor(options?: Rollbar.Configuration, client?: Rollbar);
|
|
8
8
|
static init(options: Rollbar.Configuration): Rollbar;
|
|
9
9
|
static setComponents(components: Rollbar.Components): void;
|
|
10
10
|
|
|
@@ -34,12 +34,30 @@ declare class Rollbar {
|
|
|
34
34
|
|
|
35
35
|
public errorHandler(): Rollbar.ExpressErrorHandler;
|
|
36
36
|
|
|
37
|
+
// Components
|
|
38
|
+
|
|
39
|
+
public telemeter?: TelemeterType;
|
|
40
|
+
public instrumenter?: InstrumenterType;
|
|
41
|
+
public wrapGlobals?: WrapGlobalsType;
|
|
42
|
+
public scrub?: ScrubType;
|
|
43
|
+
public truncation?: TruncationType;
|
|
44
|
+
public tracing?: TracingType;
|
|
45
|
+
/**
|
|
46
|
+
* Replay component for session recording.
|
|
47
|
+
* Only available when using replay bundles (rollbar.replay.*).
|
|
48
|
+
* Use `import Rollbar from 'rollbar/replay'` to access.
|
|
49
|
+
*/
|
|
50
|
+
public replay?: ReplayType;
|
|
51
|
+
|
|
37
52
|
// Used with rollbar-react for rollbar-react-native compatibility.
|
|
38
53
|
public rollbar: Rollbar;
|
|
39
54
|
|
|
40
55
|
// Exposed only for testing, should be changed via the configure method
|
|
41
56
|
// DO NOT MODIFY DIRECTLY
|
|
42
57
|
public options: Rollbar.Configuration;
|
|
58
|
+
|
|
59
|
+
// Exposed only for testing, tracks pending anonymous errors
|
|
60
|
+
anonymousErrorsPending: number;
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
declare namespace Rollbar {
|
|
@@ -48,11 +66,16 @@ declare namespace Rollbar {
|
|
|
48
66
|
context: TContext,
|
|
49
67
|
callback: Callback<TResult>,
|
|
50
68
|
) => void | Promise<TResult>;
|
|
51
|
-
export type MaybeError = Error | undefined | null;
|
|
52
69
|
export type Level = 'debug' | 'info' | 'warning' | 'error' | 'critical';
|
|
53
|
-
export type Dictionary =
|
|
70
|
+
export type Dictionary = Record<string, unknown>;
|
|
71
|
+
export type MaybeError = Error | undefined | null;
|
|
54
72
|
export type StringAttributes = Record<string, string>;
|
|
55
73
|
|
|
74
|
+
export interface ErrorWithContext extends Error {
|
|
75
|
+
rollbarContext?: Record<string, any>;
|
|
76
|
+
nested?: Error | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
56
79
|
/**
|
|
57
80
|
* {@link https://docs.rollbar.com/docs/rollbarjs-configuration-reference#reference}
|
|
58
81
|
*/
|
|
@@ -111,6 +134,7 @@ declare namespace Rollbar {
|
|
|
111
134
|
) => void;
|
|
112
135
|
overwriteScrubFields?: boolean;
|
|
113
136
|
payload?: Payload;
|
|
137
|
+
person?: PersonParams;
|
|
114
138
|
replay?: ReplayOptions;
|
|
115
139
|
reportLevel?: Level;
|
|
116
140
|
resource?: StringAttributes;
|
|
@@ -162,7 +186,11 @@ declare namespace Rollbar {
|
|
|
162
186
|
network?: boolean;
|
|
163
187
|
networkResponseHeaders?: boolean | string[];
|
|
164
188
|
networkResponseBody?: boolean;
|
|
189
|
+
networkRequestHeaders?: boolean;
|
|
165
190
|
networkRequestBody?: boolean;
|
|
191
|
+
networkErrorOnHttp5xx?: boolean;
|
|
192
|
+
networkErrorOnHttp4xx?: boolean;
|
|
193
|
+
networkErrorOnHttp0?: boolean;
|
|
166
194
|
log?: boolean;
|
|
167
195
|
dom?: boolean;
|
|
168
196
|
navigation?: boolean;
|
|
@@ -191,9 +219,7 @@ declare namespace Rollbar {
|
|
|
191
219
|
response: any,
|
|
192
220
|
next: ExpressNextFunction,
|
|
193
221
|
) => any;
|
|
194
|
-
export
|
|
195
|
-
(err?: any): void;
|
|
196
|
-
}
|
|
222
|
+
export type ExpressNextFunction = (err?: any) => void;
|
|
197
223
|
class Locals {}
|
|
198
224
|
export type LocalsType = typeof Locals;
|
|
199
225
|
export type LocalsOptions = LocalsType | LocalsSettings;
|
|
@@ -304,9 +330,20 @@ declare namespace Rollbar {
|
|
|
304
330
|
plugins?: any[];
|
|
305
331
|
}
|
|
306
332
|
|
|
333
|
+
export interface TransformSpanParams {
|
|
334
|
+
span: any;
|
|
335
|
+
}
|
|
307
336
|
export interface TracingOptions {
|
|
308
337
|
enabled?: boolean;
|
|
309
338
|
endpoint?: string;
|
|
339
|
+
transformSpan?: (params: TransformSpanParams) => void;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export interface PersonParams {
|
|
343
|
+
id: string | DeprecatedNumber | null;
|
|
344
|
+
username?: string;
|
|
345
|
+
email?: string;
|
|
346
|
+
[property: string]: any;
|
|
310
347
|
}
|
|
311
348
|
|
|
312
349
|
/**
|
|
@@ -318,12 +355,7 @@ declare namespace Rollbar {
|
|
|
318
355
|
* {@link https://docs.rollbar.com/docs/rollbarjs-configuration-reference#payload-1}
|
|
319
356
|
*/
|
|
320
357
|
export interface Payload {
|
|
321
|
-
person?:
|
|
322
|
-
id: string | DeprecatedNumber | null;
|
|
323
|
-
username?: string;
|
|
324
|
-
email?: string;
|
|
325
|
-
[property: string]: any;
|
|
326
|
-
};
|
|
358
|
+
person?: PersonParams;
|
|
327
359
|
context?: any;
|
|
328
360
|
client?: {
|
|
329
361
|
javascript?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollbar",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -94,6 +94,13 @@
|
|
|
94
94
|
"@babel/core": "^7.26.10",
|
|
95
95
|
"@babel/eslint-parser": "^7.27.0",
|
|
96
96
|
"@babel/preset-env": "^7.26.9",
|
|
97
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
98
|
+
"@types/chai": "^4.3.20",
|
|
99
|
+
"@types/mocha": "^10.0.10",
|
|
100
|
+
"@types/nise": "^1.4.5",
|
|
101
|
+
"@types/node": "^20.17.12",
|
|
102
|
+
"@types/sinon": "^21.0.0",
|
|
103
|
+
"@web/dev-server-esbuild": "^1.0.4",
|
|
97
104
|
"@web/test-runner": "^0.20.2",
|
|
98
105
|
"@web/test-runner-mocha": "^0.9.0",
|
|
99
106
|
"@web/test-runner-playwright": "^0.11.1",
|
|
@@ -101,13 +108,23 @@
|
|
|
101
108
|
"chai": "^5.3.3",
|
|
102
109
|
"es-check": "^9.1.4",
|
|
103
110
|
"eslint": "^9.24.0",
|
|
111
|
+
"eslint-config-prettier": "^10.1.8",
|
|
112
|
+
"eslint-plugin-chai-friendly": "^1.1.0",
|
|
113
|
+
"eslint-plugin-import": "^2.32.0",
|
|
114
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
115
|
+
"eslint-plugin-unused-imports": "^4.3.0",
|
|
104
116
|
"express": "^4.21.2",
|
|
105
117
|
"glob": "^5.0.14",
|
|
118
|
+
"globals": "^16.5.0",
|
|
106
119
|
"mocha": "^11.1.0",
|
|
120
|
+
"nise": "^6.1.1",
|
|
107
121
|
"nock": "^11.9.1",
|
|
108
|
-
"node-libs-browser": "^
|
|
122
|
+
"node-libs-browser": "^2.2.1",
|
|
109
123
|
"prettier": "^3.6.2",
|
|
110
|
-
"sinon": "^
|
|
124
|
+
"sinon": "^21.0.0",
|
|
125
|
+
"ts-node": "^10.9.2",
|
|
126
|
+
"typescript": "^5.9.3",
|
|
127
|
+
"typescript-eslint": "^8.46.4",
|
|
111
128
|
"webpack": "^5.98.0",
|
|
112
129
|
"webpack-cli": "^6.0.1",
|
|
113
130
|
"webpack-node-externals": "^3.0.0"
|
|
@@ -118,14 +135,17 @@
|
|
|
118
135
|
"build:dev": "webpack --mode development",
|
|
119
136
|
"postbuild:dev": "npm run postbuild",
|
|
120
137
|
"test": "npm run test:wtr && npm run test:server",
|
|
121
|
-
"test:server": "
|
|
138
|
+
"test:server": "node scripts/run-server-tests.js",
|
|
122
139
|
"test:wtr": "web-test-runner",
|
|
123
140
|
"test:wtr:watch": "web-test-runner --watch",
|
|
124
|
-
"lint": "
|
|
141
|
+
"lint": "eslint",
|
|
142
|
+
"lint:fix": "eslint --fix",
|
|
125
143
|
"format": "prettier --write \"**/*.{js,cjs,mjs,md,json,yml,yaml}\"",
|
|
126
144
|
"format:check": "prettier --check \"**/*.{js,cjs,mjs,md,json,yml,yaml}\"",
|
|
127
145
|
"pack": "node scripts/pack.js",
|
|
128
|
-
"
|
|
146
|
+
"typecheck": "tsc --noEmit",
|
|
147
|
+
"typecheck:tests": "tsc --noEmit -p tsconfig.test.json",
|
|
148
|
+
"validate": "npm run validate:es5 && npm run validate:examples && npm run typecheck && npm run typecheck:tests",
|
|
129
149
|
"validate:es5": "es-check es5 './dist/**/*.js' --verbose",
|
|
130
150
|
"validate:examples": "node scripts/validate-examples.js -p",
|
|
131
151
|
"update:snippets:examples": "node scripts/update-snippets.js examples"
|
package/src/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _ from './utility.js';
|
|
2
1
|
import * as helpers from './apiUtility.js';
|
|
2
|
+
import { stringify, merge } from './utility.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const defaultOptions = {
|
|
5
5
|
hostname: 'api.rollbar.com',
|
|
6
6
|
path: '/api/1/item/',
|
|
7
7
|
search: null,
|
|
@@ -10,7 +10,7 @@ var defaultOptions = {
|
|
|
10
10
|
port: 443,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const OTLPDefaultOptions = {
|
|
14
14
|
hostname: 'api.rollbar.com',
|
|
15
15
|
path: '/api/1/session/',
|
|
16
16
|
search: null,
|
|
@@ -20,153 +20,147 @@ var OTLPDefaultOptions = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Api
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param options {
|
|
30
|
-
* accessToken: the accessToken to use for posting items to rollbar
|
|
31
|
-
* endpoint: an alternative endpoint to send errors to
|
|
32
|
-
* must be a valid, fully qualified URL.
|
|
33
|
-
* The default is: https://api.rollbar.com/api/1/item
|
|
34
|
-
* proxy: if you wish to proxy requests provide an object
|
|
35
|
-
* with the following keys:
|
|
36
|
-
* host or hostname (required): foo.example.com
|
|
37
|
-
* port (optional): 123
|
|
38
|
-
* protocol (optional): https
|
|
39
|
-
* }
|
|
23
|
+
* Api encapsulates methods of communicating with the Rollbar API. It is a
|
|
24
|
+
* standard interface with some parts implemented differently for server or
|
|
25
|
+
* browser contexts. It is an object that should be instantiated when used so
|
|
26
|
+
* it can contain non-global options that may be different for another instance
|
|
27
|
+
* of RollbarApi.
|
|
40
28
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
29
|
+
class Api {
|
|
30
|
+
/**
|
|
31
|
+
* @param {Object} options - Configuration supplied from the parent Rollbar instance.
|
|
32
|
+
* @param {string} options.accessToken - Token used to authenticate API calls.
|
|
33
|
+
* @param {string} [options.endpoint] - Optional fully qualified URL overriding
|
|
34
|
+
* the default `https://api.rollbar.com/api/1/item`.
|
|
35
|
+
* @param {Object} [options.proxy] - Optional proxy descriptor containing:
|
|
36
|
+
* `host`/`hostname` (required), `port`, and `protocol`.
|
|
37
|
+
* @param {Object} transport - Adapter implementing `post` and `postJsonPayload`.
|
|
38
|
+
* @param {Object} urllib - Minimal URL helper used for option normalization.
|
|
39
|
+
* @param {Object} truncation - Optional truncation helper for payload size enforcement.
|
|
40
|
+
*/
|
|
41
|
+
constructor(options, transport, urllib, truncation) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
this.transport = transport;
|
|
44
|
+
this.url = urllib;
|
|
45
|
+
this.truncation = truncation;
|
|
46
|
+
this.accessToken = options.accessToken;
|
|
47
|
+
this.transportOptions = _getTransport(options, urllib);
|
|
48
|
+
this.OTLPTransportOptions = _getOTLPTransport(options, urllib);
|
|
49
|
+
}
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
accessToken,
|
|
71
|
-
options,
|
|
72
|
-
payload,
|
|
73
|
-
headers,
|
|
74
|
-
callback: (err, resp) => (err ? reject(err) : resolve(resp)),
|
|
51
|
+
/**
|
|
52
|
+
* Wraps transport.post in a Promise to support async/await
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} options - Options for the API request
|
|
55
|
+
* @param {string} options.accessToken - The access token for authentication
|
|
56
|
+
* @param {Object} options.transportOptions - Options for the transport
|
|
57
|
+
* @param {Object} options.payload - The data payload to send
|
|
58
|
+
* @returns {Promise} A promise that resolves with the response or rejects with an error
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
_postPromise({ accessToken, options, payload, headers }) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
this.transport.post({
|
|
64
|
+
accessToken,
|
|
65
|
+
options,
|
|
66
|
+
payload,
|
|
67
|
+
headers,
|
|
68
|
+
callback: (err, resp) => (err ? reject(err) : resolve(resp)),
|
|
69
|
+
});
|
|
75
70
|
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
71
|
+
}
|
|
78
72
|
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param data
|
|
76
|
+
* @param callback
|
|
77
|
+
*/
|
|
78
|
+
postItem(data, callback) {
|
|
79
|
+
const options = helpers.transportOptions(this.transportOptions, 'POST');
|
|
80
|
+
const payload = helpers.buildPayload(data);
|
|
81
|
+
|
|
82
|
+
// ensure the network request is scheduled after the current tick.
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
this.transport.post({
|
|
85
|
+
accessToken: this.accessToken,
|
|
86
|
+
options,
|
|
87
|
+
payload,
|
|
88
|
+
callback,
|
|
89
|
+
});
|
|
90
|
+
}, 0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Posts spans to the Rollbar API using the session endpoint
|
|
95
|
+
*
|
|
96
|
+
* @param {Array} payload - The spans to send
|
|
97
|
+
* @returns {Promise<Object>} A promise that resolves with the API response
|
|
98
|
+
*/
|
|
99
|
+
async postSpans(payload, headers = {}) {
|
|
100
|
+
const options = helpers.transportOptions(this.OTLPTransportOptions, 'POST');
|
|
101
|
+
|
|
102
|
+
return this._postPromise({
|
|
103
|
+
accessToken: this.accessToken,
|
|
93
104
|
options,
|
|
94
105
|
payload,
|
|
95
|
-
|
|
106
|
+
headers,
|
|
96
107
|
});
|
|
97
|
-
}, 0);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Posts spans to the Rollbar API using the session endpoint
|
|
102
|
-
*
|
|
103
|
-
* @param {Array} payload - The spans to send
|
|
104
|
-
* @returns {Promise<Object>} A promise that resolves with the API response
|
|
105
|
-
*/
|
|
106
|
-
Api.prototype.postSpans = async function (payload, headers = {}) {
|
|
107
|
-
const options = helpers.transportOptions(this.OTLPTransportOptions, 'POST');
|
|
108
|
-
|
|
109
|
-
return await this._postPromise({
|
|
110
|
-
accessToken: this.accessToken,
|
|
111
|
-
options,
|
|
112
|
-
payload,
|
|
113
|
-
headers,
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
*
|
|
119
|
-
* @param data
|
|
120
|
-
* @param callback
|
|
121
|
-
*/
|
|
122
|
-
Api.prototype.buildJsonPayload = function (data, callback) {
|
|
123
|
-
var payload = helpers.buildPayload(data);
|
|
124
|
-
|
|
125
|
-
var stringifyResult;
|
|
126
|
-
if (this.truncation) {
|
|
127
|
-
stringifyResult = this.truncation.truncate(payload);
|
|
128
|
-
} else {
|
|
129
|
-
stringifyResult = _.stringify(payload);
|
|
130
108
|
}
|
|
131
109
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* @param data
|
|
113
|
+
* @param callback
|
|
114
|
+
*/
|
|
115
|
+
buildJsonPayload(data, callback) {
|
|
116
|
+
const payload = helpers.buildPayload(data);
|
|
117
|
+
|
|
118
|
+
let stringifyResult;
|
|
119
|
+
if (this.truncation) {
|
|
120
|
+
stringifyResult = this.truncation.truncate(payload);
|
|
121
|
+
} else {
|
|
122
|
+
stringifyResult = stringify(payload);
|
|
135
123
|
}
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
124
|
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
if (stringifyResult.error) {
|
|
126
|
+
if (callback) {
|
|
127
|
+
callback(stringifyResult.error);
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
141
131
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
* @param jsonPayload
|
|
145
|
-
* @param callback
|
|
146
|
-
*/
|
|
147
|
-
Api.prototype.postJsonPayload = function (jsonPayload, callback) {
|
|
148
|
-
var transportOptions = helpers.transportOptions(
|
|
149
|
-
this.transportOptions,
|
|
150
|
-
'POST',
|
|
151
|
-
);
|
|
152
|
-
this.transport.postJsonPayload(
|
|
153
|
-
this.accessToken,
|
|
154
|
-
transportOptions,
|
|
155
|
-
jsonPayload,
|
|
156
|
-
callback,
|
|
157
|
-
);
|
|
158
|
-
};
|
|
132
|
+
return stringifyResult.value;
|
|
133
|
+
}
|
|
159
134
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @param jsonPayload
|
|
138
|
+
* @param callback
|
|
139
|
+
*/
|
|
140
|
+
postJsonPayload(jsonPayload, callback) {
|
|
141
|
+
const transportOptions = helpers.transportOptions(
|
|
142
|
+
this.transportOptions,
|
|
143
|
+
'POST',
|
|
144
|
+
);
|
|
145
|
+
this.transport.postJsonPayload(
|
|
146
|
+
this.accessToken,
|
|
147
|
+
transportOptions,
|
|
148
|
+
jsonPayload,
|
|
149
|
+
callback,
|
|
150
|
+
);
|
|
167
151
|
}
|
|
168
|
-
|
|
169
|
-
|
|
152
|
+
|
|
153
|
+
configure(options) {
|
|
154
|
+
const oldOptions = this.options;
|
|
155
|
+
this.options = merge(oldOptions, options);
|
|
156
|
+
this.transportOptions = _getTransport(this.options, this.url);
|
|
157
|
+
this.OTLPTransportOptions = _getOTLPTransport(this.options, this.url);
|
|
158
|
+
if (this.options.accessToken !== undefined) {
|
|
159
|
+
this.accessToken = this.options.accessToken;
|
|
160
|
+
}
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
170
164
|
|
|
171
165
|
function _getTransport(options, url) {
|
|
172
166
|
return helpers.getTransportFromOptions(options, defaultOptions, url);
|
package/src/apiUtility.js
CHANGED
|
@@ -49,8 +49,8 @@ function getTransportFromOptions(options, defaults, url) {
|
|
|
49
49
|
|
|
50
50
|
function detectTransport(options) {
|
|
51
51
|
var gWindow =
|
|
52
|
-
(typeof window
|
|
53
|
-
(typeof self
|
|
52
|
+
(typeof window !== 'undefined' && window) ||
|
|
53
|
+
(typeof self !== 'undefined' && self);
|
|
54
54
|
var transport = options.defaultTransport || 'xhr';
|
|
55
55
|
if (typeof gWindow.fetch === 'undefined') transport = 'xhr';
|
|
56
56
|
if (typeof gWindow.XMLHttpRequest === 'undefined') transport = 'fetch';
|