@grafana/faro-core 1.0.2 → 1.0.4
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/dist/bundle/faro-core.iife.js +1 -1
- package/dist/cjs/metas/types.js.map +1 -1
- package/dist/cjs/testUtils/mockTransport.js +4 -1
- package/dist/cjs/testUtils/mockTransport.js.map +1 -1
- package/dist/cjs/transports/base.js.map +1 -1
- package/dist/cjs/transports/types.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/metas/types.js.map +1 -1
- package/dist/esm/testUtils/mockTransport.js +3 -1
- package/dist/esm/testUtils/mockTransport.js.map +1 -1
- package/dist/esm/transports/base.js.map +1 -1
- package/dist/esm/transports/types.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/spec/core/src/api/events/index.js +6 -0
- package/dist/spec/core/src/api/events/index.js.map +1 -0
- package/dist/spec/core/src/api/events/initialize.js +44 -0
- package/dist/spec/core/src/api/events/initialize.js.map +1 -0
- package/dist/spec/core/src/api/events/initialize.test.js +86 -0
- package/dist/spec/core/src/api/events/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/events/types.js +3 -0
- package/dist/spec/core/src/api/events/types.js.map +1 -0
- package/dist/spec/core/src/api/exceptions/const.js +5 -0
- package/dist/spec/core/src/api/exceptions/const.js.map +1 -0
- package/dist/spec/core/src/api/exceptions/index.js +8 -0
- package/dist/spec/core/src/api/exceptions/index.js.map +1 -0
- package/dist/spec/core/src/api/exceptions/initialize.js +58 -0
- package/dist/spec/core/src/api/exceptions/initialize.js.map +1 -0
- package/dist/spec/core/src/api/exceptions/initialize.test.js +133 -0
- package/dist/spec/core/src/api/exceptions/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/exceptions/types.js +3 -0
- package/dist/spec/core/src/api/exceptions/types.js.map +1 -0
- package/dist/spec/core/src/api/index.js +8 -0
- package/dist/spec/core/src/api/index.js.map +1 -0
- package/dist/spec/core/src/api/initialize.js +27 -0
- package/dist/spec/core/src/api/initialize.js.map +1 -0
- package/dist/spec/core/src/api/logs/index.js +6 -0
- package/dist/spec/core/src/api/logs/index.js.map +1 -0
- package/dist/spec/core/src/api/logs/initialize.js +54 -0
- package/dist/spec/core/src/api/logs/initialize.js.map +1 -0
- package/dist/spec/core/src/api/logs/initialize.test.js +82 -0
- package/dist/spec/core/src/api/logs/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/logs/types.js +3 -0
- package/dist/spec/core/src/api/logs/types.js.map +1 -0
- package/dist/spec/core/src/api/measurements/index.js +6 -0
- package/dist/spec/core/src/api/measurements/index.js.map +1 -0
- package/dist/spec/core/src/api/measurements/initialize.js +50 -0
- package/dist/spec/core/src/api/measurements/initialize.js.map +1 -0
- package/dist/spec/core/src/api/measurements/initialize.test.js +117 -0
- package/dist/spec/core/src/api/measurements/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/measurements/types.js +3 -0
- package/dist/spec/core/src/api/measurements/types.js.map +1 -0
- package/dist/spec/core/src/api/meta/index.js +6 -0
- package/dist/spec/core/src/api/meta/index.js.map +1 -0
- package/dist/spec/core/src/api/meta/initialize.js +49 -0
- package/dist/spec/core/src/api/meta/initialize.js.map +1 -0
- package/dist/spec/core/src/api/meta/types.js +3 -0
- package/dist/spec/core/src/api/meta/types.js.map +1 -0
- package/dist/spec/core/src/api/traces/index.js +6 -0
- package/dist/spec/core/src/api/traces/index.js.map +1 -0
- package/dist/spec/core/src/api/traces/initialize.js +49 -0
- package/dist/spec/core/src/api/traces/initialize.js.map +1 -0
- package/dist/spec/core/src/api/traces/types.js +3 -0
- package/dist/spec/core/src/api/traces/types.js.map +1 -0
- package/dist/spec/core/src/api/types.js +3 -0
- package/dist/spec/core/src/api/types.js.map +1 -0
- package/dist/spec/core/src/config/const.js +5 -0
- package/dist/spec/core/src/config/const.js.map +1 -0
- package/dist/spec/core/src/config/index.js +6 -0
- package/dist/spec/core/src/config/index.js.map +1 -0
- package/dist/spec/core/src/config/types.js +3 -0
- package/dist/spec/core/src/config/types.js.map +1 -0
- package/dist/spec/core/src/extensions/baseExtension.js +57 -0
- package/dist/spec/core/src/extensions/baseExtension.js.map +1 -0
- package/dist/spec/core/src/extensions/index.js +6 -0
- package/dist/spec/core/src/extensions/index.js.map +1 -0
- package/dist/spec/core/src/extensions/types.js +3 -0
- package/dist/spec/core/src/extensions/types.js.map +1 -0
- package/dist/spec/core/src/faro.test.js +40 -0
- package/dist/spec/core/src/faro.test.js.map +1 -0
- package/dist/spec/core/src/globalObject/globalObject.js +6 -0
- package/dist/spec/core/src/globalObject/globalObject.js.map +1 -0
- package/dist/spec/core/src/globalObject/index.js +6 -0
- package/dist/spec/core/src/globalObject/index.js.map +1 -0
- package/dist/spec/core/src/index.js +75 -0
- package/dist/spec/core/src/index.js.map +1 -0
- package/dist/spec/core/src/initialize.js +32 -0
- package/dist/spec/core/src/initialize.js.map +1 -0
- package/dist/spec/core/src/instrumentations/base.js +31 -0
- package/dist/spec/core/src/instrumentations/base.js.map +1 -0
- package/dist/spec/core/src/instrumentations/index.js +10 -0
- package/dist/spec/core/src/instrumentations/index.js.map +1 -0
- package/dist/spec/core/src/instrumentations/initialize.js +71 -0
- package/dist/spec/core/src/instrumentations/initialize.js.map +1 -0
- package/dist/spec/core/src/instrumentations/registerInitial.js +9 -0
- package/dist/spec/core/src/instrumentations/registerInitial.js.map +1 -0
- package/dist/spec/core/src/instrumentations/types.js +3 -0
- package/dist/spec/core/src/instrumentations/types.js.map +1 -0
- package/dist/spec/core/src/internalLogger/const.js +22 -0
- package/dist/spec/core/src/internalLogger/const.js.map +1 -0
- package/dist/spec/core/src/internalLogger/createInternalLogger.js +65 -0
- package/dist/spec/core/src/internalLogger/createInternalLogger.js.map +1 -0
- package/dist/spec/core/src/internalLogger/index.js +13 -0
- package/dist/spec/core/src/internalLogger/index.js.map +1 -0
- package/dist/spec/core/src/internalLogger/initialize.js +12 -0
- package/dist/spec/core/src/internalLogger/initialize.js.map +1 -0
- package/dist/spec/core/src/internalLogger/types.js +3 -0
- package/dist/spec/core/src/internalLogger/types.js.map +1 -0
- package/dist/spec/core/src/metas/index.js +8 -0
- package/dist/spec/core/src/metas/index.js.map +1 -0
- package/dist/spec/core/src/metas/initialize.js +52 -0
- package/dist/spec/core/src/metas/initialize.js.map +1 -0
- package/dist/spec/core/src/metas/initialize.test.js +20 -0
- package/dist/spec/core/src/metas/initialize.test.js.map +1 -0
- package/dist/spec/core/src/metas/registerInitial.js +42 -0
- package/dist/spec/core/src/metas/registerInitial.js.map +1 -0
- package/dist/spec/core/src/metas/types.js +3 -0
- package/dist/spec/core/src/metas/types.js.map +1 -0
- package/dist/spec/core/src/sdk/const.js +5 -0
- package/dist/spec/core/src/sdk/const.js.map +1 -0
- package/dist/spec/core/src/sdk/faroGlobalObject.js +23 -0
- package/dist/spec/core/src/sdk/faroGlobalObject.js.map +1 -0
- package/dist/spec/core/src/sdk/index.js +13 -0
- package/dist/spec/core/src/sdk/index.js.map +1 -0
- package/dist/spec/core/src/sdk/internalFaroGlobalObject.js +29 -0
- package/dist/spec/core/src/sdk/internalFaroGlobalObject.js.map +1 -0
- package/dist/spec/core/src/sdk/registerFaro.js +25 -0
- package/dist/spec/core/src/sdk/registerFaro.js.map +1 -0
- package/dist/spec/core/src/sdk/types.js +3 -0
- package/dist/spec/core/src/sdk/types.js.map +1 -0
- package/dist/spec/core/src/semantic.js +12 -0
- package/dist/spec/core/src/semantic.js.map +1 -0
- package/dist/spec/core/src/testUtils/index.js +14 -0
- package/dist/spec/core/src/testUtils/index.js.map +1 -0
- package/dist/spec/core/src/testUtils/mockConfig.js +25 -0
- package/dist/spec/core/src/testUtils/mockConfig.js.map +1 -0
- package/dist/spec/core/src/testUtils/mockInternalLogger.js +12 -0
- package/dist/spec/core/src/testUtils/mockInternalLogger.js.map +1 -0
- package/dist/spec/core/src/testUtils/mockStacktraceParser.js +21 -0
- package/dist/spec/core/src/testUtils/mockStacktraceParser.js.map +1 -0
- package/dist/spec/core/src/testUtils/mockTransport.js +44 -0
- package/dist/spec/core/src/testUtils/mockTransport.js.map +1 -0
- package/dist/spec/core/src/testUtils/testPromise.js +15 -0
- package/dist/spec/core/src/testUtils/testPromise.js.map +1 -0
- package/dist/spec/core/src/transports/base.js +31 -0
- package/dist/spec/core/src/transports/base.js.map +1 -0
- package/dist/spec/core/src/transports/const.js +20 -0
- package/dist/spec/core/src/transports/const.js.map +1 -0
- package/dist/spec/core/src/transports/index.js +15 -0
- package/dist/spec/core/src/transports/index.js.map +1 -0
- package/dist/spec/core/src/transports/initialize.js +151 -0
- package/dist/spec/core/src/transports/initialize.js.map +1 -0
- package/dist/spec/core/src/transports/registerInitial.js +11 -0
- package/dist/spec/core/src/transports/registerInitial.js.map +1 -0
- package/dist/spec/core/src/transports/transports.test.js +139 -0
- package/dist/spec/core/src/transports/transports.test.js.map +1 -0
- package/dist/spec/core/src/transports/types.js +3 -0
- package/dist/spec/core/src/transports/types.js.map +1 -0
- package/dist/spec/core/src/transports/utils.js +13 -0
- package/dist/spec/core/src/transports/utils.js.map +1 -0
- package/dist/spec/core/src/unpatchedConsole/const.js +16 -0
- package/dist/spec/core/src/unpatchedConsole/const.js.map +1 -0
- package/dist/spec/core/src/unpatchedConsole/index.js +9 -0
- package/dist/spec/core/src/unpatchedConsole/index.js.map +1 -0
- package/dist/spec/core/src/unpatchedConsole/initialize.js +12 -0
- package/dist/spec/core/src/unpatchedConsole/initialize.js.map +1 -0
- package/dist/spec/core/src/unpatchedConsole/types.js +3 -0
- package/dist/spec/core/src/unpatchedConsole/types.js.map +1 -0
- package/dist/spec/core/src/utils/baseObject.js +3 -0
- package/dist/spec/core/src/utils/baseObject.js.map +1 -0
- package/dist/spec/core/src/utils/deepEqual.js +62 -0
- package/dist/spec/core/src/utils/deepEqual.js.map +1 -0
- package/dist/spec/core/src/utils/deepEqual.test.js +103 -0
- package/dist/spec/core/src/utils/deepEqual.test.js.map +1 -0
- package/dist/spec/core/src/utils/getCurrentTimestamp.js +8 -0
- package/dist/spec/core/src/utils/getCurrentTimestamp.js.map +1 -0
- package/dist/spec/core/src/utils/index.js +47 -0
- package/dist/spec/core/src/utils/index.js.map +1 -0
- package/dist/spec/core/src/utils/is.js +53 -0
- package/dist/spec/core/src/utils/is.js.map +1 -0
- package/dist/spec/core/src/utils/logLevels.js +22 -0
- package/dist/spec/core/src/utils/logLevels.js.map +1 -0
- package/dist/spec/core/src/utils/noop.js +6 -0
- package/dist/spec/core/src/utils/noop.js.map +1 -0
- package/dist/spec/core/src/utils/promiseBuffer.js +43 -0
- package/dist/spec/core/src/utils/promiseBuffer.js.map +1 -0
- package/dist/spec/core/src/utils/promiseBuffer.test.js +146 -0
- package/dist/spec/core/src/utils/promiseBuffer.test.js.map +1 -0
- package/dist/spec/core/src/utils/shortId.js +12 -0
- package/dist/spec/core/src/utils/shortId.js.map +1 -0
- package/dist/spec/core/src/version.js +6 -0
- package/dist/spec/core/src/version.js.map +1 -0
- package/dist/types/core/src/api/events/index.d.ts +2 -0
- package/dist/types/core/src/api/events/initialize.d.ts +8 -0
- package/dist/types/core/src/api/events/initialize.test.d.ts +1 -0
- package/dist/types/core/src/api/events/types.d.ts +15 -0
- package/dist/types/core/src/api/exceptions/const.d.ts +1 -0
- package/dist/types/core/src/api/exceptions/index.d.ts +3 -0
- package/dist/types/core/src/api/exceptions/initialize.d.ts +8 -0
- package/dist/types/core/src/api/exceptions/initialize.test.d.ts +1 -0
- package/dist/types/core/src/api/exceptions/types.d.ts +32 -0
- package/dist/types/core/src/api/index.d.ts +9 -0
- package/dist/types/core/src/api/initialize.d.ts +7 -0
- package/dist/types/core/src/api/logs/index.d.ts +2 -0
- package/dist/types/core/src/api/logs/initialize.d.ts +8 -0
- package/dist/types/core/src/api/logs/initialize.test.d.ts +1 -0
- package/dist/types/core/src/api/logs/types.d.ts +18 -0
- package/dist/types/core/src/api/measurements/index.d.ts +2 -0
- package/dist/types/core/src/api/measurements/initialize.d.ts +8 -0
- package/dist/types/core/src/api/measurements/initialize.test.d.ts +1 -0
- package/dist/types/core/src/api/measurements/types.d.ts +17 -0
- package/dist/types/core/src/api/meta/index.d.ts +2 -0
- package/dist/types/core/src/api/meta/initialize.d.ts +7 -0
- package/dist/types/core/src/api/meta/types.d.ts +10 -0
- package/dist/types/core/src/api/traces/index.d.ts +2 -0
- package/dist/types/core/src/api/traces/initialize.d.ts +7 -0
- package/dist/types/core/src/api/traces/types.d.ts +20 -0
- package/dist/types/core/src/api/types.d.ts +8 -0
- package/dist/types/core/src/config/const.d.ts +1 -0
- package/dist/types/core/src/config/index.d.ts +2 -0
- package/dist/types/core/src/config/types.d.ts +27 -0
- package/dist/types/core/src/extensions/baseExtension.d.ts +15 -0
- package/dist/types/core/src/extensions/index.d.ts +2 -0
- package/dist/types/core/src/extensions/types.d.ts +16 -0
- package/dist/types/core/src/faro.test.d.ts +1 -0
- package/dist/types/core/src/globalObject/globalObject.d.ts +7 -0
- package/dist/types/core/src/globalObject/index.d.ts +2 -0
- package/dist/types/core/src/index.d.ts +24 -0
- package/dist/types/core/src/initialize.d.ts +3 -0
- package/dist/types/core/src/instrumentations/base.d.ts +9 -0
- package/dist/types/core/src/instrumentations/index.d.ts +4 -0
- package/dist/types/core/src/instrumentations/initialize.d.ts +8 -0
- package/dist/types/core/src/instrumentations/registerInitial.d.ts +2 -0
- package/dist/types/core/src/instrumentations/types.d.ts +14 -0
- package/dist/types/core/src/internalLogger/const.d.ts +11 -0
- package/dist/types/core/src/internalLogger/createInternalLogger.d.ts +4 -0
- package/dist/types/core/src/internalLogger/index.d.ts +4 -0
- package/dist/types/core/src/internalLogger/initialize.d.ts +5 -0
- package/dist/types/core/src/internalLogger/types.d.ts +7 -0
- package/dist/types/core/src/metas/index.d.ts +3 -0
- package/dist/types/core/src/metas/initialize.d.ts +5 -0
- package/dist/types/core/src/metas/initialize.test.d.ts +1 -0
- package/dist/types/core/src/metas/registerInitial.d.ts +2 -0
- package/dist/types/core/src/metas/types.d.ts +67 -0
- package/dist/types/core/src/sdk/const.d.ts +1 -0
- package/dist/types/core/src/sdk/faroGlobalObject.d.ts +2 -0
- package/dist/types/core/src/sdk/index.d.ts +4 -0
- package/dist/types/core/src/sdk/internalFaroGlobalObject.d.ts +4 -0
- package/dist/types/core/src/sdk/registerFaro.d.ts +10 -0
- package/dist/types/core/src/sdk/types.d.ts +18 -0
- package/dist/types/core/src/semantic.d.ts +8 -0
- package/dist/types/core/src/testUtils/index.d.ts +6 -0
- package/dist/types/core/src/testUtils/mockConfig.d.ts +2 -0
- package/dist/types/core/src/testUtils/mockInternalLogger.d.ts +2 -0
- package/dist/types/core/src/testUtils/mockStacktraceParser.d.ts +2 -0
- package/dist/types/core/src/testUtils/mockTransport.d.ts +12 -0
- package/dist/types/core/src/testUtils/testPromise.d.ts +7 -0
- package/dist/types/core/src/transports/base.d.ts +6 -0
- package/dist/types/core/src/transports/const.d.ts +8 -0
- package/dist/types/core/src/transports/index.d.ts +6 -0
- package/dist/types/core/src/transports/initialize.d.ts +8 -0
- package/dist/types/core/src/transports/registerInitial.d.ts +2 -0
- package/dist/types/core/src/transports/transports.test.d.ts +1 -0
- package/dist/types/core/src/transports/types.d.ts +37 -0
- package/dist/types/core/src/transports/utils.d.ts +2 -0
- package/dist/types/core/src/unpatchedConsole/const.d.ts +2 -0
- package/dist/types/core/src/unpatchedConsole/index.d.ts +3 -0
- package/dist/types/core/src/unpatchedConsole/initialize.d.ts +4 -0
- package/dist/types/core/src/unpatchedConsole/types.d.ts +1 -0
- package/dist/types/core/src/utils/baseObject.d.ts +6 -0
- package/dist/types/core/src/utils/deepEqual.d.ts +1 -0
- package/dist/types/core/src/utils/deepEqual.test.d.ts +1 -0
- package/dist/types/core/src/utils/getCurrentTimestamp.d.ts +1 -0
- package/dist/types/core/src/utils/index.d.ts +10 -0
- package/dist/types/core/src/utils/is.d.ts +31 -0
- package/dist/types/core/src/utils/logLevels.d.ts +10 -0
- package/dist/types/core/src/utils/noop.d.ts +1 -0
- package/dist/types/core/src/utils/promiseBuffer.d.ts +14 -0
- package/dist/types/core/src/utils/promiseBuffer.test.d.ts +1 -0
- package/dist/types/core/src/utils/shortId.d.ts +1 -0
- package/dist/types/core/src/version.d.ts +1 -0
- package/dist/types/metas/types.d.ts +6 -0
- package/dist/types/testUtils/mockTransport.d.ts +2 -2
- package/dist/types/transports/base.d.ts +1 -1
- package/dist/types/transports/types.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var initialize_1 = require("../../initialize");
|
|
4
|
+
var testUtils_1 = require("../../testUtils");
|
|
5
|
+
var transports_1 = require("../../transports");
|
|
6
|
+
describe('api.exceptions', function () {
|
|
7
|
+
function createAPI(_a) {
|
|
8
|
+
var _b = _a === void 0 ? { dedupe: true } : _a, dedupe = _b.dedupe;
|
|
9
|
+
var transport = new testUtils_1.MockTransport();
|
|
10
|
+
var config = (0, testUtils_1.mockConfig)({
|
|
11
|
+
dedupe: dedupe,
|
|
12
|
+
transports: [transport],
|
|
13
|
+
});
|
|
14
|
+
var api = (0, initialize_1.initializeFaro)(config).api;
|
|
15
|
+
return [api, transport];
|
|
16
|
+
}
|
|
17
|
+
describe('pushError', function () {
|
|
18
|
+
var api;
|
|
19
|
+
var transport;
|
|
20
|
+
beforeEach(function () {
|
|
21
|
+
var _a;
|
|
22
|
+
_a = createAPI(), api = _a[0], transport = _a[1];
|
|
23
|
+
});
|
|
24
|
+
it('error with overrides', function () {
|
|
25
|
+
var frames = [
|
|
26
|
+
{
|
|
27
|
+
filename: 'foo.js',
|
|
28
|
+
function: 'FooFn',
|
|
29
|
+
colno: 4,
|
|
30
|
+
lineno: 23,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
filename: 'bar.js',
|
|
34
|
+
function: 'BarFn',
|
|
35
|
+
colno: 6,
|
|
36
|
+
lineno: 52,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
api.pushError(new Error('test exception'), {
|
|
40
|
+
stackFrames: frames,
|
|
41
|
+
type: 'TestError',
|
|
42
|
+
});
|
|
43
|
+
expect(transport.items).toHaveLength(1);
|
|
44
|
+
var payload = transport.items[0];
|
|
45
|
+
expect(payload === null || payload === void 0 ? void 0 : payload.payload).toBeTruthy();
|
|
46
|
+
expect(payload === null || payload === void 0 ? void 0 : payload.type).toEqual(transports_1.TransportItemType.EXCEPTION);
|
|
47
|
+
var evt = payload === null || payload === void 0 ? void 0 : payload.payload;
|
|
48
|
+
expect(evt.type).toEqual('TestError');
|
|
49
|
+
expect(evt.value).toEqual('test exception');
|
|
50
|
+
expect(evt.stacktrace).toEqual({ frames: frames });
|
|
51
|
+
});
|
|
52
|
+
it('error without overrides', function () {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
var err = new Error('test');
|
|
55
|
+
api.pushError(err);
|
|
56
|
+
expect(transport.items).toHaveLength(1);
|
|
57
|
+
var payload = transport.items[0];
|
|
58
|
+
expect((_a = payload === null || payload === void 0 ? void 0 : payload.meta.app) === null || _a === void 0 ? void 0 : _a.name).toEqual('test');
|
|
59
|
+
expect(payload === null || payload === void 0 ? void 0 : payload.payload).toBeTruthy();
|
|
60
|
+
expect(payload === null || payload === void 0 ? void 0 : payload.type).toEqual(transports_1.TransportItemType.EXCEPTION);
|
|
61
|
+
var evt = payload === null || payload === void 0 ? void 0 : payload.payload;
|
|
62
|
+
expect(evt.type).toEqual('Error');
|
|
63
|
+
expect(evt.value).toEqual('test');
|
|
64
|
+
expect(evt.timestamp).toBeTruthy();
|
|
65
|
+
var stacktrace = evt.stacktrace;
|
|
66
|
+
expect(stacktrace).toBeTruthy();
|
|
67
|
+
expect(stacktrace === null || stacktrace === void 0 ? void 0 : stacktrace.frames.length).toBeGreaterThan(3);
|
|
68
|
+
expect((_b = stacktrace === null || stacktrace === void 0 ? void 0 : stacktrace.frames[0]) === null || _b === void 0 ? void 0 : _b.filename).toEqual('Error: test');
|
|
69
|
+
});
|
|
70
|
+
describe('Filtering', function () {
|
|
71
|
+
it('filters the same event', function () {
|
|
72
|
+
var error = new Error('test');
|
|
73
|
+
api.pushError(error);
|
|
74
|
+
expect(transport.items).toHaveLength(1);
|
|
75
|
+
api.pushError(error);
|
|
76
|
+
expect(transport.items).toHaveLength(1);
|
|
77
|
+
});
|
|
78
|
+
it("doesn't filter events with same message and different stacktrace", function () {
|
|
79
|
+
var error1 = new Error('test');
|
|
80
|
+
var error2 = new Error('test');
|
|
81
|
+
api.pushError(error1);
|
|
82
|
+
expect(transport.items).toHaveLength(1);
|
|
83
|
+
api.pushError(error2);
|
|
84
|
+
expect(transport.items).toHaveLength(2);
|
|
85
|
+
});
|
|
86
|
+
it("doesn't filter events with other message and same stacktrace", function () {
|
|
87
|
+
var error = new Error('test');
|
|
88
|
+
api.pushError(error);
|
|
89
|
+
expect(transport.items).toHaveLength(1);
|
|
90
|
+
error.message = 'test2';
|
|
91
|
+
api.pushError(error);
|
|
92
|
+
expect(transport.items).toHaveLength(2);
|
|
93
|
+
});
|
|
94
|
+
it("doesn't filter events with same message and same stacktrace but different type", function () {
|
|
95
|
+
var error = new Error('test');
|
|
96
|
+
api.pushError(error);
|
|
97
|
+
expect(transport.items).toHaveLength(1);
|
|
98
|
+
error.name = 'Another Type';
|
|
99
|
+
api.pushError(error);
|
|
100
|
+
expect(transport.items).toHaveLength(2);
|
|
101
|
+
});
|
|
102
|
+
it("filters an event and doesn't filter the next different one", function () {
|
|
103
|
+
var error = new Error('test');
|
|
104
|
+
api.pushError(error);
|
|
105
|
+
expect(transport.items).toHaveLength(1);
|
|
106
|
+
api.pushError(error);
|
|
107
|
+
expect(transport.items).toHaveLength(1);
|
|
108
|
+
error.name = 'Another Type';
|
|
109
|
+
api.pushError(error);
|
|
110
|
+
expect(transport.items).toHaveLength(2);
|
|
111
|
+
});
|
|
112
|
+
it("doesn't filter when dedupe is false", function () {
|
|
113
|
+
var _a;
|
|
114
|
+
_a = createAPI({ dedupe: false }), api = _a[0], transport = _a[1];
|
|
115
|
+
var error = new Error('test');
|
|
116
|
+
api.pushError(error);
|
|
117
|
+
expect(transport.items).toHaveLength(1);
|
|
118
|
+
api.pushError(error);
|
|
119
|
+
expect(transport.items).toHaveLength(2);
|
|
120
|
+
});
|
|
121
|
+
it("doesn't filter when skipDedupe is true", function () {
|
|
122
|
+
var error = new Error('test');
|
|
123
|
+
api.pushError(error);
|
|
124
|
+
expect(transport.items).toHaveLength(1);
|
|
125
|
+
api.pushError(error, {
|
|
126
|
+
skipDedupe: true,
|
|
127
|
+
});
|
|
128
|
+
expect(transport.items).toHaveLength(2);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=initialize.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.test.js","sourceRoot":"","sources":["../../../../../../src/api/exceptions/initialize.test.ts"],"names":[],"mappings":";;AAAA,+CAAkD;AAClD,6CAA4D;AAC5D,+CAAqD;AAKrD,QAAQ,CAAC,gBAAgB,EAAE;IACzB,SAAS,SAAS,CAAC,EAAkD;YAAlD,qBAAkC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAA,EAAhD,MAAM,YAAA;QACzB,IAAM,SAAS,GAAG,IAAI,yBAAa,EAAE,CAAC;QACtC,IAAM,MAAM,GAAG,IAAA,sBAAU,EAAC;YACxB,MAAM,QAAA;YACN,UAAU,EAAE,CAAC,SAAS,CAAC;SACxB,CAAC,CAAC;QAEK,IAAA,GAAG,GAAK,IAAA,2BAAc,EAAC,MAAM,CAAC,IAA3B,CAA4B;QAEvC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC1B,CAAC;IAED,QAAQ,CAAC,WAAW,EAAE;QACpB,IAAI,GAAQ,CAAC;QACb,IAAI,SAAwB,CAAC;QAE7B,UAAU,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AE,SAAS,QAAA,CAAiC;gBAEhD,IAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;gBAEhC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACrB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAExC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACrB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,wCAAwC,EAAE;gBAC3C,IAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;gBAEhC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACrB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAExC,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;oBACnB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;gBACH,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { initializeFaro } from '../../initialize';\nimport { mockConfig, MockTransport } from '../../testUtils';\nimport { TransportItemType } from '../../transports';\nimport type { API } from '../types';\n\nimport type { ExceptionEvent, ExceptionStackFrame } from './types';\n\ndescribe('api.exceptions', () => {\n function createAPI({ dedupe }: { dedupe: boolean } = { dedupe: true }): [API, MockTransport] {\n const transport = new MockTransport();\n const config = mockConfig({\n dedupe,\n transports: [transport],\n });\n\n const { api } = initializeFaro(config);\n\n return [api, transport];\n }\n\n describe('pushError', () => {\n let api: API;\n let transport: MockTransport;\n\n beforeEach(() => {\n [api, transport] = createAPI();\n });\n\n it('error with overrides', () => {\n const frames: ExceptionStackFrame[] = [\n {\n filename: 'foo.js',\n function: 'FooFn',\n colno: 4,\n lineno: 23,\n },\n {\n filename: 'bar.js',\n function: 'BarFn',\n colno: 6,\n lineno: 52,\n },\n ];\n\n api.pushError(new Error('test exception'), {\n stackFrames: frames,\n type: 'TestError',\n });\n\n expect(transport.items).toHaveLength(1);\n\n const payload = transport.items[0];\n expect(payload?.payload).toBeTruthy();\n expect(payload?.type).toEqual(TransportItemType.EXCEPTION);\n\n const evt = payload?.payload as ExceptionEvent;\n expect(evt.type).toEqual('TestError');\n expect(evt.value).toEqual('test exception');\n expect(evt.stacktrace).toEqual({ frames });\n });\n\n it('error without overrides', () => {\n const err = new Error('test');\n api.pushError(err);\n expect(transport.items).toHaveLength(1);\n\n const payload = transport.items[0];\n expect(payload?.meta.app?.name).toEqual('test');\n expect(payload?.payload).toBeTruthy();\n expect(payload?.type).toEqual(TransportItemType.EXCEPTION);\n\n const evt = payload?.payload as ExceptionEvent;\n expect(evt.type).toEqual('Error');\n expect(evt.value).toEqual('test');\n expect(evt.timestamp).toBeTruthy();\n\n const stacktrace = evt.stacktrace;\n expect(stacktrace).toBeTruthy();\n expect(stacktrace?.frames.length).toBeGreaterThan(3);\n expect(stacktrace?.frames[0]?.filename).toEqual('Error: test');\n });\n\n describe('Filtering', () => {\n it('filters the same event', () => {\n const error = new Error('test');\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n });\n\n it(\"doesn't filter events with same message and different stacktrace\", () => {\n const error1 = new Error('test');\n const error2 = new Error('test');\n\n api.pushError(error1);\n expect(transport.items).toHaveLength(1);\n\n api.pushError(error2);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter events with other message and same stacktrace\", () => {\n const error = new Error('test');\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n error.message = 'test2';\n api.pushError(error);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter events with same message and same stacktrace but different type\", () => {\n const error = new Error('test');\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n error.name = 'Another Type';\n api.pushError(error);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"filters an event and doesn't filter the next different one\", () => {\n const error = new Error('test');\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n error.name = 'Another Type';\n api.pushError(error);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when dedupe is false\", () => {\n [api, transport] = createAPI({ dedupe: false });\n\n const error = new Error('test');\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n api.pushError(error);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when skipDedupe is true\", () => {\n const error = new Error('test');\n\n api.pushError(error);\n expect(transport.items).toHaveLength(1);\n\n api.pushError(error, {\n skipDedupe: true,\n });\n expect(transport.items).toHaveLength(2);\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport interface ExceptionEvent {\n timestamp: string;\n type: string;\n value: string;\n\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n}\n\nexport interface PushErrorOptions {\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n}\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: Error, options?: PushErrorOptions) => void;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultExceptionType = exports.initializeAPI = void 0;
|
|
4
|
+
var initialize_1 = require("./initialize");
|
|
5
|
+
Object.defineProperty(exports, "initializeAPI", { enumerable: true, get: function () { return initialize_1.initializeAPI; } });
|
|
6
|
+
var exceptions_1 = require("./exceptions");
|
|
7
|
+
Object.defineProperty(exports, "defaultExceptionType", { enumerable: true, get: function () { return exceptions_1.defaultExceptionType; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/api/index.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AAKtB,2CAAoD;AAA3C,kHAAA,oBAAoB,OAAA","sourcesContent":["export { initializeAPI } from './initialize';\nexport type { API, APIEvent } from './types';\n\nexport type { EventAttributes, EventEvent, EventsAPI } from './events';\n\nexport { defaultExceptionType } from './exceptions';\nexport type {\n ExceptionEvent,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n PushErrorOptions,\n Stacktrace,\n StacktraceParser,\n} from './exceptions';\n\nexport type { LogContext, LogEvent, LogsAPI, PushLogOptions } from './logs';\n\nexport type { MeasurementEvent, MeasurementsAPI, PushMeasurementOptions } from './measurements';\n\nexport type { MetaAPI } from './meta';\n\nexport type { OTELApi, TraceContext, TraceEvent, TracesAPI } from './traces';\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.initializeAPI = void 0;
|
|
15
|
+
var events_1 = require("./events");
|
|
16
|
+
var exceptions_1 = require("./exceptions");
|
|
17
|
+
var logs_1 = require("./logs");
|
|
18
|
+
var measurements_1 = require("./measurements");
|
|
19
|
+
var meta_1 = require("./meta");
|
|
20
|
+
var traces_1 = require("./traces");
|
|
21
|
+
function initializeAPI(unpatchedConsole, internalLogger, config, metas, transports) {
|
|
22
|
+
internalLogger.debug('Initializing API');
|
|
23
|
+
var tracesApi = (0, traces_1.initializeTracesAPI)(unpatchedConsole, internalLogger, config, metas, transports);
|
|
24
|
+
return __assign(__assign(__assign(__assign(__assign(__assign({}, tracesApi), (0, exceptions_1.initializeExceptionsAPI)(unpatchedConsole, internalLogger, config, metas, transports, tracesApi)), (0, meta_1.initializeMetaAPI)(unpatchedConsole, internalLogger, config, metas, transports)), (0, logs_1.initializeLogsAPI)(unpatchedConsole, internalLogger, config, metas, transports, tracesApi)), (0, measurements_1.initializeMeasurementsAPI)(unpatchedConsole, internalLogger, config, metas, transports, tracesApi)), (0, events_1.initializeEventsAPI)(unpatchedConsole, internalLogger, config, metas, transports, tracesApi));
|
|
25
|
+
}
|
|
26
|
+
exports.initializeAPI = initializeAPI;
|
|
27
|
+
//# sourceMappingURL=initialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../src/api/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,mCAA+C;AAC/C,2CAAuD;AACvD,+BAA2C;AAC3C,+CAA2D;AAC3D,+BAA2C;AAC3C,mCAA+C;AAG/C,SAAgB,aAAa,CAC3B,gBAAkC,EAClC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB;IAEtB,cAAc,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAEzC,IAAM,SAAS,GAAG,IAAA,4BAAmB,EAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IAEnG,iEACK,SAAS,GACT,IAAA,oCAAuB,EAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,GAC/F,IAAA,wBAAiB,EAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,GAC9E,IAAA,wBAAiB,EAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,GACzF,IAAA,wCAAyB,EAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,GACjG,IAAA,4BAAmB,EAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,EAC9F;AACJ,CAAC;AAnBD,sCAmBC","sourcesContent":["import type { Config } from '../config';\nimport type { InternalLogger } from '../internalLogger';\nimport type { Metas } from '../metas';\nimport type { Transports } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\n\nimport { initializeEventsAPI } from './events';\nimport { initializeExceptionsAPI } from './exceptions';\nimport { initializeLogsAPI } from './logs';\nimport { initializeMeasurementsAPI } from './measurements';\nimport { initializeMetaAPI } from './meta';\nimport { initializeTracesAPI } from './traces';\nimport type { API } from './types';\n\nexport function initializeAPI(\n unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports\n): API {\n internalLogger.debug('Initializing API');\n\n const tracesApi = initializeTracesAPI(unpatchedConsole, internalLogger, config, metas, transports);\n\n return {\n ...tracesApi,\n ...initializeExceptionsAPI(unpatchedConsole, internalLogger, config, metas, transports, tracesApi),\n ...initializeMetaAPI(unpatchedConsole, internalLogger, config, metas, transports),\n ...initializeLogsAPI(unpatchedConsole, internalLogger, config, metas, transports, tracesApi),\n ...initializeMeasurementsAPI(unpatchedConsole, internalLogger, config, metas, transports, tracesApi),\n ...initializeEventsAPI(unpatchedConsole, internalLogger, config, metas, transports, tracesApi),\n };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeLogsAPI = void 0;
|
|
4
|
+
var initialize_1 = require("./initialize");
|
|
5
|
+
Object.defineProperty(exports, "initializeLogsAPI", { enumerable: true, get: function () { return initialize_1.initializeLogsAPI; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/api/logs/index.ts"],"names":[],"mappings":";;;AAAA,2CAAiD;AAAxC,+GAAA,iBAAiB,OAAA","sourcesContent":["export { initializeLogsAPI } from './initialize';\n\nexport type { LogContext, LogEvent, LogsAPI, PushLogOptions } from './types';\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeLogsAPI = void 0;
|
|
4
|
+
var transports_1 = require("../../transports");
|
|
5
|
+
var utils_1 = require("../../utils");
|
|
6
|
+
function initializeLogsAPI(_unpatchedConsole, internalLogger, config, metas, transports, tracesApi) {
|
|
7
|
+
internalLogger.debug('Initializing logs API');
|
|
8
|
+
var lastPayload = null;
|
|
9
|
+
var pushLog = function (args, _a) {
|
|
10
|
+
var _b = _a === void 0 ? {} : _a, context = _b.context, level = _b.level, skipDedupe = _b.skipDedupe;
|
|
11
|
+
try {
|
|
12
|
+
var item = {
|
|
13
|
+
type: transports_1.TransportItemType.LOG,
|
|
14
|
+
payload: {
|
|
15
|
+
message: args
|
|
16
|
+
.map(function (arg) {
|
|
17
|
+
try {
|
|
18
|
+
return String(arg);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.join(' '),
|
|
25
|
+
level: level !== null && level !== void 0 ? level : utils_1.defaultLogLevel,
|
|
26
|
+
context: context !== null && context !== void 0 ? context : {},
|
|
27
|
+
timestamp: (0, utils_1.getCurrentTimestamp)(),
|
|
28
|
+
trace: tracesApi.getTraceContext(),
|
|
29
|
+
},
|
|
30
|
+
meta: metas.value,
|
|
31
|
+
};
|
|
32
|
+
var testingPayload = {
|
|
33
|
+
message: item.payload.message,
|
|
34
|
+
level: item.payload.level,
|
|
35
|
+
context: item.payload.context,
|
|
36
|
+
};
|
|
37
|
+
if (!skipDedupe && config.dedupe && !(0, utils_1.isNull)(lastPayload) && (0, utils_1.deepEqual)(testingPayload, lastPayload)) {
|
|
38
|
+
internalLogger.debug('Skipping log push because it is the same as the last one\n', item.payload);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
lastPayload = testingPayload;
|
|
42
|
+
internalLogger.debug('Pushing log\n', item);
|
|
43
|
+
transports.execute(item);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
internalLogger.error('Error pushing log\n', err);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
pushLog: pushLog,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.initializeLogsAPI = initializeLogsAPI;
|
|
54
|
+
//# sourceMappingURL=initialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../../src/api/logs/initialize.ts"],"names":[],"mappings":";;;AAGA,+CAAoE;AAGpE,qCAAsF;AAKtF,SAAgB,iBAAiB,CAC/B,iBAAmC,EACnC,cAA8B,EAC9B,M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CAAC,OAAO,CAAC,CAAC;gBAEjG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;YAE5C,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC,CAAC;IAEF,OAAO;QACL,OAAO,SAAA;KACR,CAAC;AACJ,CAAC;AA3DD,8CA2DC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, defaultLogLevel, getCurrentTimestamp, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport type { LogEvent, LogsAPI } from './types';\n\nexport function initializeLogsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): LogsAPI {\n internalLogger.debug('Initializing logs API');\n\n let lastPayload: Pick<LogEvent, 'message' | 'level' | 'context'> | null = null;\n\n const pushLog: LogsAPI['pushLog'] = (args, { context, level, skipDedupe } = {}) => {\n try {\n const item: TransportItem<LogEvent> = {\n type: TransportItemType.LOG,\n payload: {\n message: args\n .map((arg) => {\n try {\n return String(arg);\n } catch (err) {\n return '';\n }\n })\n .join(' '),\n level: level ?? defaultLogLevel,\n context: context ?? {},\n timestamp: getCurrentTimestamp(),\n trace: tracesApi.getTraceContext(),\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n message: item.payload.message,\n level: item.payload.level,\n context: item.payload.context,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping log push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing log\\n', item);\n\n transports.execute(item);\n } catch (err) {\n internalLogger.error('Error pushing log\\n', err);\n }\n };\n\n return {\n pushLog,\n };\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var initialize_1 = require("../../initialize");
|
|
4
|
+
var testUtils_1 = require("../../testUtils");
|
|
5
|
+
var utils_1 = require("../../utils");
|
|
6
|
+
describe('api.logs', function () {
|
|
7
|
+
function createAPI(_a) {
|
|
8
|
+
var _b = _a === void 0 ? { dedupe: true } : _a, dedupe = _b.dedupe;
|
|
9
|
+
var transport = new testUtils_1.MockTransport();
|
|
10
|
+
var config = (0, testUtils_1.mockConfig)({
|
|
11
|
+
dedupe: dedupe,
|
|
12
|
+
transports: [transport],
|
|
13
|
+
});
|
|
14
|
+
var api = (0, initialize_1.initializeFaro)(config).api;
|
|
15
|
+
return [api, transport];
|
|
16
|
+
}
|
|
17
|
+
describe('pushLog', function () {
|
|
18
|
+
var api;
|
|
19
|
+
var transport;
|
|
20
|
+
beforeEach(function () {
|
|
21
|
+
var _a;
|
|
22
|
+
_a = createAPI(), api = _a[0], transport = _a[1];
|
|
23
|
+
});
|
|
24
|
+
describe('Filtering', function () {
|
|
25
|
+
it('filters the same event', function () {
|
|
26
|
+
api.pushLog(['test']);
|
|
27
|
+
expect(transport.items).toHaveLength(1);
|
|
28
|
+
api.pushLog(['test']);
|
|
29
|
+
expect(transport.items).toHaveLength(1);
|
|
30
|
+
});
|
|
31
|
+
it("doesn't filter events with partially same message", function () {
|
|
32
|
+
api.pushLog(['test', 'another test']);
|
|
33
|
+
expect(transport.items).toHaveLength(1);
|
|
34
|
+
api.pushLog(['test']);
|
|
35
|
+
expect(transport.items).toHaveLength(2);
|
|
36
|
+
});
|
|
37
|
+
it("doesn't filter events with same message and different level", function () {
|
|
38
|
+
api.pushLog(['test']);
|
|
39
|
+
expect(transport.items).toHaveLength(1);
|
|
40
|
+
api.pushLog(['test'], {
|
|
41
|
+
level: utils_1.LogLevel.INFO,
|
|
42
|
+
});
|
|
43
|
+
expect(transport.items).toHaveLength(2);
|
|
44
|
+
});
|
|
45
|
+
it("doesn't filter events with same message and same level but different context", function () {
|
|
46
|
+
api.pushLog(['test']);
|
|
47
|
+
expect(transport.items).toHaveLength(1);
|
|
48
|
+
api.pushLog(['test'], {
|
|
49
|
+
context: {
|
|
50
|
+
a: 1,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(transport.items).toHaveLength(2);
|
|
54
|
+
});
|
|
55
|
+
it("filters an event and doesn't filter the next different one", function () {
|
|
56
|
+
api.pushLog(['test']);
|
|
57
|
+
expect(transport.items).toHaveLength(1);
|
|
58
|
+
api.pushLog(['test']);
|
|
59
|
+
expect(transport.items).toHaveLength(1);
|
|
60
|
+
api.pushLog(['test'], {
|
|
61
|
+
level: utils_1.LogLevel.ERROR,
|
|
62
|
+
});
|
|
63
|
+
expect(transport.items).toHaveLength(2);
|
|
64
|
+
});
|
|
65
|
+
it("doesn't filter when dedupe is false", function () {
|
|
66
|
+
var _a;
|
|
67
|
+
_a = createAPI({ dedupe: false }), api = _a[0], transport = _a[1];
|
|
68
|
+
api.pushLog(['test']);
|
|
69
|
+
expect(transport.items).toHaveLength(1);
|
|
70
|
+
api.pushLog(['test']);
|
|
71
|
+
expect(transport.items).toHaveLength(2);
|
|
72
|
+
});
|
|
73
|
+
it("doesn't filter when skipDedupe is true", function () {
|
|
74
|
+
api.pushLog(['test']);
|
|
75
|
+
expect(transport.items).toHaveLength(1);
|
|
76
|
+
api.pushLog(['test'], { skipDedupe: true });
|
|
77
|
+
expect(transport.items).toHaveLength(2);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=initialize.test.js.map
|
|
@@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L,CAAC,CAAC,CAAC","sourcesContent":["import { initializeFaro } from '../../initialize';\nimport { mockConfig, MockTransport } from '../../testUtils';\nimport { LogLevel } from '../../utils';\nimport type { API } from '../types';\n\ndescribe('api.logs', () => {\n function createAPI({ dedupe }: { dedupe: boolean } = { dedupe: true }): [API, MockTransport] {\n const transport = new MockTransport();\n const config = mockConfig({\n dedupe,\n transports: [transport],\n });\n\n const { api } = initializeFaro(config);\n\n return [api, transport];\n }\n\n describe('pushLog', () => {\n let api: API;\n let transport: MockTransport;\n\n beforeEach(() => {\n [api, transport] = createAPI();\n });\n\n describe('Filtering', () => {\n it('filters the same event', () => {\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n });\n\n it(\"doesn't filter events with partially same message\", () => {\n api.pushLog(['test', 'another test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter events with same message and different level\", () => {\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test'], {\n level: LogLevel.INFO,\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter events with same message and same level but different context\", () => {\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test'], {\n context: {\n a: 1,\n },\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"filters an event and doesn't filter the next different one\", () => {\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test'], {\n level: LogLevel.ERROR,\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when dedupe is false\", () => {\n [api, transport] = createAPI({ dedupe: false });\n\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when skipDedupe is true\", () => {\n api.pushLog(['test']);\n expect(transport.items).toHaveLength(1);\n\n api.pushLog(['test'], { skipDedupe: true });\n expect(transport.items).toHaveLength(2);\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/api/logs/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseObject, LogLevel } from '../../utils';\nimport type { TraceContext } from '../traces';\n\nexport type LogContext = BaseObject;\n\nexport interface LogEvent {\n context: LogContext;\n level: LogLevel;\n message: string;\n timestamp: string;\n\n trace?: TraceContext;\n}\n\nexport interface PushLogOptions {\n context?: LogContext;\n level?: LogLevel;\n skipDedupe?: boolean;\n}\n\nexport interface LogsAPI {\n pushLog: (args: unknown[], options?: PushLogOptions) => void;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeMeasurementsAPI = void 0;
|
|
4
|
+
var initialize_1 = require("./initialize");
|
|
5
|
+
Object.defineProperty(exports, "initializeMeasurementsAPI", { enumerable: true, get: function () { return initialize_1.initializeMeasurementsAPI; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/api/measurements/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AAAhD,uHAAA,yBAAyB,OAAA","sourcesContent":["export { initializeMeasurementsAPI } from './initialize';\n\nexport type { MeasurementEvent, MeasurementsAPI, PushMeasurementOptions } from './types';\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.initializeMeasurementsAPI = void 0;
|
|
15
|
+
var transports_1 = require("../../transports");
|
|
16
|
+
var utils_1 = require("../../utils");
|
|
17
|
+
function initializeMeasurementsAPI(_unpatchedConsole, internalLogger, config, metas, transports, tracesApi) {
|
|
18
|
+
internalLogger.debug('Initializing measurements API');
|
|
19
|
+
var lastPayload = null;
|
|
20
|
+
var pushMeasurement = function (payload, _a) {
|
|
21
|
+
var _b;
|
|
22
|
+
var _c = _a === void 0 ? {} : _a, skipDedupe = _c.skipDedupe;
|
|
23
|
+
try {
|
|
24
|
+
var item = {
|
|
25
|
+
type: transports_1.TransportItemType.MEASUREMENT,
|
|
26
|
+
payload: __assign(__assign({}, payload), { trace: tracesApi.getTraceContext(), timestamp: (_b = payload.timestamp) !== null && _b !== void 0 ? _b : (0, utils_1.getCurrentTimestamp)() }),
|
|
27
|
+
meta: metas.value,
|
|
28
|
+
};
|
|
29
|
+
var testingPayload = {
|
|
30
|
+
type: item.payload.type,
|
|
31
|
+
values: item.payload.values,
|
|
32
|
+
};
|
|
33
|
+
if (!skipDedupe && config.dedupe && !(0, utils_1.isNull)(lastPayload) && (0, utils_1.deepEqual)(testingPayload, lastPayload)) {
|
|
34
|
+
internalLogger.debug('Skipping measurement push because it is the same as the last one\n', item.payload);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
lastPayload = testingPayload;
|
|
38
|
+
internalLogger.debug('Pushing measurement\n', item);
|
|
39
|
+
transports.execute(item);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
internalLogger.error('Error pushing measurement\n', err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
pushMeasurement: pushMeasurement,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.initializeMeasurementsAPI = initializeMeasurementsAPI;
|
|
50
|
+
//# sourceMappingURL=initialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,+CAAoE;AAGpE,qCAAqE;AAKrE,SAAgB,yBAAyB,CACvC,iBAAmC,EACnC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB,EACtB,SAAoB;IAEpB,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,IAAI,WAAW,GAAqD,IAAI,CAAC;IAEzE,IAAM,eAAe,GAAuC,UAAC,OAAO,EAAE,EAAmB;;YAAnB,qBAAiB,EAAE,KAAA,EAAjB,UAAU,gBAAA;QAChF,IAAI;YACF,IAAM,IAAI,GAAoC;gBAC5C,IAAI,EAAE,8BAAiB,CAAC,WAAW;gBACnC,OAAO,wBACF,OAAO,KACV,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,EAClC,SAAS,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,IAAA,2BAAmB,GAAE,GACtD;gBACD,IAAI,EAAE,KAAK,CAAC,KAAK;aAClB,CAAC;YAEF,IAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAA,cAAM,EAAC,WAAW,CAAC,IAAI,IAAA,iBAAS,EAAC,cAAc,EAAE,WAAW,CAAC,EAAE;gBAClG,cAAc,CAAC,KAAK,CAAC,oEAAoE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEzG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe,iBAAA;KAChB,CAAC;AACJ,CAAC;AAhDD,8DAgDC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): MeasurementsAPI {\n internalLogger.debug('Initializing measurements API');\n\n let lastPayload: Pick<MeasurementEvent, 'type' | 'values'> | null = null;\n\n const pushMeasurement: MeasurementsAPI['pushMeasurement'] = (payload, { skipDedupe } = {}) => {\n try {\n const item: TransportItem<MeasurementEvent> = {\n type: TransportItemType.MEASUREMENT,\n payload: {\n ...payload,\n trace: tracesApi.getTraceContext(),\n timestamp: payload.timestamp ?? getCurrentTimestamp(),\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n type: item.payload.type,\n values: item.payload.values,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping measurement push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing measurement\\n', item);\n\n transports.execute(item);\n } catch (err) {\n internalLogger.error('Error pushing measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var initialize_1 = require("../../initialize");
|
|
15
|
+
var testUtils_1 = require("../../testUtils");
|
|
16
|
+
describe('api.measurements', function () {
|
|
17
|
+
function createAPI(_a) {
|
|
18
|
+
var _b = _a === void 0 ? { dedupe: true } : _a, dedupe = _b.dedupe;
|
|
19
|
+
var transport = new testUtils_1.MockTransport();
|
|
20
|
+
var config = (0, testUtils_1.mockConfig)({
|
|
21
|
+
dedupe: dedupe,
|
|
22
|
+
transports: [transport],
|
|
23
|
+
});
|
|
24
|
+
var api = (0, initialize_1.initializeFaro)(config).api;
|
|
25
|
+
return [api, transport];
|
|
26
|
+
}
|
|
27
|
+
describe('pushMeasurement', function () {
|
|
28
|
+
var api;
|
|
29
|
+
var transport;
|
|
30
|
+
beforeEach(function () {
|
|
31
|
+
var _a;
|
|
32
|
+
_a = createAPI(), api = _a[0], transport = _a[1];
|
|
33
|
+
});
|
|
34
|
+
describe('Filtering', function () {
|
|
35
|
+
it('filters the same measurement', function () {
|
|
36
|
+
var measurement = {
|
|
37
|
+
type: 'custom',
|
|
38
|
+
values: {
|
|
39
|
+
a: 1,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
api.pushMeasurement(measurement);
|
|
43
|
+
expect(transport.items).toHaveLength(1);
|
|
44
|
+
api.pushMeasurement(measurement);
|
|
45
|
+
expect(transport.items).toHaveLength(1);
|
|
46
|
+
});
|
|
47
|
+
it("doesn't filter measurements with same type and partially same values", function () {
|
|
48
|
+
var measurement1 = {
|
|
49
|
+
type: 'custom',
|
|
50
|
+
values: {
|
|
51
|
+
a: 1,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
var measurement2 = __assign(__assign({}, measurement1), { values: __assign(__assign({}, measurement1.values), { b: 2 }) });
|
|
55
|
+
api.pushMeasurement(measurement1);
|
|
56
|
+
expect(transport.items).toHaveLength(1);
|
|
57
|
+
api.pushMeasurement(measurement2);
|
|
58
|
+
expect(transport.items).toHaveLength(2);
|
|
59
|
+
});
|
|
60
|
+
it("doesn't filter measurements with different type and same values", function () {
|
|
61
|
+
var measurement1 = {
|
|
62
|
+
type: 'custom',
|
|
63
|
+
values: {
|
|
64
|
+
a: 1,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
var measurement2 = __assign(__assign({}, measurement1), { type: 'web-vitals' });
|
|
68
|
+
api.pushMeasurement(measurement1);
|
|
69
|
+
expect(transport.items).toHaveLength(1);
|
|
70
|
+
api.pushMeasurement(measurement2);
|
|
71
|
+
expect(transport.items).toHaveLength(2);
|
|
72
|
+
});
|
|
73
|
+
it("filters a measurement and doesn't filter the next different one", function () {
|
|
74
|
+
var measurement1 = {
|
|
75
|
+
type: 'custom',
|
|
76
|
+
values: {
|
|
77
|
+
a: 1,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
var measurement2 = __assign(__assign({}, measurement1), { type: 'web-vitals' });
|
|
81
|
+
api.pushMeasurement(measurement1);
|
|
82
|
+
expect(transport.items).toHaveLength(1);
|
|
83
|
+
api.pushMeasurement(measurement1);
|
|
84
|
+
expect(transport.items).toHaveLength(1);
|
|
85
|
+
api.pushMeasurement(measurement2);
|
|
86
|
+
expect(transport.items).toHaveLength(2);
|
|
87
|
+
});
|
|
88
|
+
it("doesn't filter when dedupe is false", function () {
|
|
89
|
+
var _a;
|
|
90
|
+
_a = createAPI({ dedupe: false }), api = _a[0], transport = _a[1];
|
|
91
|
+
var measurement = {
|
|
92
|
+
type: 'custom',
|
|
93
|
+
values: {
|
|
94
|
+
a: 1,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
api.pushMeasurement(measurement);
|
|
98
|
+
expect(transport.items).toHaveLength(1);
|
|
99
|
+
api.pushMeasurement(measurement);
|
|
100
|
+
expect(transport.items).toHaveLength(2);
|
|
101
|
+
});
|
|
102
|
+
it("doesn't filter when skipDedupe is true", function () {
|
|
103
|
+
var measurement = {
|
|
104
|
+
type: 'custom',
|
|
105
|
+
values: {
|
|
106
|
+
a: 1,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
api.pushMeasurement(measurement);
|
|
110
|
+
expect(transport.items).toHaveLength(1);
|
|
111
|
+
api.pushMeasurement(measurement, { skipDedupe: true });
|
|
112
|
+
expect(transport.items).toHaveLength(2);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=initialize.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.test.js","sourceRoot":"","sources":["../../../../../../src/api/measurements/initialize.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAAkD;AAClD,6CAA4D;AAG5D,QAAQ,CAAC,kBAAkB,EAAE;IAC3B,SAAS,SAAS,CAAC,EAAkD;YAAlD,qBAAkC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAA,EAAhD,MAAM,YAAA;QACzB,IAAM,SAAS,GAAG,IAAI,yBAAa,EAAE,CAAC;QACtC,IAAM,MAAM,GAAG,IAAA,sBAAU,EAAC;YACxB,MAAM,QAAA;YACN,UAAU,EAAE,CAAC,SAAS,CAAC;SACxB,CAAC,CAAC;QAEK,IAAA,GAAG,GAAK,IAAA,2BAAc,EAAC,MAAM,CAAC,IAA3B,CA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AA9C,GAAG,QAAA,EAAE,SAAS,QAAA,CAAiC;gBAEhD,IAAM,WAAW,GAAG;oBAClB,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE;wBACN,CAAC,EAAE,CAAC;qBACL;iBACF,CAAC;gBAEF,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;gBACjC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAExC,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;gBACjC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,wCAAwC,EAAE;gBAC3C,IAAM,WAAW,GAAG;oBAClB,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE;wBACN,CAAC,EAAE,CAAC;qBACL;iBACF,CAAC;gBAEF,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;gBACjC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAExC,GAAG,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;gBACvD,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { initializeFaro } from '../../initialize';\nimport { mockConfig, MockTransport } from '../../testUtils';\nimport type { API } from '../types';\n\ndescribe('api.measurements', () => {\n function createAPI({ dedupe }: { dedupe: boolean } = { dedupe: true }): [API, MockTransport] {\n const transport = new MockTransport();\n const config = mockConfig({\n dedupe,\n transports: [transport],\n });\n\n const { api } = initializeFaro(config);\n\n return [api, transport];\n }\n\n describe('pushMeasurement', () => {\n let api: API;\n let transport: MockTransport;\n\n beforeEach(() => {\n [api, transport] = createAPI();\n });\n\n describe('Filtering', () => {\n it('filters the same measurement', () => {\n const measurement = {\n type: 'custom',\n values: {\n a: 1,\n },\n };\n\n api.pushMeasurement(measurement);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement);\n expect(transport.items).toHaveLength(1);\n });\n\n it(\"doesn't filter measurements with same type and partially same values\", () => {\n const measurement1 = {\n type: 'custom',\n values: {\n a: 1,\n },\n };\n\n const measurement2 = {\n ...measurement1,\n values: {\n ...measurement1.values,\n b: 2,\n },\n };\n\n api.pushMeasurement(measurement1);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement2);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter measurements with different type and same values\", () => {\n const measurement1 = {\n type: 'custom',\n values: {\n a: 1,\n },\n };\n\n const measurement2 = {\n ...measurement1,\n type: 'web-vitals',\n };\n\n api.pushMeasurement(measurement1);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement2);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"filters a measurement and doesn't filter the next different one\", () => {\n const measurement1 = {\n type: 'custom',\n values: {\n a: 1,\n },\n };\n\n const measurement2 = {\n ...measurement1,\n type: 'web-vitals',\n };\n\n api.pushMeasurement(measurement1);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement1);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement2);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when dedupe is false\", () => {\n [api, transport] = createAPI({ dedupe: false });\n\n const measurement = {\n type: 'custom',\n values: {\n a: 1,\n },\n };\n\n api.pushMeasurement(measurement);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement);\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when skipDedupe is true\", () => {\n const measurement = {\n type: 'custom',\n values: {\n a: 1,\n },\n };\n\n api.pushMeasurement(measurement);\n expect(transport.items).toHaveLength(1);\n\n api.pushMeasurement(measurement, { skipDedupe: true });\n expect(transport.items).toHaveLength(2);\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n timestamp: string;\n trace?: TraceContext;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (\n // TODO: change this back once we have aligned the measurement event types: See: https://github.com/grafana/faro-web-sdk/issues/110\n payload: Omit<MeasurementEvent, 'timestamp'> & Partial<Pick<MeasurementEvent, 'timestamp'>>,\n options?: PushMeasurementOptions\n ) => void;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeMetaAPI = void 0;
|
|
4
|
+
var initialize_1 = require("./initialize");
|
|
5
|
+
Object.defineProperty(exports, "initializeMetaAPI", { enumerable: true, get: function () { return initialize_1.initializeMetaAPI; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|