@grafana/faro-core 2.0.0-beta → 2.0.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/dist/bundle/faro-core.iife.js +1 -1
- package/dist/bundle/types/api/index.d.ts +1 -1
- package/dist/bundle/types/api/userActions/const.d.ts +6 -4
- package/dist/bundle/types/api/userActions/index.d.ts +3 -2
- package/dist/bundle/types/api/userActions/initialize.d.ts +10 -2
- package/dist/bundle/types/api/userActions/types.d.ts +16 -6
- package/dist/bundle/types/api/userActions/userAction.d.ts +7 -15
- package/dist/bundle/types/config/types.d.ts +22 -22
- package/dist/bundle/types/index.d.ts +2 -2
- package/dist/bundle/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/bundle/types/version.d.ts +1 -1
- package/dist/cjs/api/events/initialize.js +2 -5
- package/dist/cjs/api/events/initialize.js.map +1 -1
- package/dist/cjs/api/exceptions/initialize.js +2 -5
- package/dist/cjs/api/exceptions/initialize.js.map +1 -1
- package/dist/cjs/api/index.js +2 -2
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/logs/const.js +1 -1
- package/dist/cjs/api/logs/const.js.map +1 -1
- package/dist/cjs/api/logs/initialize.js +2 -5
- package/dist/cjs/api/logs/initialize.js.map +1 -1
- package/dist/cjs/api/measurements/initialize.js +2 -5
- package/dist/cjs/api/measurements/initialize.js.map +1 -1
- package/dist/cjs/api/userActions/const.js +6 -6
- package/dist/cjs/api/userActions/const.js.map +1 -1
- package/dist/cjs/api/userActions/index.js +3 -3
- package/dist/cjs/api/userActions/index.js.map +1 -1
- package/dist/cjs/api/userActions/initialize.js +24 -2
- package/dist/cjs/api/userActions/initialize.js.map +1 -1
- package/dist/cjs/api/userActions/types.js.map +1 -1
- package/dist/cjs/api/userActions/userAction.js +7 -49
- package/dist/cjs/api/userActions/userAction.js.map +1 -1
- package/dist/cjs/config/types.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/transports/utils.js +4 -2
- package/dist/cjs/transports/utils.js.map +1 -1
- package/dist/cjs/utils/is.js +1 -1
- package/dist/cjs/utils/is.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/api/events/initialize.js +2 -5
- package/dist/esm/api/events/initialize.js.map +1 -1
- package/dist/esm/api/exceptions/initialize.js +2 -5
- package/dist/esm/api/exceptions/initialize.js.map +1 -1
- package/dist/esm/api/index.js +1 -1
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/logs/const.js +1 -1
- package/dist/esm/api/logs/const.js.map +1 -1
- package/dist/esm/api/logs/initialize.js +2 -5
- package/dist/esm/api/logs/initialize.js.map +1 -1
- package/dist/esm/api/measurements/initialize.js +2 -5
- package/dist/esm/api/measurements/initialize.js.map +1 -1
- package/dist/esm/api/userActions/const.js +5 -5
- package/dist/esm/api/userActions/const.js.map +1 -1
- package/dist/esm/api/userActions/index.js +3 -2
- package/dist/esm/api/userActions/index.js.map +1 -1
- package/dist/esm/api/userActions/initialize.js +24 -3
- package/dist/esm/api/userActions/initialize.js.map +1 -1
- package/dist/esm/api/userActions/types.js +1 -1
- package/dist/esm/api/userActions/types.js.map +1 -1
- package/dist/esm/api/userActions/userAction.js +8 -49
- package/dist/esm/api/userActions/userAction.js.map +1 -1
- package/dist/esm/config/types.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/transports/utils.js +4 -2
- package/dist/esm/transports/utils.js.map +1 -1
- package/dist/esm/utils/is.js +1 -1
- package/dist/esm/utils/is.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/initialize.js +2 -5
- package/dist/spec/core/src/api/events/initialize.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.js +2 -5
- package/dist/spec/core/src/api/exceptions/initialize.js.map +1 -1
- package/dist/spec/core/src/api/index.js +2 -2
- package/dist/spec/core/src/api/index.js.map +1 -1
- package/dist/spec/core/src/api/logs/const.js +1 -1
- package/dist/spec/core/src/api/logs/const.js.map +1 -1
- package/dist/spec/core/src/api/logs/initialize.js +2 -5
- package/dist/spec/core/src/api/logs/initialize.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.js +2 -5
- package/dist/spec/core/src/api/measurements/initialize.js.map +1 -1
- package/dist/spec/core/src/api/userActions/const.js +6 -6
- package/dist/spec/core/src/api/userActions/const.js.map +1 -1
- package/dist/spec/core/src/api/userActions/index.js +3 -3
- package/dist/spec/core/src/api/userActions/index.js.map +1 -1
- package/dist/spec/core/src/api/userActions/initialize.js +24 -2
- package/dist/spec/core/src/api/userActions/initialize.js.map +1 -1
- package/dist/spec/core/src/api/userActions/initialize.test.js +34 -8
- package/dist/spec/core/src/api/userActions/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/userActions/types.js.map +1 -1
- package/dist/spec/core/src/api/userActions/userAction.js +7 -49
- package/dist/spec/core/src/api/userActions/userAction.js.map +1 -1
- package/dist/spec/core/src/api/userActions/userAction.test.js +27 -14
- package/dist/spec/core/src/api/userActions/userAction.test.js.map +1 -1
- package/dist/spec/core/src/config/types.js.map +1 -1
- package/dist/spec/core/src/index.js +2 -2
- package/dist/spec/core/src/index.js.map +1 -1
- package/dist/spec/core/src/transports/utils.js +4 -2
- package/dist/spec/core/src/transports/utils.js.map +1 -1
- package/dist/spec/core/src/utils/is.js +1 -1
- package/dist/spec/core/src/utils/is.js.map +1 -1
- package/dist/spec/core/src/version.js +1 -1
- package/dist/spec/core/src/version.js.map +1 -1
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/userActions/const.d.ts +6 -4
- package/dist/types/api/userActions/index.d.ts +3 -2
- package/dist/types/api/userActions/initialize.d.ts +10 -2
- package/dist/types/api/userActions/types.d.ts +16 -6
- package/dist/types/api/userActions/userAction.d.ts +7 -15
- package/dist/types/config/types.d.ts +22 -22
- package/dist/types/core/src/api/index.d.ts +1 -1
- package/dist/types/core/src/api/userActions/const.d.ts +6 -4
- package/dist/types/core/src/api/userActions/index.d.ts +3 -2
- package/dist/types/core/src/api/userActions/initialize.d.ts +10 -2
- package/dist/types/core/src/api/userActions/types.d.ts +16 -6
- package/dist/types/core/src/api/userActions/userAction.d.ts +7 -15
- package/dist/types/core/src/config/types.d.ts +22 -22
- package/dist/types/core/src/index.d.ts +2 -2
- package/dist/types/core/src/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/core/src/version.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAcA,8DAsEC;AAjFD,+CAAqD;AAGrD,qCAAqG;AACrG,yCAAwD;AAGxD,wDAAsE;AAItE,SAAgB,yBAAyB,CAAC,EAezC;QAdC,cAAc,oBAAA,EACd,MAAM,YAAA,EACN,KAAK,WAAA,EACL,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA;IAUd,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,IAAI,WAAW,GAAiE,IAAI,CAAC;IAErF,IAAM,eAAe,GAAuC,UAC1D,OAAO,EACP,EAA+D;YAA/D,qBAA6D,EAAE,KAAA,EAA7D,UAAU,gBAAA,EAAE,OAAO,aAAA,EAAE,WAAW,iBAAA,EAAE,oBAAoB,0BAAA;QAExD,IAAI,CAAC;YACH,IAAM,GAAG,GAAG,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAC;YAE3C,IAAM,IAAI,GAAoC;gBAC5C,IAAI,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,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe,iBAAA;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItemType } from '../../transports';\nimport type { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport type { TracesAPI } from '../traces';\nimport type { UserActionsAPI } from '../userActions';\nimport { addItemToUserActionBuffer } from '../userActions/initialize';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI({\n internalLogger,\n config,\n metas,\n transports,\n tracesApi,\n userActionsApi,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n userActionsApi: UserActionsAPI;\n}): MeasurementsAPI {\n internalLogger.debug('Initializing measurements API');\n\n let lastPayload: Pick<MeasurementEvent, 'type' | 'values' | 'context'> | null = null;\n\n const pushMeasurement: MeasurementsAPI['pushMeasurement'] = (\n payload,\n { skipDedupe, context, spanContext, timestampOverwriteMs } = {}\n ) => {\n try {\n const ctx = stringifyObjectValues(context);\n\n const item: TransportItem<MeasurementEvent> = {\n type: TransportItemType.MEASUREMENT,\n payload: {\n ...payload,\n trace: spanContext\n ? {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n }\n : tracesApi.getTraceContext(),\n timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(),\n context: isEmpty(ctx) ? undefined : ctx,\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n type: item.payload.type,\n values: item.payload.values,\n context: item.payload.context,\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 if (!addItemToUserActionBuffer(userActionsApi.getActiveUserAction(), item)) {\n transports.execute(item);\n }\n } catch (err) {\n internalLogger.error('Error pushing measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.userActionEventName = exports.UserActionImportance = exports.userActionStart = exports.userActionStartByApiCallEventName = void 0;
|
|
4
4
|
exports.userActionStartByApiCallEventName = 'faroApiCall';
|
|
5
5
|
exports.userActionStart = 'user_action_start';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
exports.UserActionImportance = {
|
|
7
|
+
Normal: 'normal',
|
|
8
|
+
Critical: 'critical',
|
|
9
|
+
};
|
|
10
|
+
exports.userActionEventName = 'faro.user.action';
|
|
11
11
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../src/api/userActions/const.ts"],"names":[],"mappings":";;;AAAa,QAAA,iCAAiC,GAAG,aAAa,CAAC;AAElD,QAAA,eAAe,GAAG,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../src/api/userActions/const.ts"],"names":[],"mappings":";;;AAAa,QAAA,iCAAiC,GAAG,aAAa,CAAC;AAElD,QAAA,eAAe,GAAG,mBAAmB,CAAC;AAEtC,QAAA,oBAAoB,GAAG;IAClC,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAIE,QAAA,mBAAmB,GAAG,kBAAkB,CAAC","sourcesContent":["export const userActionStartByApiCallEventName = 'faroApiCall';\n\nexport const userActionStart = 'user_action_start';\n\nexport const UserActionImportance = {\n Normal: 'normal',\n Critical: 'critical',\n} as const;\n\nexport type UserActionImportanceType = (typeof UserActionImportance)[keyof typeof UserActionImportance];\n\nexport const userActionEventName = 'faro.user.action';\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userActionsMessageBus = exports.initializeUserActionsAPI = exports.
|
|
3
|
+
exports.userActionsMessageBus = exports.initializeUserActionsAPI = exports.UserActionState = exports.UserActionImportance = void 0;
|
|
4
|
+
var const_1 = require("./const");
|
|
5
|
+
Object.defineProperty(exports, "UserActionImportance", { enumerable: true, get: function () { return const_1.UserActionImportance; } });
|
|
4
6
|
var types_1 = require("./types");
|
|
5
7
|
Object.defineProperty(exports, "UserActionState", { enumerable: true, get: function () { return types_1.UserActionState; } });
|
|
6
|
-
var const_1 = require("./const");
|
|
7
|
-
Object.defineProperty(exports, "UserActionSeverity", { enumerable: true, get: function () { return const_1.UserActionSeverity; } });
|
|
8
8
|
var initialize_1 = require("./initialize");
|
|
9
9
|
Object.defineProperty(exports, "initializeUserActionsAPI", { enumerable: true, get: function () { return initialize_1.initializeUserActionsAPI; } });
|
|
10
10
|
Object.defineProperty(exports, "userActionsMessageBus", { enumerable: true, get: function () { return initialize_1.userActionsMessageBus; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/userActions/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/userActions/index.ts"],"names":[],"mappings":";;;AAAA,iCAA+C;AAAtC,6GAAA,oBAAoB,OAAA;AAE7B,iCAKiB;AAHf,wGAAA,eAAe,OAAA;AAKjB,2CAA+E;AAAtE,sHAAA,wBAAwB,OAAA;AAAE,mHAAA,qBAAqB,OAAA","sourcesContent":["export { UserActionImportance } from './const';\nexport { type UserActionImportance as UserActionImportanceType } from './const';\nexport {\n type UserActionsAPI,\n UserActionState,\n type UserActionInterface,\n type UserActionInternalInterface,\n} from './types';\n\nexport { initializeUserActionsAPI, userActionsMessageBus } from './initialize';\n"]}
|
|
@@ -5,14 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.userActionsMessageBus = void 0;
|
|
7
7
|
exports.initializeUserActionsAPI = initializeUserActionsAPI;
|
|
8
|
+
exports.addItemToUserActionBuffer = addItemToUserActionBuffer;
|
|
8
9
|
var reactive_1 = require("../../utils/reactive");
|
|
9
10
|
var const_1 = require("./const");
|
|
10
11
|
var types_1 = require("./types");
|
|
11
12
|
var userAction_1 = __importDefault(require("./userAction"));
|
|
12
13
|
exports.userActionsMessageBus = new reactive_1.Observable();
|
|
13
14
|
function initializeUserActionsAPI(_a) {
|
|
15
|
+
var _b;
|
|
14
16
|
var transports = _a.transports, internalLogger = _a.internalLogger, config = _a.config;
|
|
15
|
-
var trackUserActionsExcludeItem = config.
|
|
17
|
+
var trackUserActionsExcludeItem = (_b = config.userActionsInstrumentation) === null || _b === void 0 ? void 0 : _b.excludeItem;
|
|
16
18
|
// Currently running user action. It can be in either started or halted
|
|
17
19
|
// state
|
|
18
20
|
var activeUserAction;
|
|
@@ -26,6 +28,7 @@ function initializeUserActionsAPI(_a) {
|
|
|
26
28
|
transports: transports,
|
|
27
29
|
attributes: attributes,
|
|
28
30
|
trigger: (options === null || options === void 0 ? void 0 : options.triggerName) || const_1.userActionStartByApiCallEventName,
|
|
31
|
+
importance: (options === null || options === void 0 ? void 0 : options.importance) || const_1.UserActionImportance.Normal,
|
|
29
32
|
trackUserActionsExcludeItem: trackUserActionsExcludeItem,
|
|
30
33
|
});
|
|
31
34
|
userAction
|
|
@@ -49,9 +52,28 @@ function initializeUserActionsAPI(_a) {
|
|
|
49
52
|
var getActiveUserAction = function () {
|
|
50
53
|
return activeUserAction;
|
|
51
54
|
};
|
|
52
|
-
|
|
55
|
+
var api = {
|
|
53
56
|
startUserAction: startUserAction,
|
|
54
57
|
getActiveUserAction: getActiveUserAction,
|
|
55
58
|
};
|
|
59
|
+
return api;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Adds an item to the buffer associated with the given UserAction.
|
|
63
|
+
* The item will only be added if the UserAction is in the Started state.
|
|
64
|
+
* @param userAction The UserAction instance
|
|
65
|
+
* @param item The item to add to the buffer
|
|
66
|
+
* @returns {boolean} True if the item was added, false otherwise
|
|
67
|
+
*/
|
|
68
|
+
function addItemToUserActionBuffer(userAction, item) {
|
|
69
|
+
if (!userAction) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
var state = userAction === null || userAction === void 0 ? void 0 : userAction.getState();
|
|
73
|
+
if (state !== types_1.UserActionState.Started) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
userAction.addItem(item);
|
|
77
|
+
return true;
|
|
56
78
|
}
|
|
57
79
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/userActions/initialize.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/userActions/initialize.ts"],"names":[],"mappings":";;;;;;AAkBA,4DA+DC;AASD,8DAUC;AAlGD,iDAAkD;AAElD,iCAAmG;AACnG,iCAQiB;AACjB,4DAAsC;AAEzB,QAAA,qBAAqB,GAAG,IAAI,qBAAU,EAAqB,CAAC;AAEzE,SAAgB,wBAAwB,CAAC,EAQxC;;QAPC,UAAU,gBAAA,EACV,cAAc,oBAAA,EACd,MAAM,YAAA;IAMN,IAAM,2BAA2B,GAAG,MAAA,MAAM,CAAC,0BAA0B,0C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,eAAe,iBAAA;QACf,mBAAmB,qBAAA;KACpB,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CAAC,UAA2C,EAAE,IAAmB;IACxG,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAM,KAAK,GAAI,UAAqD,aAArD,UAAU,uBAAV,UAAU,CAA6C,QAAQ,EAAE,CAAC;IACjF,IAAI,KAAK,KAAK,uBAAe,CAAC,OAAO,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IACA,UAAuD,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { type InternalLogger, type TransportItem, type Transports } from '../..';\nimport type { Config } from '../../config';\nimport { Observable } from '../../utils/reactive';\n\nimport { UserActionImportance, userActionStart, userActionStartByApiCallEventName } from './const';\nimport {\n type StartUserActionOptions,\n type UserActionInterface,\n type UserActionInternalInterface,\n type UserActionMessage,\n type UserActionsAPI,\n UserActionState,\n type UserActionTransportItemBuffer,\n} from './types';\nimport UserAction from './userAction';\n\nexport const userActionsMessageBus = new Observable<UserActionMessage>();\n\nexport function initializeUserActionsAPI({\n transports,\n internalLogger,\n config,\n}: {\n transports: Transports;\n config: Config;\n internalLogger: InternalLogger;\n}): UserActionsAPI {\n const trackUserActionsExcludeItem = config.userActionsInstrumentation?.excludeItem;\n\n // Currently running user action. It can be in either started or halted\n // state\n let activeUserAction: UserAction | undefined;\n\n // If there is a an action already running, return undefined to indicate\n // we were not able to create one.\n const startUserAction: UserActionsAPI['startUserAction'] = (\n name: string,\n attributes?: Record<string, string>,\n options?: StartUserActionOptions\n ): UserActionInterface | undefined => {\n const currentRunningUserAction = getActiveUserAction();\n\n if (currentRunningUserAction === undefined) {\n const userAction = new UserAction({\n name,\n transports,\n attributes,\n trigger: options?.triggerName || userActionStartByApiCallEventName,\n importance: options?.importance || UserActionImportance.Normal,\n trackUserActionsExcludeItem,\n });\n userAction\n .filter((v) => [UserActionState.Ended, UserActionState.Cancelled].includes(v))\n .first()\n .subscribe(() => {\n activeUserAction = undefined;\n });\n\n userActionsMessageBus.notify({\n type: userActionStart,\n userAction: userAction,\n });\n activeUserAction = userAction;\n\n return activeUserAction;\n } else {\n internalLogger.error('Attempted to create a new user action while one is already running. This is not possible.');\n return undefined;\n }\n };\n\n const getActiveUserAction: UserActionsAPI['getActiveUserAction'] = (): UserActionInterface | undefined => {\n return activeUserAction;\n };\n\n const api: UserActionsAPI = {\n startUserAction,\n getActiveUserAction,\n };\n\n return api;\n}\n\n/**\n * Adds an item to the buffer associated with the given UserAction.\n * The item will only be added if the UserAction is in the Started state.\n * @param userAction The UserAction instance\n * @param item The item to add to the buffer\n * @returns {boolean} True if the item was added, false otherwise\n */\nexport function addItemToUserActionBuffer(userAction: UserActionInterface | undefined, item: TransportItem): boolean {\n if (!userAction) {\n return false;\n }\n const state = (userAction as unknown as UserActionInternalInterface)?.getState();\n if (state !== UserActionState.Started) {\n return false;\n }\n (userAction as unknown as UserActionTransportItemBuffer).addItem(item);\n return true;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/userActions/types.ts"],"names":[],"mappings":";;;AAIA,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,2DAAO,CAAA;IACP,yDAAM,CAAA;IACN,+DAAS,CAAA;IACT,uDAAK,CAAA;AACP,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B","sourcesContent":["import { type TransportItem } from '../../transports';\n\nimport {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/userActions/types.ts"],"names":[],"mappings":";;;AAIA,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,2DAAO,CAAA;IACP,yDAAM,CAAA;IACN,+DAAS,CAAA;IACT,uDAAK,CAAA;AACP,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B","sourcesContent":["import { type TransportItem } from '../../transports';\n\nimport { type UserActionImportanceType, userActionStartByApiCallEventName } from './const';\n\nexport enum UserActionState {\n Started,\n Halted,\n Cancelled,\n Ended,\n}\n\n/**\n * Public interface for the UserAction.\n * This is the interface that is part of the public API.\n */\nexport interface UserActionInterface {\n name: string;\n parentId: string;\n}\n\n/**\n * Internal interface for the UserAction.\n * This interface is intended for internal use only and not guaranteed to be stable.\n */\nexport interface UserActionInternalInterface extends UserActionInterface {\n halt(): void;\n end(attributes?: Record<string, string>): void;\n cancel(): void;\n getState(): UserActionState;\n}\n\nexport interface UserActionTransportItemBuffer {\n addItem(item: TransportItem): boolean;\n}\n\nexport type ApiUserActionEvent = {\n name: string;\n attributes?: Record<string, string>;\n type: typeof userActionStartByApiCallEventName | string;\n};\n\nexport type EndUserActionProps = {\n userActionName: string;\n startTime: number;\n endTime: number;\n actionId: string;\n event: ApiUserActionEvent;\n attributes?: Record<string, string>;\n};\n\nexport type StartUserActionOptions = {\n triggerName?: string;\n importance?: UserActionImportanceType;\n};\n\nexport interface UserActionsAPI {\n startUserAction: (\n name: string,\n attributes?: Record<string, string>,\n options?: StartUserActionOptions\n ) => UserActionInterface | undefined;\n getActiveUserAction: () => UserActionInterface | undefined;\n}\n\nexport type UserActionStart = {\n type: 'user_action_start';\n userAction: UserActionInterface;\n};\n\n// Union type\nexport type UserActionMessage = UserActionStart;\n"]}
|
|
@@ -32,71 +32,42 @@ var utils_1 = require("../../utils");
|
|
|
32
32
|
var ItemBuffer_1 = require("../ItemBuffer");
|
|
33
33
|
var const_1 = require("./const");
|
|
34
34
|
var types_1 = require("./types");
|
|
35
|
-
var defaultFollowUpActionTimeRange = 100;
|
|
36
|
-
var defaultHaltTimeout = 10 * 1000;
|
|
37
35
|
var UserAction = /** @class */ (function (_super) {
|
|
38
36
|
__extends(UserAction, _super);
|
|
39
37
|
function UserAction(_a) {
|
|
40
|
-
var name = _a.name, parentId = _a.parentId,
|
|
38
|
+
var name = _a.name, parentId = _a.parentId, trigger = _a.trigger, transports = _a.transports, attributes = _a.attributes, trackUserActionsExcludeItem = _a.trackUserActionsExcludeItem, _b = _a.importance, importance = _b === void 0 ? const_1.UserActionImportance.Normal : _b;
|
|
41
39
|
var _this = _super.call(this) || this;
|
|
42
40
|
_this.name = name;
|
|
43
41
|
_this.attributes = attributes;
|
|
44
42
|
_this.id = (0, utils_1.genShortID)();
|
|
45
43
|
_this.trigger = trigger;
|
|
46
|
-
_this.cancelTimeout = defaultFollowUpActionTimeRange;
|
|
47
|
-
_this.haltTimeout = haltTimeout !== null && haltTimeout !== void 0 ? haltTimeout : defaultHaltTimeout;
|
|
48
44
|
_this.parentId = parentId !== null && parentId !== void 0 ? parentId : _this.id;
|
|
49
45
|
_this.trackUserActionsExcludeItem = trackUserActionsExcludeItem;
|
|
50
|
-
_this.
|
|
46
|
+
_this.importance = importance;
|
|
51
47
|
_this._itemBuffer = new ItemBuffer_1.ItemBuffer();
|
|
52
48
|
_this._transports = transports;
|
|
53
|
-
_this._haltTimeoutId = -1;
|
|
54
49
|
_this._state = types_1.UserActionState.Started;
|
|
55
|
-
_this._isValid = false;
|
|
56
50
|
_this._start();
|
|
57
51
|
return _this;
|
|
58
52
|
}
|
|
59
53
|
UserAction.prototype.addItem = function (item) {
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!this._isValid) {
|
|
64
|
-
this._isValid = true;
|
|
54
|
+
if (this._state === types_1.UserActionState.Started) {
|
|
55
|
+
this._itemBuffer.addItem(item);
|
|
56
|
+
return true;
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
UserAction.prototype._setFollowupActionTimeout = function (haltPredicate) {
|
|
69
|
-
var _this = this;
|
|
70
|
-
this._timeoutId = startTimeout(this._timeoutId, function () {
|
|
71
|
-
if (_this._state === types_1.UserActionState.Started && (haltPredicate === null || haltPredicate === void 0 ? void 0 : haltPredicate())) {
|
|
72
|
-
_this.halt();
|
|
73
|
-
}
|
|
74
|
-
else if (_this._isValid) {
|
|
75
|
-
_this.end();
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
_this.cancel();
|
|
79
|
-
}
|
|
80
|
-
}, defaultFollowUpActionTimeRange);
|
|
58
|
+
return false;
|
|
81
59
|
};
|
|
82
60
|
UserAction.prototype._start = function () {
|
|
83
61
|
this._state = types_1.UserActionState.Started;
|
|
84
62
|
if (this._state === types_1.UserActionState.Started) {
|
|
85
63
|
this.startTime = (0, utils_1.dateNow)();
|
|
86
64
|
}
|
|
87
|
-
this._setFollowupActionTimeout();
|
|
88
65
|
};
|
|
89
66
|
UserAction.prototype.halt = function () {
|
|
90
|
-
var _this = this;
|
|
91
67
|
if (this._state !== types_1.UserActionState.Started) {
|
|
92
68
|
return;
|
|
93
69
|
}
|
|
94
70
|
this._state = types_1.UserActionState.Halted;
|
|
95
|
-
// If the halt timeout fires, we end the user action as
|
|
96
|
-
// it is still a valid one.
|
|
97
|
-
this._haltTimeoutId = setTimeout(function () {
|
|
98
|
-
_this.end();
|
|
99
|
-
}, this.haltTimeout);
|
|
100
71
|
this.notify(this._state);
|
|
101
72
|
};
|
|
102
73
|
UserAction.prototype.cancel = function () {
|
|
@@ -112,9 +83,6 @@ var UserAction = /** @class */ (function (_super) {
|
|
|
112
83
|
if (this._state === types_1.UserActionState.Cancelled) {
|
|
113
84
|
return;
|
|
114
85
|
}
|
|
115
|
-
// Make sure we don't end the user action twice
|
|
116
|
-
clearTimeout(this._haltTimeoutId);
|
|
117
|
-
clearTimeout(this._timeoutId);
|
|
118
86
|
var endTime = (0, utils_1.dateNow)();
|
|
119
87
|
var duration = endTime - this.startTime;
|
|
120
88
|
this._state = types_1.UserActionState.Ended;
|
|
@@ -131,7 +99,7 @@ var UserAction = /** @class */ (function (_super) {
|
|
|
131
99
|
});
|
|
132
100
|
this._state = types_1.UserActionState.Ended;
|
|
133
101
|
this.notify(this._state);
|
|
134
|
-
registerFaro_1.faro.api.pushEvent(
|
|
102
|
+
registerFaro_1.faro.api.pushEvent(const_1.userActionEventName, __assign({ userActionName: this.name, userActionStartTime: this.startTime.toString(), userActionEndTime: endTime.toString(), userActionDuration: duration.toString(), userActionTrigger: this.trigger, userActionImportance: this.importance }, (0, utils_1.stringifyObjectValues)(this.attributes)), undefined, {
|
|
135
103
|
timestampOverwriteMs: this.startTime,
|
|
136
104
|
customPayloadTransformer: function (payload) {
|
|
137
105
|
payload.action = {
|
|
@@ -152,14 +120,4 @@ function isExcludeFromUserAction(item, trackUserActionsExcludeItem) {
|
|
|
152
120
|
return ((trackUserActionsExcludeItem === null || trackUserActionsExcludeItem === void 0 ? void 0 : trackUserActionsExcludeItem(item)) ||
|
|
153
121
|
(item.type === transports_1.TransportItemType.MEASUREMENT && item.payload.type === 'web-vitals'));
|
|
154
122
|
}
|
|
155
|
-
function startTimeout(timeoutId, cb, delay) {
|
|
156
|
-
if (timeoutId) {
|
|
157
|
-
clearTimeout(timeoutId);
|
|
158
|
-
}
|
|
159
|
-
//@ts-expect-error for some reason vscode is using the node types
|
|
160
|
-
timeoutId = setTimeout(function () {
|
|
161
|
-
cb();
|
|
162
|
-
}, delay);
|
|
163
|
-
return timeoutId;
|
|
164
|
-
}
|
|
165
123
|
//# sourceMappingURL=userAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userAction.js","sourceRoot":"","sources":["../../../../src/api/userActions/userAction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uDAA8C;AAC9C,+CAA0F;AAC1F,qCAAqF;AACrF,4CAA2C;AAI3C,iCAA6C;AAC7C,iCAAwF;AAExF,IAAM,8BAA8B,GAAG,GAAG,CAAC;AAC3C,IAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC;IAAwC,8BAAU;IAmBhD,oBAAY,EAkBX;YAjBC,IAAI,UAAA,EACJ,QAAQ,cAAA,EACR,WAAW,iBAAA,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AK,CAAC,CAAC;IAEV,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { type Config } from '../../config';\nimport { faro } from '../../sdk/registerFaro';\nimport { type TransportItem, TransportItemType, type Transports } from '../../transports';\nimport { dateNow, genShortID, Observable, stringifyObjectValues } from '../../utils';\nimport { ItemBuffer } from '../ItemBuffer';\nimport { type MeasurementEvent } from '../measurements';\nimport { type APIEvent } from '../types';\n\nimport { UserActionSeverity } from './const';\nimport { type HaltPredicate, type UserActionInterface, UserActionState } from './types';\n\nconst defaultFollowUpActionTimeRange = 100;\nconst defaultHaltTimeout = 10 * 1000;\n\nexport default class UserAction extends Observable implements UserActionInterface {\n name: string;\n id: string;\n attributes?: Record<string, string>;\n parentId: string;\n trigger: string;\n severity: UserActionSeverity;\n startTime?: number;\n trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;\n cancelTimeout: number;\n haltTimeout: number;\n\n private _state: UserActionState;\n private _timeoutId?: number;\n private _itemBuffer: ItemBuffer<TransportItem>;\n private _transports: Transports;\n private _haltTimeoutId: any;\n private _isValid: boolean;\n\n constructor({\n name,\n parentId,\n haltTimeout,\n trigger,\n transports,\n attributes,\n trackUserActionsExcludeItem,\n severity = UserActionSeverity.Normal,\n }: {\n name: string;\n transports: Transports;\n parentId?: string;\n trigger: string;\n attributes?: Record<string, string>;\n haltTimeout?: number;\n trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;\n severity?: UserActionSeverity;\n }) {\n super();\n this.name = name;\n this.attributes = attributes;\n this.id = genShortID();\n this.trigger = trigger;\n this.cancelTimeout = defaultFollowUpActionTimeRange;\n this.haltTimeout = haltTimeout ?? defaultHaltTimeout;\n this.parentId = parentId ?? this.id;\n this.trackUserActionsExcludeItem = trackUserActionsExcludeItem;\n this.severity = severity;\n\n this._itemBuffer = new ItemBuffer<TransportItem>();\n this._transports = transports;\n this._haltTimeoutId = -1;\n this._state = UserActionState.Started;\n this._isValid = false;\n this._start();\n }\n\n addItem(item: TransportItem) {\n this._itemBuffer.addItem(item);\n }\n\n extend(haltPredicate?: HaltPredicate) {\n if (!this._isValid) {\n this._isValid = true;\n }\n this._setFollowupActionTimeout(haltPredicate);\n }\n\n private _setFollowupActionTimeout(haltPredicate?: HaltPredicate) {\n this._timeoutId = startTimeout(\n this._timeoutId,\n () => {\n if (this._state === UserActionState.Started && haltPredicate?.()) {\n this.halt();\n } else if (this._isValid) {\n this.end();\n } else {\n this.cancel();\n }\n },\n defaultFollowUpActionTimeRange\n );\n }\n\n private _start(): void {\n this._state = UserActionState.Started;\n if (this._state === UserActionState.Started) {\n this.startTime = dateNow();\n }\n this._setFollowupActionTimeout();\n }\n\n halt() {\n if (this._state !== UserActionState.Started) {\n return;\n }\n this._state = UserActionState.Halted;\n\n // If the halt timeout fires, we end the user action as\n // it is still a valid one.\n this._haltTimeoutId = setTimeout(() => {\n this.end();\n }, this.haltTimeout);\n this.notify(this._state);\n }\n\n cancel() {\n if (this._state === UserActionState.Started) {\n // Empty the buffer\n this._itemBuffer.flushBuffer();\n }\n\n this._state = UserActionState.Cancelled;\n this.notify(this._state);\n }\n\n end() {\n if (this._state === UserActionState.Cancelled) {\n return;\n }\n\n // Make sure we don't end the user action twice\n clearTimeout(this._haltTimeoutId);\n clearTimeout(this._timeoutId);\n\n const endTime = dateNow();\n const duration = endTime - this.startTime!;\n this._state = UserActionState.Ended;\n this._itemBuffer.flushBuffer((item) => {\n if (isExcludeFromUserAction(item, this.trackUserActionsExcludeItem)) {\n this._transports.execute(item);\n return;\n }\n\n const userActionItem = {\n ...item,\n payload: {\n ...item.payload,\n action: {\n parentId: this.id,\n name: this.name,\n },\n },\n } as TransportItem;\n\n this._transports.execute(userActionItem);\n });\n\n this._state = UserActionState.Ended;\n this.notify(this._state);\n\n faro.api.pushEvent(\n this.name,\n {\n userActionStartTime: this.startTime!.toString(),\n userActionEndTime: endTime.toString(),\n userActionDuration: duration.toString(),\n userActionTrigger: this.trigger!,\n userActionSeverity: this.severity,\n ...stringifyObjectValues(this.attributes),\n },\n undefined,\n {\n timestampOverwriteMs: this.startTime,\n customPayloadTransformer: (payload) => {\n payload.action = {\n id: this.id,\n name: this.name,\n };\n\n return payload;\n },\n }\n );\n }\n\n getState(): UserActionState {\n return this._state;\n }\n}\n\nfunction isExcludeFromUserAction(\n item: TransportItem<APIEvent>,\n trackUserActionsExcludeItem: Config['trackUserActionsExcludeItem']\n) {\n return (\n trackUserActionsExcludeItem?.(item) ||\n (item.type === TransportItemType.MEASUREMENT && (item.payload as MeasurementEvent).type === 'web-vitals')\n );\n}\n\nfunction startTimeout(timeoutId: number | undefined, cb: () => void, delay: number) {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n\n //@ts-expect-error for some reason vscode is using the node types\n timeoutId = setTimeout(() => {\n cb();\n }, delay);\n\n return timeoutId;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"userAction.js","sourceRoot":"","sources":["../../../../src/api/userActions/userAction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA8C;AAC9C,+CAA0F;AAC1F,qCAAqF;AACrF,4CAA2C;AAI3C,iCAAmG;AACnG,iCAAgH;AAEhH;IACU,8BAAU;IAgBlB,oBAAY,EAgBX;YAfC,IAAI,UAAA,EACJ,QAAQ,cAAA,EACR,OAAO,aAAA,EACP,UAAU,gBAAA,EACV,UAAU,gBAAA,EACV,2BAA2B,iCAAA,EAC3B,kBAAwC,EAAxC,UAAU,mBAAG,4BAAoB,CAAC,MAAM,KAAA;QAUxC,YAAA,MAAK,WAAE,SAAC;QACR,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,KAAI,CAAC,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;QACvB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,QAAQ,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,KAA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,EAChC,oBAAoB,EAAE,IAAI,CAAC,UAAU,IAClC,IAAA,6BAAqB,EAAC,IAAI,CAAC,UAAU,CAAC,GAE3C,SAAS,EACT;YACE,oBAAoB,EAAE,IAAI,CAAC,SAAS;YACpC,wBAAwB,EAAE,UAAC,OAAO;gBAChC,OAAO,CAAC,MAAM,GAAG;oBACf,EAAE,EAAE,KAAI,CAAC,EAAE;oBACX,IAAI,EAAE,KAAI,CAAC,IAAI;iBAChB,CAAC;gBAEF,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CACF,CAAC;IACJ,CAAC;IAED,6BAAQ,GAAR;QACE,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACH,iBAAC;AAAD,CAAC,AA9ID,CACU,kBAAU,GA6InB;;AAED,SAAS,uBAAuB,CAC9B,IAA6B,EAC7B,2BAAqF;IAErF,OAAO,CACL,CAAA,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAG,IAAI,CAAC;QACnC,CAAC,IAAI,CAAC,IAAI,KAAK,8BAAiB,CAAC,WAAW,IAAK,IAAI,CAAC,OAA4B,CAAC,IAAI,KAAK,YAAY,CAAC,CAC1G,CAAC;AACJ,CAAC","sourcesContent":["import { faro } from '../../sdk/registerFaro';\nimport { type TransportItem, TransportItemType, type Transports } from '../../transports';\nimport { dateNow, genShortID, Observable, stringifyObjectValues } from '../../utils';\nimport { ItemBuffer } from '../ItemBuffer';\nimport { type MeasurementEvent } from '../measurements';\nimport { type APIEvent } from '../types';\n\nimport { userActionEventName, UserActionImportance, type UserActionImportanceType } from './const';\nimport { type UserActionInternalInterface, UserActionState, type UserActionTransportItemBuffer } from './types';\n\nexport default class UserAction\n extends Observable\n implements UserActionInternalInterface, UserActionTransportItemBuffer\n{\n name: string;\n id: string;\n attributes?: Record<string, string>;\n parentId: string;\n trigger: string;\n importance: UserActionImportanceType;\n startTime?: number;\n trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;\n\n private _state: UserActionState;\n private _itemBuffer: ItemBuffer<TransportItem>;\n private _transports: Transports;\n\n constructor({\n name,\n parentId,\n trigger,\n transports,\n attributes,\n trackUserActionsExcludeItem,\n importance = UserActionImportance.Normal,\n }: {\n name: string;\n transports: Transports;\n parentId?: string;\n trigger: string;\n attributes?: Record<string, string>;\n trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;\n importance?: UserActionImportanceType;\n }) {\n super();\n this.name = name;\n this.attributes = attributes;\n this.id = genShortID();\n this.trigger = trigger;\n this.parentId = parentId ?? this.id;\n this.trackUserActionsExcludeItem = trackUserActionsExcludeItem;\n this.importance = importance;\n\n this._itemBuffer = new ItemBuffer<TransportItem>();\n this._transports = transports;\n this._state = UserActionState.Started;\n this._start();\n }\n\n addItem(item: TransportItem): boolean {\n if (this._state === UserActionState.Started) {\n this._itemBuffer.addItem(item);\n return true;\n }\n return false;\n }\n\n private _start(): void {\n this._state = UserActionState.Started;\n if (this._state === UserActionState.Started) {\n this.startTime = dateNow();\n }\n }\n\n halt() {\n if (this._state !== UserActionState.Started) {\n return;\n }\n this._state = UserActionState.Halted;\n this.notify(this._state);\n }\n\n cancel() {\n if (this._state === UserActionState.Started) {\n // Empty the buffer\n this._itemBuffer.flushBuffer();\n }\n\n this._state = UserActionState.Cancelled;\n this.notify(this._state);\n }\n\n end() {\n if (this._state === UserActionState.Cancelled) {\n return;\n }\n\n const endTime = dateNow();\n const duration = endTime - this.startTime!;\n this._state = UserActionState.Ended;\n this._itemBuffer.flushBuffer((item) => {\n if (isExcludeFromUserAction(item, this.trackUserActionsExcludeItem)) {\n this._transports.execute(item);\n return;\n }\n\n const userActionItem = {\n ...item,\n payload: {\n ...item.payload,\n action: {\n parentId: this.id,\n name: this.name,\n },\n },\n } as TransportItem;\n\n this._transports.execute(userActionItem);\n });\n\n this._state = UserActionState.Ended;\n this.notify(this._state);\n\n faro.api.pushEvent(\n userActionEventName,\n {\n userActionName: this.name,\n userActionStartTime: this.startTime!.toString(),\n userActionEndTime: endTime.toString(),\n userActionDuration: duration.toString(),\n userActionTrigger: this.trigger!,\n userActionImportance: this.importance,\n ...stringifyObjectValues(this.attributes),\n },\n undefined,\n {\n timestampOverwriteMs: this.startTime,\n customPayloadTransformer: (payload) => {\n payload.action = {\n id: this.id,\n name: this.name,\n };\n\n return payload;\n },\n }\n );\n }\n\n getState(): UserActionState {\n return this._state;\n }\n}\n\nfunction isExcludeFromUserAction(\n item: TransportItem<APIEvent>,\n trackUserActionsExcludeItem: ((item: TransportItem<APIEvent>) => boolean) | undefined\n) {\n return (\n trackUserActionsExcludeItem?.(item) ||\n (item.type === TransportItemType.MEASUREMENT && (item.payload as MeasurementEvent).type === 'web-vitals')\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { APIEvent, LogArgsSerializer, StacktraceParser } from '../api';\nimport type { Instrumentation } from '../instrumentations';\nimport type { InternalLoggerLevel } from '../internalLogger';\nimport type { Meta, MetaApp, MetaItem, MetaPage, MetaSession, MetaUser, MetaView } from '../metas';\nimport type { BatchExecutorOptions, BeforeSendHook, Transport, TransportItem } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\nimport type { LogLevel } from '../utils';\n\ntype SamplingContext = {\n metas: Meta;\n};\n\nexport interface Config<P = APIEvent> {\n /**\n * Application metadata\n */\n app: MetaApp;\n\n /**\n * Set max number and max interval for signals to be batched before sending\n */\n batching?: BatchExecutorOptions;\n\n /**\n * A flag for toggling deduplication for signals\n */\n dedupe: boolean;\n\n /**\n * The key (name) to use for the global Faro object (default: 'faro')\n */\n globalObjectKey: string;\n\n /**\n * The (custom) instrumentations to use with Faro\n */\n instrumentations: Instrumentation[];\n\n /**\n * The level of information printed to console for internal messages (default: LogLevel.ERROR)\n */\n internalLoggerLevel: InternalLoggerLevel;\n\n /**\n * Isolate Faro instance from other Faro instances on the same page. (default: false)\n */\n isolate: boolean;\n\n /**\n * Custom function to serialize log arguments\n */\n logArgsSerializer?: LogArgsSerializer;\n\n /**\n * Add custom Metas during Faro initialization\n */\n metas: MetaItem[];\n\n /**\n * Custom function used to parse stack traces\n */\n parseStacktrace: StacktraceParser;\n\n /**\n * Pause sending data (default: false)\n */\n paused: boolean;\n\n /**\n * Prevent Faro from exposing itself to the global object (default: false)\n */\n preventGlobalExposure: boolean;\n\n /**\n * The transports to use for sending beacons\n */\n transports: Transport[];\n\n /**\n * Some instrumentations might override the default console methods but Faro instance provides a\n * way to access the unmodified console methods.\n *\n * faro.unpatchedConsole.log('This is a log');\n * faro.unpatchedConsole.warn('This is a warning');\n */\n unpatchedConsole: UnpatchedConsole;\n\n /**\n * Function which invoked before pushing event to transport. Can be used to modify or filter events\n */\n beforeSend?: BeforeSendHook<P>;\n\n /**\n * Error message patterns for errors that should be ignored\n */\n ignoreErrors?: Patterns;\n\n /**\n * Path patterns for Endpoints that should be ignored form being tracked\n */\n ignoreUrls?: Patterns;\n\n /**\n * Configuration for the built in session tracker\n */\n sessionTracking?: {\n /**\n * Enable session tracking (default: true)\n */\n enabled?: boolean;\n /**\n * Wether to use sticky sessions (default: false)\n */\n persistent?: boolean;\n /**\n * Session metadata object to be used when initializing session tracking\n */\n session?: MetaSession;\n /**\n * How long is a sticky session valid for recurring users (default: 15 minutes)\n */\n maxSessionPersistenceTime?: number;\n /**\n * Called each time a session changes. This can be when a new session is created or when an existing session is updated.\n * @param oldSession\n * @param newSession\n */\n onSessionChange?: (oldSession: MetaSession | null, newSession: MetaSession) => void;\n /**\n * Then sampling rate for the session based sampler (default: 1). If a session is not part of a sample, no signals for this session are tracked.\n */\n samplingRate?: number;\n /**\n * Custom sampler function if custom sampling logic is needed.\n * @param context\n */\n sampler?: (context: SamplingContext) => number;\n /**\n * Custom function to generate session id. If available Faro uses this function instead of the internal one.\n */\n generateSessionId?: () => string;\n };\n\n /**\n * Meta object for user data\n */\n user?: MetaUser;\n\n /**\n * Meta object for view data\n */\n view?: MetaView;\n\n eventDomain?: string;\n\n /**\n * Only resource timings for fetch and xhr requests are tracked by default. Set this to true to track all resources (default: false).\n */\n trackResources?: boolean;\n\n /**\n *
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { APIEvent, LogArgsSerializer, StacktraceParser } from '../api';\nimport type { Instrumentation } from '../instrumentations';\nimport type { InternalLoggerLevel } from '../internalLogger';\nimport type { Meta, MetaApp, MetaItem, MetaPage, MetaSession, MetaUser, MetaView } from '../metas';\nimport type { BatchExecutorOptions, BeforeSendHook, Transport, TransportItem } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\nimport type { LogLevel } from '../utils';\n\ntype SamplingContext = {\n metas: Meta;\n};\n\nexport interface Config<P = APIEvent> {\n /**\n * Application metadata\n */\n app: MetaApp;\n\n /**\n * Set max number and max interval for signals to be batched before sending\n */\n batching?: BatchExecutorOptions;\n\n /**\n * A flag for toggling deduplication for signals\n */\n dedupe: boolean;\n\n /**\n * The key (name) to use for the global Faro object (default: 'faro')\n */\n globalObjectKey: string;\n\n /**\n * The (custom) instrumentations to use with Faro\n */\n instrumentations: Instrumentation[];\n\n /**\n * The level of information printed to console for internal messages (default: LogLevel.ERROR)\n */\n internalLoggerLevel: InternalLoggerLevel;\n\n /**\n * Isolate Faro instance from other Faro instances on the same page. (default: false)\n */\n isolate: boolean;\n\n /**\n * Custom function to serialize log arguments\n */\n logArgsSerializer?: LogArgsSerializer;\n\n /**\n * Add custom Metas during Faro initialization\n */\n metas: MetaItem[];\n\n /**\n * Custom function used to parse stack traces\n */\n parseStacktrace: StacktraceParser;\n\n /**\n * Pause sending data (default: false)\n */\n paused: boolean;\n\n /**\n * Prevent Faro from exposing itself to the global object (default: false)\n */\n preventGlobalExposure: boolean;\n\n /**\n * The transports to use for sending beacons\n */\n transports: Transport[];\n\n /**\n * Some instrumentations might override the default console methods but Faro instance provides a\n * way to access the unmodified console methods.\n *\n * faro.unpatchedConsole.log('This is a log');\n * faro.unpatchedConsole.warn('This is a warning');\n */\n unpatchedConsole: UnpatchedConsole;\n\n /**\n * Function which invoked before pushing event to transport. Can be used to modify or filter events\n */\n beforeSend?: BeforeSendHook<P>;\n\n /**\n * Error message patterns for errors that should be ignored\n */\n ignoreErrors?: Patterns;\n\n /**\n * Path patterns for Endpoints that should be ignored form being tracked\n */\n ignoreUrls?: Patterns;\n\n /**\n * Configuration for the built in session tracker\n */\n sessionTracking?: {\n /**\n * Enable session tracking (default: true)\n */\n enabled?: boolean;\n /**\n * Wether to use sticky sessions (default: false)\n */\n persistent?: boolean;\n /**\n * Session metadata object to be used when initializing session tracking\n */\n session?: MetaSession;\n /**\n * How long is a sticky session valid for recurring users (default: 15 minutes)\n */\n maxSessionPersistenceTime?: number;\n /**\n * Called each time a session changes. This can be when a new session is created or when an existing session is updated.\n * @param oldSession\n * @param newSession\n */\n onSessionChange?: (oldSession: MetaSession | null, newSession: MetaSession) => void;\n /**\n * Then sampling rate for the session based sampler (default: 1). If a session is not part of a sample, no signals for this session are tracked.\n */\n samplingRate?: number;\n /**\n * Custom sampler function if custom sampling logic is needed.\n * @param context\n */\n sampler?: (context: SamplingContext) => number;\n /**\n * Custom function to generate session id. If available Faro uses this function instead of the internal one.\n */\n generateSessionId?: () => string;\n };\n\n /**\n * Meta object for user data\n */\n user?: MetaUser;\n\n /**\n * Meta object for view data\n */\n view?: MetaView;\n\n eventDomain?: string;\n\n /**\n * Only resource timings for fetch and xhr requests are tracked by default. Set this to true to track all resources (default: false).\n */\n trackResources?: boolean;\n\n /**\n * Configuration for the web vitals instrumentation\n */\n webVitalsInstrumentation?: {\n /**\n * Report all changes for web vitals (default: false)\n *\n * In most cases, you only want the callback function to be called when the metric is ready to be reported.\n * However, it is possible to report every change (e.g. each larger layout shift as it happens)\n * by setting reportAllChanges to true.\n *\n * This can be useful when debugging, but in general using reportAllChanges is not needed (or recommended)\n * for measuring these metrics in production.\n */\n reportAllChanges?: boolean;\n };\n\n /**\n * Configuration for the console instrumentation\n */\n consoleInstrumentation?: {\n /**\n * Configure what console levels should be captured by Faro. By default the following levels\n * are disabled: console.debug, console.trace, console.log\n *\n * If you want to collect all levels set captureConsoleDisabledLevels: [];\n * If you want to disable only some levels set captureConsoleDisabledLevels: [LogLevel.DEBUG, LogLevel.TRACE];\n */\n disabledLevels?: LogLevel[];\n /*\n * By default, Faro sends an error for console.error calls. If you want to send a log instead, set this to true.\n */\n consoleErrorAsLog?: boolean;\n\n /**\n * If true, use the default Faro error serializer for console.error calls. If false, simply call toString() on the error arguments.\n * If enabled, payloads containing serialized errors may become very large. If left disabled, some error details may be lost.\n * (default: false)\n */\n serializeErrors?: boolean;\n\n /**\n * Custom function to serialize Error arguments\n */\n errorSerializer?: LogArgsSerializer;\n };\n\n /**\n * Configuration for the page tracking\n */\n pageTracking?: {\n /**\n * The page meta for initial page settings\n */\n page?: MetaPage;\n\n /**\n * Allows to provide a template for the page id\n */\n generatePageId?: (location: Location) => string;\n };\n\n /**\n * Enable or disable geolocation tracking.\n * Geolocation tracking must be enabled in the Grafana Cloud settings first.\n * It cannot be enabled solely on the client side.\n * This option allows control over tracking on the client side to comply with user\n * privacy requirements.\n */\n trackGeolocation?: boolean;\n\n /**\n * Configuration for the user actions instrumentation\n */\n userActionsInstrumentation?: {\n /**\n * Configure your own attribute name for tracking user actions. Default is 'data-faro-user-action-name'\n */\n dataAttributeName?: string;\n\n /**\n * Predicate function to exclude items from user actions.\n * If the function returns true, the item will be excluded from user actions.\n */\n excludeItem?: (item: TransportItem<APIEvent>) => boolean;\n };\n\n /**\n * When enabled, preserves the original Error object in the transport item for use in the beforeSend hook.\n * The original error is automatically removed before the item is sent to the transport.\n *\n * This is useful for error post-processing in (uncontrolled) environments where you need to handle special cases:\n * - Errors from third-party libraries\n * - Errors with missing or incomplete data\n * - Edge cases like `throw undefined` or `throw ''`\n *\n * With access to the original error in the beforeSend hook, you can enhance or modify the\n * Faro exception payload to include additional context or fix missing information.\n */\n preserveOriginalError?: boolean;\n\n /**\n * Configuration for experimental features.\n * These features have been tested thoroughly, but it is possible that they might not work as expected in all cases.\n */\n experimental?: {\n /**\n * Track navigation events.\n */\n trackNavigation?: boolean;\n };\n}\n\nexport type Patterns = Array<string | RegExp>;\n"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,13 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.isObject = exports.isNumber = exports.isNull = exports.isMapDefined = exports.isMap = exports.isInt = exports.isInstanceOf = exports.isFunction = exports.isEventDefined = exports.isEvent = exports.isErrorEvent = exports.isErrorDefined = exports.isError = exports.isElementDefined = exports.isElement = exports.isDomException = exports.isDomError = exports.isBoolean = exports.isArray = exports.getCurrentTimestamp = exports.genShortID = exports.defaultLogLevel = exports.deepEqual = exports.createPromiseBuffer = exports.allLogLevels = exports.defaultUnpatchedConsole = exports.transportItemTypeToBodyKey = exports.TransportItemType = exports.getTransportBody = exports.BaseTransport = exports.setInternalFaroOnGlobalObject = exports.isInternalFaroOnGlobalObject = exports.internalGlobalObjectKey = exports.getInternalFaroFromGlobalObject = exports.faro = exports.InternalLoggerLevel = exports.defaultInternalLoggerLevel = exports.createInternalLogger = exports.BaseInstrumentation = exports.defaultGlobalObjectKey = exports.defaultBatchingConfig = exports.initializeFaro = exports.globalObject = exports.BaseExtension = exports.userActionsMessageBus = exports.UserActionState = exports.
|
|
17
|
+
exports.isObject = exports.isNumber = exports.isNull = exports.isMapDefined = exports.isMap = exports.isInt = exports.isInstanceOf = exports.isFunction = exports.isEventDefined = exports.isEvent = exports.isErrorEvent = exports.isErrorDefined = exports.isError = exports.isElementDefined = exports.isElement = exports.isDomException = exports.isDomError = exports.isBoolean = exports.isArray = exports.getCurrentTimestamp = exports.genShortID = exports.defaultLogLevel = exports.deepEqual = exports.createPromiseBuffer = exports.allLogLevels = exports.defaultUnpatchedConsole = exports.transportItemTypeToBodyKey = exports.TransportItemType = exports.getTransportBody = exports.BaseTransport = exports.setInternalFaroOnGlobalObject = exports.isInternalFaroOnGlobalObject = exports.internalGlobalObjectKey = exports.getInternalFaroFromGlobalObject = exports.faro = exports.InternalLoggerLevel = exports.defaultInternalLoggerLevel = exports.createInternalLogger = exports.BaseInstrumentation = exports.defaultGlobalObjectKey = exports.defaultBatchingConfig = exports.initializeFaro = exports.globalObject = exports.BaseExtension = exports.userActionsMessageBus = exports.UserActionState = exports.UserActionImportance = exports.defaultErrorArgsSerializer = exports.defaultLogArgsSerializer = exports.defaultExceptionType = void 0;
|
|
18
18
|
exports.unknownString = exports.VERSION = exports.Observable = exports.stringifyObjectValues = exports.stringifyExternalJson = exports.getCircularDependencyReplacer = exports.isEmpty = exports.dateNow = exports.noop = exports.LogLevel = exports.isUndefined = exports.isTypeof = exports.isToString = exports.isThenable = exports.isSyntheticEvent = exports.isSymbol = exports.isString = exports.isRegExp = exports.isPrimitive = void 0;
|
|
19
19
|
var api_1 = require("./api");
|
|
20
20
|
Object.defineProperty(exports, "defaultExceptionType", { enumerable: true, get: function () { return api_1.defaultExceptionType; } });
|
|
21
21
|
Object.defineProperty(exports, "defaultLogArgsSerializer", { enumerable: true, get: function () { return api_1.defaultLogArgsSerializer; } });
|
|
22
22
|
Object.defineProperty(exports, "defaultErrorArgsSerializer", { enumerable: true, get: function () { return api_1.defaultErrorArgsSerializer; } });
|
|
23
|
-
Object.defineProperty(exports, "
|
|
23
|
+
Object.defineProperty(exports, "UserActionImportance", { enumerable: true, get: function () { return api_1.UserActionImportance; } });
|
|
24
24
|
Object.defineProperty(exports, "UserActionState", { enumerable: true, get: function () { return api_1.UserActionState; } });
|
|
25
25
|
Object.defineProperty(exports, "userActionsMessageBus", { enumerable: true, get: function () { return api_1.userActionsMessageBus; } });
|
|
26
26
|
var extensions_1 = require("./extensions");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,6BAQe;AAPb,2GAAA,oBAAoB,OAAA;AACpB,+GAAA,wBAAwB,OAAA;AACxB,iHAAA,0BAA0B,OAAA;AAC1B,2GAAA,oBAAoB,OAAA;AAEpB,sGAAA,eAAe,OAAA;AACf,4GAAA,qBAAqB,OAAA;AAmCvB,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AAGtB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,2CAA8C;AAArC,4GAAA,cAAc,OAAA;AAEvB,mCAAyE;AAAhE,+GAAA,qBAAqB,OAAA;AAAE,gHAAA,sBAAsB,OAAA;AAGtD,uDAAyD;AAAhD,uHAAA,mBAAmB,OAAA;AAG5B,mDAAyG;AAAhG,sHAAA,oBAAoB,OAAA;AAAE,4HAAA,0BAA0B,OAAA;AAAE,qHAAA,mBAAmB,OAAA;AAoB9E,6BAMe;AALb,2FAAA,IAAI,OAAA;AACJ,sHAAA,+BAA+B,OAAA;AAC/B,8GAAA,uBAAuB,OAAA;AACvB,mHAAA,4BAA4B,OAAA;AAC5B,oHAAA,6BAA6B,OAAA;AAI/B,6CAA2B;AAE3B,2CAA8G;AAArG,2GAAA,aAAa,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAAE,wHAAA,0BAA0B,OAAA;AAWvF,uDAA6D;AAApD,2HAAA,uBAAuB,OAAA;AAGhC,iCA2CiB;AA1Cf,qGAAA,YAAY,OAAA;AACZ,4GAAA,mBAAmB,OAAA;AACnB,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,4GAAA,mBAAmB,OAAA;AACnB,gGAAA,OAAO,OAAA;AACP,kGAAA,SAAS,OAAA;AACT,mGAAA,UAAU,OAAA;AACV,uGAAA,cAAc,OAAA;AACd,kGAAA,SAAS,OAAA;AACT,yGAAA,gBAAgB,OAAA;AAChB,gGAAA,OAAO,OAAA;AACP,uGAAA,cAAc,OAAA;AACd,qGAAA,YAAY,OAAA;AACZ,gGAAA,OAAO,OAAA;AACP,uGAAA,cAAc,OAAA;AACd,mGAAA,UAAU,OAAA;AACV,qGAAA,YAAY,OAAA;AACZ,8FAAA,KAAK,OAAA;AACL,8FAAA,KAAK,OAAA;AACL,qGAAA,YAAY,OAAA;AACZ,+FAAA,MAAM,OAAA;AACN,iGAAA,QAAQ,OAAA;AACR,iGAAA,QAAQ,OAAA;AACR,oGAAA,WAAW,OAAA;AACX,iGAAA,QAAQ,OAAA;AACR,iGAAA,QAAQ,OAAA;AACR,iGAAA,QAAQ,OAAA;AACR,yGAAA,gBAAgB,OAAA;AAChB,mGAAA,UAAU,OAAA;AACV,mGAAA,UAAU,OAAA;AACV,iGAAA,QAAQ,OAAA;AACR,oGAAA,WAAW,OAAA;AACX,iGAAA,QAAQ,OAAA;AACR,6FAAA,IAAI,OAAA;AACJ,gGAAA,OAAO,OAAA;AACP,gGAAA,OAAO,OAAA;AACP,sHAAA,6BAA6B,OAAA;AAC7B,8GAAA,qBAAqB,OAAA;AACrB,8GAAA,qBAAqB,OAAA;AACrB,mGAAA,UAAU,OAAA;AAcZ,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,mCAAyC;AAAhC,uGAAA,aAAa,OAAA","sourcesContent":["export {\n defaultExceptionType,\n defaultLogArgsSerializer,\n defaultErrorArgsSerializer,\n UserActionImportance,\n type UserActionImportanceType,\n UserActionState,\n userActionsMessageBus,\n} from './api';\nexport type {\n API,\n APIEvent,\n EventAttributes,\n EventEvent,\n EventsAPI,\n ExceptionEvent,\n ExceptionEventExtended,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n LogArgsSerializer,\n LogContext,\n LogEvent,\n LogsAPI,\n MeasurementEvent,\n MeasurementsAPI,\n MetaAPI,\n OTELApi,\n PushErrorOptions,\n PushEventOptions,\n PushLogOptions,\n PushMeasurementOptions,\n Stacktrace,\n StacktraceParser,\n TraceContext,\n TraceEvent,\n TracesAPI,\n UserAction,\n UserActionInterface,\n UserActionInternalInterface,\n} from './api';\n\nexport { BaseExtension } from './extensions';\nexport type { Extension } from './extensions';\n\nexport { globalObject } from './globalObject';\nexport type { GlobalObject } from './globalObject';\n\nexport { initializeFaro } from './initialize';\n\nexport { defaultBatchingConfig, defaultGlobalObjectKey } from './config';\nexport type { Config, Patterns } from './config';\n\nexport { BaseInstrumentation } from './instrumentations';\nexport type { Instrumentation, Instrumentations } from './instrumentations';\n\nexport { createInternalLogger, defaultInternalLoggerLevel, InternalLoggerLevel } from './internalLogger';\nexport type { InternalLogger } from './internalLogger';\n\nexport type {\n Meta,\n MetaApp,\n MetaAttributes,\n MetaBrowser,\n MetaGetter,\n MetaItem,\n MetaPage,\n Metas,\n MetaSDK,\n MetaSDKIntegration,\n MetaSession,\n MetaUser,\n MetaView,\n MetaOverrides,\n} from './metas';\n\nexport {\n faro,\n getInternalFaroFromGlobalObject,\n internalGlobalObjectKey,\n isInternalFaroOnGlobalObject,\n setInternalFaroOnGlobalObject,\n} from './sdk';\nexport type { Faro } from './sdk';\n\nexport * from './semantic';\n\nexport { BaseTransport, getTransportBody, TransportItemType, transportItemTypeToBodyKey } from './transports';\nexport type {\n BeforeSendHook,\n SendFn,\n Transport,\n TransportBody,\n TransportItem,\n TransportItemPayload,\n Transports,\n} from './transports';\n\nexport { defaultUnpatchedConsole } from './unpatchedConsole';\nexport type { UnpatchedConsole } from './unpatchedConsole';\n\nexport {\n allLogLevels,\n createPromiseBuffer,\n deepEqual,\n defaultLogLevel,\n genShortID,\n getCurrentTimestamp,\n isArray,\n isBoolean,\n isDomError,\n isDomException,\n isElement,\n isElementDefined,\n isError,\n isErrorDefined,\n isErrorEvent,\n isEvent,\n isEventDefined,\n isFunction,\n isInstanceOf,\n isInt,\n isMap,\n isMapDefined,\n isNull,\n isNumber,\n isObject,\n isPrimitive,\n isRegExp,\n isString,\n isSymbol,\n isSyntheticEvent,\n isThenable,\n isToString,\n isTypeof,\n isUndefined,\n LogLevel,\n noop,\n dateNow,\n isEmpty,\n getCircularDependencyReplacer,\n stringifyExternalJson,\n stringifyObjectValues,\n Observable,\n} from './utils';\nexport type {\n BaseObject,\n BaseObjectKey,\n BaseObjectPrimitiveValue,\n BaseObjectValue,\n BufferItem,\n PromiseBuffer,\n PromiseBufferOptions,\n PromiseProducer,\n Subscription,\n} from './utils';\n\nexport { VERSION } from './version';\n\nexport { unknownString } from './consts';\n"]}
|
|
@@ -56,14 +56,16 @@ function getTransportBody(item) {
|
|
|
56
56
|
case const_1.TransportItemType.LOG:
|
|
57
57
|
case const_1.TransportItemType.EVENT:
|
|
58
58
|
case const_1.TransportItemType.EXCEPTION:
|
|
59
|
-
case const_1.TransportItemType.MEASUREMENT:
|
|
59
|
+
case const_1.TransportItemType.MEASUREMENT: {
|
|
60
60
|
var bk = const_1.transportItemTypeToBodyKey[currentItem.type];
|
|
61
61
|
var signals = body[bk];
|
|
62
62
|
body = __assign(__assign({}, body), (_a = {}, _a[bk] = signals === undefined ? [currentItem.payload] : __spreadArray(__spreadArray([], signals, true), [currentItem.payload], false), _a));
|
|
63
63
|
break;
|
|
64
|
-
|
|
64
|
+
}
|
|
65
|
+
case const_1.TransportItemType.TRACE: {
|
|
65
66
|
body = __assign(__assign({}, body), { traces: mergeResourceSpans(body.traces, currentItem.payload.resourceSpans) });
|
|
66
67
|
break;
|
|
68
|
+
}
|
|
67
69
|
}
|
|
68
70
|
});
|
|
69
71
|
return body;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transports/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAOA,gDA4BC;AAED,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transports/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAOA,gDA4BC;AAED,4CAmCC;AApED,iCAAwE;AAGxE,SAAgB,kBAAkB,CAAC,MAAmB,EAAE,aAAgC;;IACtF,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO;YACL,aAAa,eAAA;SACd,CAAC;IACJ,CAAC;IAED,IAAM,eAAe,GAAG,MAAA,MAAM,CAAC,aAAa,0CAAG,CAAC,CAAC,CAAC;IAClD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAM,YAAY,GAAG,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,UAAU,KAAI,EAAE,CAAC;IACvD,IAAM,QAAQ,GAAG,CAAA,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAG,CAAC,CAAC,0CAAE,UAAU,KAAI,EAAE,CAAC;IAEtD,6BACK,MAAM,KACT,aAAa,EAAE;kCAER,eAAe,KAClB,UAAU,kCAAM,YAAY,SAAK,QAAQ;SAE5C,IACD;AACJ,CAAC;AAED,SAAgB,gBAAgB,CAAC,IAAqB;IACpD,IAAI,IAAI,GAAkB;QACxB,IAAI,EAAE,EAAE;KACT,CAAC;IAEF,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,UAAC,WAA0B;;QACtC,QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,KAAK,yBAAiB,CAAC,GAAG,CAAC;YAC3B,KAAK,yBAAiB,CAAC,KAAK,CAAC;YAC7B,KAAK,yBAAiB,CAAC,SAAS,CAAC;YACjC,KAAK,yBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;gBACnC,IAAM,EAAE,GAAG,kCAA0B,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBACxD,IAAM,OAAO,GAAG,IAAI,CAAC,EAAE,CAAsE,CAAC;gBAE9F,IAAI,yBACC,IAAI,gBACN,EAAE,IAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,iCAAK,OAAO,UAAE,WAAW,CAAC,OAAO,SAAC,MACxF,CAAC;gBACF,MAAM;YACR,CAAC;YACD,KAAK,yBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7B,IAAI,yBACC,IAAI,KACP,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAG,WAAW,CAAC,OAAsB,CAAC,aAAa,CAAC,GAC3F,CAAC;gBACF,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { IResourceSpans } from '@opentelemetry/otlp-transformer/build/src/trace/internal-types';\n\nimport type { EventEvent, ExceptionEvent, LogEvent, MeasurementEvent, TraceEvent } from '..';\n\nimport { TransportItemType, transportItemTypeToBodyKey } from './const';\nimport type { TransportBody, TransportItem } from './types';\n\nexport function mergeResourceSpans(traces?: TraceEvent, resourceSpans?: IResourceSpans[]): TraceEvent | undefined {\n if (resourceSpans === undefined) {\n return traces;\n }\n\n if (traces === undefined) {\n return {\n resourceSpans,\n };\n }\n\n const currentResource = traces.resourceSpans?.[0];\n if (currentResource === undefined) {\n return traces;\n }\n\n const currentSpans = currentResource?.scopeSpans || [];\n const newSpans = resourceSpans?.[0]?.scopeSpans || [];\n\n return {\n ...traces,\n resourceSpans: [\n {\n ...currentResource,\n scopeSpans: [...currentSpans, ...newSpans],\n },\n ],\n };\n}\n\nexport function getTransportBody(item: TransportItem[]): TransportBody {\n let body: TransportBody = {\n meta: {},\n };\n\n if (item[0] !== undefined) {\n body.meta = item[0].meta;\n }\n\n item.forEach((currentItem: TransportItem) => {\n switch (currentItem.type) {\n case TransportItemType.LOG:\n case TransportItemType.EVENT:\n case TransportItemType.EXCEPTION:\n case TransportItemType.MEASUREMENT: {\n const bk = transportItemTypeToBodyKey[currentItem.type];\n const signals = body[bk] as LogEvent[] | EventEvent[] | ExceptionEvent[] | MeasurementEvent[];\n\n body = {\n ...body,\n [bk]: signals === undefined ? [currentItem.payload] : [...signals, currentItem.payload],\n };\n break;\n }\n case TransportItemType.TRACE: {\n body = {\n ...body,\n traces: mergeResourceSpans(body.traces, (currentItem.payload as TraceEvent).resourceSpans),\n };\n break;\n }\n }\n });\n\n return body;\n}\n"]}
|
package/dist/cjs/utils/is.js
CHANGED
package/dist/cjs/utils/is.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.js","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":";;;AAEA,4BAEC;AAED,gCAEC;AAED,oCAMC;AA2DD,0BAcC;AAvFD,SAAgB,QAAQ,CAAc,KAAc,EAAE,IAAY;IAChE,OAAO,OAAO,KAAK,KAAK,IAAI,CAAC;AAC/B,CAAC;AAED,SAAgB,UAAU,CAAc,KAAc,EAAE,IAAY;IAClE,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,kBAAW,IAAI,MAAG,CAAC;AACtE,CAAC;AAED,SAAgB,YAAY,CAA2B,KAAc,EAAE,SAAY;IACjF,IAAI,CAAC;QACH,OAAO,KAAK,YAAY,SAAS,CAAC;IACpC,CAAC;IAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"is.js","sourceRoot":"","sources":["../../../src/utils/is.ts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,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,IAAA,eAAO,EAAC,KAAK,CAAC,IAAI,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["export type IsFnHelper<T = unknown> = (value: unknown) => value is T;\n\nexport function isTypeof<T = unknown>(value: unknown, type: string): value is T {\n return typeof value === type;\n}\n\nexport function isToString<T = unknown>(value: unknown, type: string): value is T {\n return Object.prototype.toString.call(value) === `[object ${type}]`;\n}\n\nexport function isInstanceOf<T extends Function = any>(value: unknown, reference: T): value is T {\n try {\n return value instanceof reference;\n } catch (_err) {\n return false;\n }\n}\n\nexport const isUndefined = ((value) => isTypeof(value, 'undefined')) as IsFnHelper<undefined>;\n\nexport const isNull = ((value) => isTypeof(value, 'null')) as IsFnHelper<null>;\n\nexport const isString = ((value) => isTypeof(value, 'string')) as IsFnHelper<string>;\n\nexport const isNumber = ((value) =>\n (isTypeof<number>(value, 'number') && !isNaN(value)) || isTypeof(value, 'bigint')) as IsFnHelper<number | bigint>;\n\nexport const isInt = ((value) => isNumber(value) && Number.isInteger(value)) as IsFnHelper<number>;\n\nexport const isBoolean = ((value) => isTypeof(value, 'boolean')) as IsFnHelper<boolean>;\n\nexport const isSymbol = ((value) => isTypeof(value, 'symbol')) as IsFnHelper<Symbol>;\n\nexport const isObject = ((value) => !isNull(value) && isTypeof(value, 'object')) as IsFnHelper<object>;\n\nexport const isFunction = ((value) => isTypeof(value, 'function')) as IsFnHelper<Function>;\n\nexport const isArray = ((value) => isToString(value, 'Array')) as IsFnHelper<unknown[]>;\n\nexport const isRegExp = ((value) => isToString(value, 'RegExp')) as IsFnHelper<string>;\n\nexport const isThenable = ((value) => isFunction((value as any)?.then)) as IsFnHelper<{ then: Function }>;\n\nexport const isPrimitive = ((value) => !isObject(value) && !isFunction(value)) as IsFnHelper<\n string | number | bigint | boolean | symbol\n>;\n\nexport const isEventDefined = typeof Event !== 'undefined';\n\nexport const isEvent = ((value) => isEventDefined && isInstanceOf(value, Event)) as IsFnHelper<Event>;\n\nexport const isErrorDefined = typeof Error !== 'undefined';\n\nexport const isError = ((value) => isErrorDefined && isInstanceOf(value, Error)) as IsFnHelper<Error>;\n\nexport const isErrorEvent = ((value) => isToString(value, 'ErrorEvent')) as IsFnHelper<ErrorEvent>;\n\nexport const isDomError = ((value) => isToString(value, 'DOMError')) as IsFnHelper<DOMException>;\n\nexport const isDomException = ((value) => isToString(value, 'DOMException')) as IsFnHelper<DOMException>;\n\nexport const isElementDefined = typeof Element !== 'undefined';\n\nexport const isElement = ((value) => isElementDefined && isInstanceOf(value, Element)) as IsFnHelper<Element>;\n\nexport const isMapDefined = typeof Map !== 'undefined';\n\nexport const isMap = ((value) => isMapDefined && isInstanceOf(value, Map)) as IsFnHelper<Map<any, any>>;\n\nexport const isSyntheticEvent = ((value: unknown) =>\n isObject(value) &&\n 'nativeEvent' in value &&\n 'preventDefault' in value &&\n 'stopPropagation' in value) as unknown as IsFnHelper<Event>;\n\nexport function isEmpty(value: any): boolean {\n if (value == null) {\n return true;\n }\n\n if (isArray(value) || isString(value)) {\n return value.length === 0;\n }\n\n if (isObject(value)) {\n return Object.keys(value).length === 0;\n }\n\n return false;\n}\n"]}
|
package/dist/cjs/version.js
CHANGED
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACzB,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACzB,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.0.2';\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TransportItemType } from '../../transports';
|
|
2
2
|
import { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';
|
|
3
3
|
import { timestampToIsoString } from '../../utils/date';
|
|
4
|
+
import { addItemToUserActionBuffer } from '../userActions/initialize';
|
|
4
5
|
export function initializeEventsAPI({ internalLogger, config, metas, transports, tracesApi, userActionsApi, }) {
|
|
5
6
|
let lastPayload = null;
|
|
6
7
|
const pushEvent = (name, attributes, domain, { skipDedupe, spanContext, timestampOverwriteMs, customPayloadTransformer = (payload) => payload } = {}) => {
|
|
@@ -33,11 +34,7 @@ export function initializeEventsAPI({ internalLogger, config, metas, transports,
|
|
|
33
34
|
}
|
|
34
35
|
lastPayload = testingPayload;
|
|
35
36
|
internalLogger.debug('Pushing event\n', item);
|
|
36
|
-
|
|
37
|
-
if (currentUserAction) {
|
|
38
|
-
currentUserAction.addItem(item);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
37
|
+
if (!addItemToUserActionBuffer(userActionsApi.getActiveUserAction(), item)) {
|
|
41
38
|
transports.execute(item);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/events/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../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C,eAAe,EAAE;iBAChC,CAAC;gBACF,IAAI,EAAE,iBAAiB,CAAC,KAAK;aAC9B,CAAC;YAEF,MAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;gBACnC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC;gBACnG,cAAc,CAAC,KAAK,CAAC,8DAA8D,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEnG,OAAO;YACT,CAAC;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YAE9C,IAAI,CAAC,yBAAyB,CAAC,cAAc,CAAC,mBAAmB,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;gBAC3E,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItemType } from '../../transports';\nimport type { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport type { TracesAPI } from '../traces';\nimport type { UserActionsAPI } from '../userActions';\nimport { addItemToUserActionBuffer } from '../userActions/initialize';\n\nimport type { EventEvent, EventsAPI } from './types';\n\nexport function initializeEventsAPI({\n internalLogger,\n config,\n metas,\n transports,\n tracesApi,\n userActionsApi,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n userActionsApi: UserActionsAPI;\n}): EventsAPI {\n let lastPayload: Pick<EventEvent, 'name' | 'domain' | 'attributes'> | null = null;\n\n const pushEvent: EventsAPI['pushEvent'] = (\n name,\n attributes,\n domain,\n { skipDedupe, spanContext, timestampOverwriteMs, customPayloadTransformer = (payload: EventEvent) => payload } = {}\n ) => {\n try {\n const attrs = stringifyObjectValues(attributes);\n\n const item: TransportItem<EventEvent> = {\n meta: metas.value,\n payload: customPayloadTransformer({\n name,\n domain: domain ?? config.eventDomain,\n attributes: isEmpty(attrs) ? undefined : attrs,\n timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(),\n trace: spanContext\n ? {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n }\n : tracesApi.getTraceContext(),\n }),\n type: TransportItemType.EVENT,\n };\n\n const testingPayload = {\n name: item.payload.name,\n attributes: item.payload.attributes,\n domain: item.payload.domain,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping event 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 event\\n', item);\n\n if (!addItemToUserActionBuffer(userActionsApi.getActiveUserAction(), item)) {\n transports.execute(item);\n }\n } catch (err) {\n internalLogger.error('Error pushing event', err);\n }\n };\n\n return {\n pushEvent,\n };\n}\n"]}
|