@grafana/faro-core 1.19.0 → 2.0.0-beta-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/apiTestHelpers.d.ts +2 -0
- package/dist/bundle/types/api/events/initialize.d.ts +4 -6
- package/dist/bundle/types/api/exceptions/initialize.d.ts +4 -6
- package/dist/bundle/types/api/index.d.ts +2 -3
- package/dist/bundle/types/api/initialize.d.ts +1 -3
- package/dist/bundle/types/api/logs/initialize.d.ts +4 -6
- package/dist/bundle/types/api/measurements/initialize.d.ts +4 -6
- package/dist/bundle/types/api/meta/initialize.d.ts +1 -5
- package/dist/bundle/types/api/types.d.ts +3 -44
- package/dist/bundle/types/api/userActions/const.d.ts +6 -0
- package/dist/bundle/types/api/userActions/index.d.ts +3 -0
- package/dist/bundle/types/api/userActions/initialize.d.ts +10 -0
- package/dist/bundle/types/api/userActions/types.d.ts +45 -0
- package/dist/bundle/types/api/userActions/userAction.d.ts +41 -0
- package/dist/bundle/types/index.d.ts +2 -2
- package/dist/bundle/types/semantic.d.ts +0 -14
- package/dist/bundle/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/bundle/types/version.d.ts +1 -1
- package/dist/cjs/api/apiTestHelpers.js +5 -1
- package/dist/cjs/api/apiTestHelpers.js.map +1 -1
- package/dist/cjs/api/events/initialize.js +4 -5
- package/dist/cjs/api/events/initialize.js.map +1 -1
- package/dist/cjs/api/exceptions/initialize.js +6 -7
- package/dist/cjs/api/exceptions/initialize.js.map +1 -1
- package/dist/cjs/api/index.js +5 -8
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/initialize.js +8 -8
- package/dist/cjs/api/initialize.js.map +1 -1
- package/dist/cjs/api/logs/initialize.js +6 -7
- package/dist/cjs/api/logs/initialize.js.map +1 -1
- package/dist/cjs/api/measurements/initialize.js +4 -5
- package/dist/cjs/api/measurements/initialize.js.map +1 -1
- package/dist/cjs/api/meta/initialize.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/api/userActions/const.js +11 -0
- package/dist/cjs/api/userActions/const.js.map +1 -0
- package/dist/cjs/api/userActions/index.js +11 -0
- package/dist/cjs/api/userActions/index.js.map +1 -0
- package/dist/cjs/api/userActions/initialize.js +57 -0
- package/dist/cjs/api/userActions/initialize.js.map +1 -0
- package/dist/cjs/api/userActions/types.js +11 -0
- package/dist/cjs/api/userActions/types.js.map +1 -0
- package/dist/cjs/api/userActions/userAction.js +165 -0
- package/dist/cjs/api/userActions/userAction.js.map +1 -0
- package/dist/cjs/index.js +5 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/semantic.js +1 -15
- package/dist/cjs/semantic.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/api/apiTestHelpers.js +4 -0
- package/dist/esm/api/apiTestHelpers.js.map +1 -1
- package/dist/esm/api/events/initialize.js +4 -5
- package/dist/esm/api/events/initialize.js.map +1 -1
- package/dist/esm/api/exceptions/initialize.js +4 -5
- package/dist/esm/api/exceptions/initialize.js.map +1 -1
- package/dist/esm/api/index.js +1 -2
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/initialize.js +8 -7
- package/dist/esm/api/initialize.js.map +1 -1
- package/dist/esm/api/logs/initialize.js +4 -5
- package/dist/esm/api/logs/initialize.js.map +1 -1
- package/dist/esm/api/measurements/initialize.js +4 -5
- package/dist/esm/api/measurements/initialize.js.map +1 -1
- package/dist/esm/api/meta/initialize.js.map +1 -1
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/api/userActions/const.js +8 -0
- package/dist/esm/api/userActions/const.js.map +1 -0
- package/dist/esm/api/userActions/index.js +4 -0
- package/dist/esm/api/userActions/index.js.map +1 -0
- package/dist/esm/api/userActions/initialize.js +50 -0
- package/dist/esm/api/userActions/initialize.js.map +1 -0
- package/dist/esm/api/userActions/types.js +10 -0
- package/dist/esm/api/userActions/types.js.map +1 -0
- package/dist/esm/api/userActions/userAction.js +132 -0
- package/dist/esm/api/userActions/userAction.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/semantic.js +0 -14
- package/dist/esm/semantic.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/apiTestHelpers.js +5 -1
- package/dist/spec/core/src/api/apiTestHelpers.js.map +1 -1
- package/dist/spec/core/src/api/events/initialize.js +4 -5
- package/dist/spec/core/src/api/events/initialize.js.map +1 -1
- package/dist/spec/core/src/api/events/initialize.test.js +11 -33
- package/dist/spec/core/src/api/events/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.js +6 -7
- package/dist/spec/core/src/api/exceptions/initialize.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.test.js +24 -52
- package/dist/spec/core/src/api/exceptions/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/index.js +5 -8
- package/dist/spec/core/src/api/index.js.map +1 -1
- package/dist/spec/core/src/api/initialize.js +8 -8
- package/dist/spec/core/src/api/initialize.js.map +1 -1
- package/dist/spec/core/src/api/initialize.test.js +0 -50
- package/dist/spec/core/src/api/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/logs/initialize.js +6 -7
- package/dist/spec/core/src/api/logs/initialize.js.map +1 -1
- package/dist/spec/core/src/api/logs/initialize.test.js +12 -73
- package/dist/spec/core/src/api/logs/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.js +4 -5
- package/dist/spec/core/src/api/measurements/initialize.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.test.js +10 -72
- package/dist/spec/core/src/api/measurements/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/meta/initialize.js.map +1 -1
- package/dist/spec/core/src/api/types.js.map +1 -1
- package/dist/spec/core/src/api/userActions/const.js +11 -0
- package/dist/spec/core/src/api/userActions/const.js.map +1 -0
- package/dist/spec/core/src/api/userActions/index.js +11 -0
- package/dist/spec/core/src/api/userActions/index.js.map +1 -0
- package/dist/spec/core/src/api/userActions/initialize.js +57 -0
- package/dist/spec/core/src/api/userActions/initialize.js.map +1 -0
- package/dist/spec/core/src/api/userActions/initialize.test.js +62 -0
- package/dist/spec/core/src/api/userActions/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/userActions/types.js +11 -0
- package/dist/spec/core/src/api/userActions/types.js.map +1 -0
- package/dist/spec/core/src/api/userActions/userAction.js +165 -0
- package/dist/spec/core/src/api/userActions/userAction.js.map +1 -0
- package/dist/spec/core/src/api/userActions/userAction.test.js +75 -0
- package/dist/spec/core/src/api/userActions/userAction.test.js.map +1 -0
- package/dist/spec/core/src/index.js +5 -7
- package/dist/spec/core/src/index.js.map +1 -1
- package/dist/spec/core/src/semantic.js +1 -15
- package/dist/spec/core/src/semantic.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/apiTestHelpers.d.ts +2 -0
- package/dist/types/api/events/initialize.d.ts +4 -6
- package/dist/types/api/exceptions/initialize.d.ts +4 -6
- package/dist/types/api/index.d.ts +2 -3
- package/dist/types/api/initialize.d.ts +1 -3
- package/dist/types/api/logs/initialize.d.ts +4 -6
- package/dist/types/api/measurements/initialize.d.ts +4 -6
- package/dist/types/api/meta/initialize.d.ts +1 -5
- package/dist/types/api/types.d.ts +3 -44
- package/dist/types/api/userActions/const.d.ts +6 -0
- package/dist/types/api/userActions/index.d.ts +3 -0
- package/dist/types/api/userActions/initialize.d.ts +10 -0
- package/dist/types/api/userActions/types.d.ts +45 -0
- package/dist/types/api/userActions/userAction.d.ts +41 -0
- package/dist/types/core/src/api/apiTestHelpers.d.ts +2 -0
- package/dist/types/core/src/api/events/initialize.d.ts +4 -6
- package/dist/types/core/src/api/exceptions/initialize.d.ts +4 -6
- package/dist/types/core/src/api/index.d.ts +2 -3
- package/dist/types/core/src/api/initialize.d.ts +1 -3
- package/dist/types/core/src/api/logs/initialize.d.ts +4 -6
- package/dist/types/core/src/api/measurements/initialize.d.ts +4 -6
- package/dist/types/core/src/api/meta/initialize.d.ts +1 -5
- package/dist/types/core/src/api/types.d.ts +3 -44
- package/dist/types/core/src/api/userActions/const.d.ts +6 -0
- package/dist/types/core/src/api/userActions/index.d.ts +3 -0
- package/dist/types/core/src/api/userActions/initialize.d.ts +10 -0
- package/dist/types/core/src/api/userActions/types.d.ts +45 -0
- package/dist/types/core/src/api/userActions/userAction.d.ts +41 -0
- package/dist/types/core/src/api/userActions/userAction.test.d.ts +1 -0
- package/dist/types/core/src/index.d.ts +2 -2
- package/dist/types/core/src/semantic.d.ts +0 -14
- 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/semantic.d.ts +0 -14
- package/dist/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/dist/bundle/types/api/const.d.ts +0 -4
- package/dist/bundle/types/api/userActionLifecycleHandler.d.ts +0 -13
- package/dist/cjs/api/const.js +0 -8
- package/dist/cjs/api/const.js.map +0 -1
- package/dist/cjs/api/userActionLifecycleHandler.js +0 -58
- package/dist/cjs/api/userActionLifecycleHandler.js.map +0 -1
- package/dist/esm/api/const.js +0 -5
- package/dist/esm/api/const.js.map +0 -1
- package/dist/esm/api/userActionLifecycleHandler.js +0 -43
- package/dist/esm/api/userActionLifecycleHandler.js.map +0 -1
- package/dist/spec/core/src/api/const.js +0 -8
- package/dist/spec/core/src/api/const.js.map +0 -1
- package/dist/spec/core/src/api/userActionLifecycleHandler.js +0 -58
- package/dist/spec/core/src/api/userActionLifecycleHandler.js.map +0 -1
- package/dist/spec/core/src/api/userActionLifecycleHandler.test.js +0 -169
- package/dist/spec/core/src/api/userActionLifecycleHandler.test.js.map +0 -1
- package/dist/types/api/const.d.ts +0 -4
- package/dist/types/api/userActionLifecycleHandler.d.ts +0 -13
- package/dist/types/core/src/api/const.d.ts +0 -4
- package/dist/types/core/src/api/userActionLifecycleHandler.d.ts +0 -13
- /package/dist/types/core/src/api/{userActionLifecycleHandler.test.d.ts → userActions/initialize.test.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/userActions/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,MAAM,OAAO,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAKL,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,UAAU,EAAqB,CAAC;AAEzE,MAAM,UAAU,wBAAwB,CAAC,EACvC,UAAU,EACV,cAAc,EACd,MAAM,GAKP;IACC,MAAM,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC;IAEvE,uEAAuE;IACvE,QAAQ;IACR,IAAI,gBAAwC,CAAC;IAE7C,wEAAwE;IACxE,kCAAkC;IAClC,MAAM,eAAe,GAAsC,CACzD,IAAY,EACZ,UAAmC,EACnC,OAAgC,EACC,EAAE;QACnC,MAAM,wBAAwB,GAAG,mBAAmB,EAAE,CAAC;QAEvD,IAAI,wBAAwB,KAAK,SAAS,EAAE,CAAC;YAC3C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;gBAChC,IAAI;gBACJ,UAAU;gBACV,UAAU;gBACV,OAAO,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,iCAAiC;gBAClE,2BAA2B;aAC5B,CAAC,CAAC;YACH,UAAU;iBACP,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;iBAC7E,KAAK,EAAE;iBACP,SAAS,CAAC,GAAG,EAAE;gBACd,gBAAgB,GAAG,SAAS,CAAC;YAC/B,CAAC,CAAC,CAAC;YAEL,qBAAqB,CAAC,MAAM,CAAC;gBAC3B,IAAI,EAAE,eAAe;gBACrB,UAAU,EAAE,UAAU;aACvB,CAAC,CAAC;YACH,gBAAgB,GAAG,UAAU,CAAC;YAC9B,OAAO,gBAAgB,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,cAAc,CAAC,KAAK,CAAC,2FAA2F,CAAC,CAAC;YAClH,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAA0C,GAAoC,EAAE;QACvG,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,eAAe;QACf,mBAAmB;KACpB,CAAC;AACJ,CAAC","sourcesContent":["import { type InternalLogger, type Transports } from '../..';\nimport type { Config } from '../../config';\nimport { Observable } from '../../utils/reactive';\n\nimport { userActionStart, userActionStartByApiCallEventName } from './const';\nimport {\n type StartUserActionOptions,\n type UserActionInterface,\n type UserActionMessage,\n type UserActionsAPI,\n UserActionState,\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.trackUserActionsExcludeItem;\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 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 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 return {\n startUserAction,\n getActiveUserAction,\n };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '../../transports';
|
|
2
|
+
import { UserActionSeverity, userActionStartByApiCallEventName } from './const';
|
|
3
|
+
export var UserActionState;
|
|
4
|
+
(function (UserActionState) {
|
|
5
|
+
UserActionState[UserActionState["Started"] = 0] = "Started";
|
|
6
|
+
UserActionState[UserActionState["Halted"] = 1] = "Halted";
|
|
7
|
+
UserActionState[UserActionState["Cancelled"] = 2] = "Cancelled";
|
|
8
|
+
UserActionState[UserActionState["Ended"] = 3] = "Ended";
|
|
9
|
+
})(UserActionState || (UserActionState = {}));
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/userActions/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAEhF,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,2DAAO,CAAA;IACP,yDAAM,CAAA;IACN,+DAAS,CAAA;IACT,uDAAK,CAAA;AACP,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B","sourcesContent":["import { type TransportItem } from '../../transports';\n\nimport { UserActionSeverity, userActionStartByApiCallEventName } from './const';\n\nexport enum UserActionState {\n Started,\n Halted,\n Cancelled,\n Ended,\n}\n\nexport type HaltPredicate = () => boolean;\n\nexport interface UserActionInterface {\n name: string;\n parentId: string;\n\n addItem(item: TransportItem): void;\n extend(haltPredicate?: HaltPredicate): void;\n end(attributes?: Record<string, string>): void;\n halt(reason?: string): void;\n cancel(): void;\n getState(): UserActionState;\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 severity?: UserActionSeverity;\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"]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {} from '../../config';
|
|
2
|
+
import { faro } from '../../sdk/registerFaro';
|
|
3
|
+
import { TransportItemType } from '../../transports';
|
|
4
|
+
import { dateNow, genShortID, Observable, stringifyObjectValues } from '../../utils';
|
|
5
|
+
import { ItemBuffer } from '../ItemBuffer';
|
|
6
|
+
import {} from '../measurements';
|
|
7
|
+
import {} from '../types';
|
|
8
|
+
import { UserActionSeverity } from './const';
|
|
9
|
+
import { UserActionState } from './types';
|
|
10
|
+
const defaultFollowUpActionTimeRange = 100;
|
|
11
|
+
const defaultHaltTimeout = 10 * 1000;
|
|
12
|
+
export default class UserAction extends Observable {
|
|
13
|
+
constructor({ name, parentId, haltTimeout, trigger, transports, attributes, trackUserActionsExcludeItem, severity = UserActionSeverity.Normal, }) {
|
|
14
|
+
super();
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.attributes = attributes;
|
|
17
|
+
this.id = genShortID();
|
|
18
|
+
this.trigger = trigger;
|
|
19
|
+
this.cancelTimeout = defaultFollowUpActionTimeRange;
|
|
20
|
+
this.haltTimeout = haltTimeout !== null && haltTimeout !== void 0 ? haltTimeout : defaultHaltTimeout;
|
|
21
|
+
this.parentId = parentId !== null && parentId !== void 0 ? parentId : this.id;
|
|
22
|
+
this.trackUserActionsExcludeItem = trackUserActionsExcludeItem;
|
|
23
|
+
this.severity = severity;
|
|
24
|
+
this._itemBuffer = new ItemBuffer();
|
|
25
|
+
this._transports = transports;
|
|
26
|
+
this._haltTimeoutId = -1;
|
|
27
|
+
this._state = UserActionState.Started;
|
|
28
|
+
this._isValid = false;
|
|
29
|
+
this._start();
|
|
30
|
+
}
|
|
31
|
+
addItem(item) {
|
|
32
|
+
this._itemBuffer.addItem(item);
|
|
33
|
+
}
|
|
34
|
+
extend(haltPredicate) {
|
|
35
|
+
if (!this._isValid) {
|
|
36
|
+
this._isValid = true;
|
|
37
|
+
}
|
|
38
|
+
this._setFollowupActionTimeout(haltPredicate);
|
|
39
|
+
}
|
|
40
|
+
_setFollowupActionTimeout(haltPredicate) {
|
|
41
|
+
this._timeoutId = startTimeout(this._timeoutId, () => {
|
|
42
|
+
if (this._state === UserActionState.Started && (haltPredicate === null || haltPredicate === void 0 ? void 0 : haltPredicate())) {
|
|
43
|
+
this.halt();
|
|
44
|
+
}
|
|
45
|
+
else if (this._isValid) {
|
|
46
|
+
this.end();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.cancel();
|
|
50
|
+
}
|
|
51
|
+
}, defaultFollowUpActionTimeRange);
|
|
52
|
+
}
|
|
53
|
+
_start() {
|
|
54
|
+
this._state = UserActionState.Started;
|
|
55
|
+
if (this._state === UserActionState.Started) {
|
|
56
|
+
this.startTime = dateNow();
|
|
57
|
+
}
|
|
58
|
+
this._setFollowupActionTimeout();
|
|
59
|
+
}
|
|
60
|
+
halt() {
|
|
61
|
+
if (this._state !== UserActionState.Started) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this._state = UserActionState.Halted;
|
|
65
|
+
// If the halt timeout fires, we end the user action as
|
|
66
|
+
// it is still a valid one.
|
|
67
|
+
this._haltTimeoutId = setTimeout(() => {
|
|
68
|
+
this.end();
|
|
69
|
+
}, this.haltTimeout);
|
|
70
|
+
this.notify(this._state);
|
|
71
|
+
}
|
|
72
|
+
cancel() {
|
|
73
|
+
if (this._state === UserActionState.Started) {
|
|
74
|
+
// Empty the buffer
|
|
75
|
+
this._itemBuffer.flushBuffer();
|
|
76
|
+
}
|
|
77
|
+
this._state = UserActionState.Cancelled;
|
|
78
|
+
this.notify(this._state);
|
|
79
|
+
}
|
|
80
|
+
end() {
|
|
81
|
+
if (this._state === UserActionState.Cancelled) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Make sure we don't end the user action twice
|
|
85
|
+
clearTimeout(this._haltTimeoutId);
|
|
86
|
+
clearTimeout(this._timeoutId);
|
|
87
|
+
const endTime = dateNow();
|
|
88
|
+
const duration = endTime - this.startTime;
|
|
89
|
+
this._state = UserActionState.Ended;
|
|
90
|
+
this._itemBuffer.flushBuffer((item) => {
|
|
91
|
+
if (isExcludeFromUserAction(item, this.trackUserActionsExcludeItem)) {
|
|
92
|
+
this._transports.execute(item);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const userActionItem = Object.assign(Object.assign({}, item), { payload: Object.assign(Object.assign({}, item.payload), { action: {
|
|
96
|
+
parentId: this.id,
|
|
97
|
+
name: this.name,
|
|
98
|
+
} }) });
|
|
99
|
+
this._transports.execute(userActionItem);
|
|
100
|
+
});
|
|
101
|
+
this._state = UserActionState.Ended;
|
|
102
|
+
this.notify(this._state);
|
|
103
|
+
faro.api.pushEvent(this.name, Object.assign({ userActionStartTime: this.startTime.toString(), userActionEndTime: endTime.toString(), userActionDuration: duration.toString(), userActionTrigger: this.trigger, userActionSeverity: this.severity }, stringifyObjectValues(this.attributes)), undefined, {
|
|
104
|
+
timestampOverwriteMs: this.startTime,
|
|
105
|
+
customPayloadTransformer: (payload) => {
|
|
106
|
+
payload.action = {
|
|
107
|
+
id: this.id,
|
|
108
|
+
name: this.name,
|
|
109
|
+
};
|
|
110
|
+
return payload;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
getState() {
|
|
115
|
+
return this._state;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function isExcludeFromUserAction(item, trackUserActionsExcludeItem) {
|
|
119
|
+
return ((trackUserActionsExcludeItem === null || trackUserActionsExcludeItem === void 0 ? void 0 : trackUserActionsExcludeItem(item)) ||
|
|
120
|
+
(item.type === TransportItemType.MEASUREMENT && item.payload.type === 'web-vitals'));
|
|
121
|
+
}
|
|
122
|
+
function startTimeout(timeoutId, cb, delay) {
|
|
123
|
+
if (timeoutId) {
|
|
124
|
+
clearTimeout(timeoutId);
|
|
125
|
+
}
|
|
126
|
+
//@ts-expect-error for some reason vscode is using the node types
|
|
127
|
+
timeoutId = setTimeout(() => {
|
|
128
|
+
cb();
|
|
129
|
+
}, delay);
|
|
130
|
+
return timeoutId;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=userAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAction.js","sourceRoot":"","sources":["../../../../src/api/userActions/userAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAsB,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EA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Y,CAAC,SAA6B,EAAE,EAAc,EAAE,KAAa;IAChF,IAAI,SAAS,EAAE,CAAC;QACd,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;IAED,iEAAiE;IACjE,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;QAC1B,EAAE,EAAE,CAAC;IACP,CAAC,EAAE,KAAK,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"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defaultExceptionType, defaultLogArgsSerializer, defaultErrorArgsSerializer,
|
|
1
|
+
export { defaultExceptionType, defaultLogArgsSerializer, defaultErrorArgsSerializer, UserActionSeverity, UserActionState, userActionsMessageBus, } from './api';
|
|
2
2
|
export { BaseExtension } from './extensions';
|
|
3
3
|
export { globalObject } from './globalObject';
|
|
4
4
|
export { initializeFaro } from './initialize';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,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AI,EACJ,OAAO,EACP,OAAO,EACP,6BAA6B,EAC7B,qBAAqB,EACrB,qBAAqB,EACrB,UAAU,GACX,MAAM,SAAS,CAAC;AAajB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export {\n defaultExceptionType,\n defaultLogArgsSerializer,\n defaultErrorArgsSerializer,\n UserActionSeverity,\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} 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"]}
|
package/dist/esm/semantic.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated The conventions object will be removed in a future version
|
|
3
|
-
*/
|
|
4
|
-
export const Conventions = {
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated The event names object will be removed in a future version
|
|
7
|
-
*/
|
|
8
|
-
EventNames: {
|
|
9
|
-
CLICK: 'click',
|
|
10
|
-
NAVIGATION: 'navigation',
|
|
11
|
-
SESSION_START: 'session_start',
|
|
12
|
-
VIEW_CHANGED: 'view_changed',
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
1
|
export const EVENT_CLICK = 'click';
|
|
16
2
|
export const EVENT_NAVIGATION = 'navigation';
|
|
17
3
|
export const EVENT_VIEW_CHANGED = 'view_changed';
|
package/dist/esm/semantic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../src/semantic.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../src/semantic.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AACnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,4BAA4B,GAAG,uBAAuB,CAAC;AACpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC","sourcesContent":["export const EVENT_CLICK = 'click';\nexport const EVENT_NAVIGATION = 'navigation';\nexport const EVENT_VIEW_CHANGED = 'view_changed';\nexport const EVENT_SESSION_START = 'session_start';\nexport const EVENT_SESSION_RESUME = 'session_resume';\nexport const EVENT_SESSION_EXTEND = 'session_extend';\nexport const EVENT_OVERRIDES_SERVICE_NAME = 'service_name_override';\nexport const EVENT_ROUTE_CHANGE = 'route_change';\n"]}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.0.0-beta-2';\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockTracesApi = exports.mockTransports = exports.mockMetas = void 0;
|
|
3
|
+
exports.mockUserActionsApi = exports.mockTracesApi = exports.mockTransports = exports.mockMetas = void 0;
|
|
4
4
|
exports.mockMetas = {
|
|
5
5
|
add: jest.fn(),
|
|
6
6
|
remove: jest.fn(),
|
|
@@ -33,4 +33,8 @@ exports.mockTracesApi = {
|
|
|
33
33
|
isOTELInitialized: jest.fn(),
|
|
34
34
|
pushTraces: jest.fn(),
|
|
35
35
|
};
|
|
36
|
+
exports.mockUserActionsApi = {
|
|
37
|
+
startUserAction: jest.fn(),
|
|
38
|
+
getActiveUserAction: jest.fn(),
|
|
39
|
+
};
|
|
36
40
|
//# sourceMappingURL=apiTestHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiTestHelpers.js","sourceRoot":"","sources":["../../../../../src/api/apiTestHelpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"apiTestHelpers.js","sourceRoot":"","sources":["../../../../../src/api/apiTestHelpers.ts"],"names":[],"mappings":";;;AAKa,QAAA,SAAS,GAAG;IACvB,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;IACtB,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;IACzB,KAAK,EAAE,EAAE;CACV,CAAC;AAEW,QAAA,cAAc,GAAe;IACxC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,kBAAkB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC7B,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,kBAAkB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC7B,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,qBAAqB,EAAE,IAAI,CAAC,EAAE,EAAE;IAChC,QAAQ,EAAE;QACR,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,UAAU,EAAE,EAAE;IACd,KAAK,EAAE;QACL,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE;QACP,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;CACF,CAAC;AAEW,QAAA,aAAa,GAAc;IACtC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE;IAC1B,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;IACnB,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC5B,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;CACtB,CAAC;AAEW,QAAA,kBAAkB,GAAmB;IAChD,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE;IAC1B,mBAAmB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC/B,CAAC","sourcesContent":["import type { Transports } from '../transports';\n\nimport type { TracesAPI } from './traces/types';\nimport type { UserActionsAPI } from './userActions/types';\n\nexport const mockMetas = {\n add: jest.fn(),\n remove: jest.fn(),\n addListener: jest.fn(),\n removeListener: jest.fn(),\n value: {},\n};\n\nexport const mockTransports: Transports = {\n add: jest.fn(),\n addBeforeSendHooks: jest.fn(),\n execute: jest.fn(),\n getBeforeSendHooks: jest.fn(),\n remove: jest.fn(),\n removeBeforeSendHooks: jest.fn(),\n isPaused: function (): boolean {\n throw new Error('Function not implemented.');\n },\n transports: [],\n pause: function (): void {\n throw new Error('Function not implemented.');\n },\n unpause: function (): void {\n throw new Error('Function not implemented.');\n },\n};\n\nexport const mockTracesApi: TracesAPI = {\n getOTEL: jest.fn(),\n getTraceContext: jest.fn(),\n initOTEL: jest.fn(),\n isOTELInitialized: jest.fn(),\n pushTraces: jest.fn(),\n};\n\nexport const mockUserActionsApi: UserActionsAPI = {\n startUserAction: jest.fn(),\n getActiveUserAction: jest.fn(),\n};\n"]}
|
|
@@ -4,9 +4,8 @@ exports.initializeEventsAPI = initializeEventsAPI;
|
|
|
4
4
|
var transports_1 = require("../../transports");
|
|
5
5
|
var utils_1 = require("../../utils");
|
|
6
6
|
var date_1 = require("../../utils/date");
|
|
7
|
-
var const_1 = require("../const");
|
|
8
7
|
function initializeEventsAPI(_a) {
|
|
9
|
-
var internalLogger = _a.internalLogger, config = _a.config, metas = _a.metas, transports = _a.transports, tracesApi = _a.tracesApi,
|
|
8
|
+
var internalLogger = _a.internalLogger, config = _a.config, metas = _a.metas, transports = _a.transports, tracesApi = _a.tracesApi, userActionsApi = _a.userActionsApi;
|
|
10
9
|
var lastPayload = null;
|
|
11
10
|
var pushEvent = function (name, attributes, domain, _a) {
|
|
12
11
|
var _b = _a === void 0 ? {} : _a, skipDedupe = _b.skipDedupe, spanContext = _b.spanContext, timestampOverwriteMs = _b.timestampOverwriteMs, _c = _b.customPayloadTransformer, customPayloadTransformer = _c === void 0 ? function (payload) { return payload; } : _c;
|
|
@@ -39,9 +38,9 @@ function initializeEventsAPI(_a) {
|
|
|
39
38
|
}
|
|
40
39
|
lastPayload = testingPayload;
|
|
41
40
|
internalLogger.debug('Pushing event\n', item);
|
|
42
|
-
var
|
|
43
|
-
if (
|
|
44
|
-
|
|
41
|
+
var currentUserAction = userActionsApi.getActiveUserAction();
|
|
42
|
+
if (currentUserAction) {
|
|
43
|
+
currentUserAction.addItem(item);
|
|
45
44
|
}
|
|
46
45
|
else {
|
|
47
46
|
transports.execute(item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../../src/api/events/initialize.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../../src/api/events/initialize.ts"],"names":[],"mappings":";;AAaA,kDA0EC;AApFD,+CAAqD;AAGrD,qCAAqG;AACrG,yCAAwD;AAMxD,SAAgB,mBAAmB,CAAC,EAenC;QAdC,cAAc,oBAAA,EACd,MAAM,YAAA,EACN,KAAK,WAAA,EACL,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA;IAUd,IAAI,WAAW,GAA8D,IAAI,CAAC;IAElF,IAAM,SAAS,GAA2B,UACxC,IAAI,EACJ,UAAU,EACV,MAAM,EACN,EAAmH;YAAnH,qBAAiH,EAAE,KAAA,EAAjH,UAAU,gBAAA,EAAE,WAAW,iBAAA,EAAE,oBAAoB,0BAAA,EAAE,gCAA2D,EAA3D,wBAAwB,mBAAG,UAAC,OAAmB,IAAK,OAAA,OAAO,EAAP,CAAO,KAAA;QAE5G,IAAI,CAAC;YACH,IAAM,KAAK,GAAG,IAAA,6BAAqB,EAAC,UAAU,CAAC,CAAC;YAEhD,IAAM,IAAI,GAA8B;gBACtC,IAAI,EAAE,KAAK,CAAC,KAAK;gBACjB,OAAO,EAAE,wBAAwB,CAAC;oBAChC,IAAI,MAAA;oBACJ,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,MAAM,CAAC,WAAW;oBACpC,UAAU,EAAE,IAAA,eAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK;oBAC9C,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,IAAA,2BAAoB,EAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,IAAA,2BAAmB,GAAE;oBACpG,KAAK,EAAE,WAAW;wBAChB,CAAC,CAAC;4BACE,QAAQ,EAAE,WAAW,CAAC,OAAO;4BAC7B,OAAO,EAAE,WAAW,CAAC,MAAM;yBAC5B;wBACH,CAAC,CAAC,SAAS,CAAC,eAAe,EAAE;iBAChC,CAAC;gBACF,IAAI,EAAE,8BAAiB,CAAC,KAAK;aAC9B,CAAC;YAEF,IAAM,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,IAAA,cAAM,EAAC,WAAW,CAAC,IAAI,IAAA,iBAAS,EAAC,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,IAAM,iBAAiB,GAAG,cAAc,CAAC,mBAAmB,EAAE,CAAC;YAC/D,IAAI,iBAAiB,EAAE,CAAC;gBACtB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,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,WAAA;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';\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 const currentUserAction = userActionsApi.getActiveUserAction();\n if (currentUserAction) {\n currentUserAction.addItem(item);\n } else {\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"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
var initialize_1 = require("../../initialize");
|
|
4
7
|
var testUtils_1 = require("../../testUtils");
|
|
5
|
-
var utils_1 = require("../../utils");
|
|
6
8
|
var apiTestHelpers_1 = require("../apiTestHelpers");
|
|
7
|
-
var
|
|
8
|
-
var ItemBuffer_1 = require("../ItemBuffer");
|
|
9
|
+
var userAction_1 = __importDefault(require("../userActions/userAction"));
|
|
9
10
|
var initialize_2 = require("./initialize");
|
|
10
11
|
describe('api.events', function () {
|
|
11
12
|
function createAPI(_a) {
|
|
@@ -147,15 +148,6 @@ describe('api.events', function () {
|
|
|
147
148
|
it('buffers the error if a user action is in progress', function () {
|
|
148
149
|
var internalLogger = testUtils_1.mockInternalLogger;
|
|
149
150
|
var config = (0, testUtils_1.mockConfig)();
|
|
150
|
-
var actionBuffer = new ItemBuffer_1.ItemBuffer();
|
|
151
|
-
var message;
|
|
152
|
-
var getMessage = function () { return message; };
|
|
153
|
-
message = {
|
|
154
|
-
type: const_1.USER_ACTION_START,
|
|
155
|
-
name: 'testAction',
|
|
156
|
-
startTime: Date.now(),
|
|
157
|
-
parentId: 'parent-id',
|
|
158
|
-
};
|
|
159
151
|
var api = (0, initialize_2.initializeEventsAPI)({
|
|
160
152
|
unpatchedConsole: console,
|
|
161
153
|
internalLogger: internalLogger,
|
|
@@ -163,29 +155,15 @@ describe('api.events', function () {
|
|
|
163
155
|
metas: apiTestHelpers_1.mockMetas,
|
|
164
156
|
transports: apiTestHelpers_1.mockTransports,
|
|
165
157
|
tracesApi: apiTestHelpers_1.mockTracesApi,
|
|
166
|
-
|
|
167
|
-
getMessage: getMessage,
|
|
158
|
+
userActionsApi: apiTestHelpers_1.mockUserActionsApi,
|
|
168
159
|
});
|
|
160
|
+
apiTestHelpers_1.mockUserActionsApi.getActiveUserAction.mockReturnValueOnce(new userAction_1.default({
|
|
161
|
+
name: 'test',
|
|
162
|
+
trigger: 'foo',
|
|
163
|
+
transports: apiTestHelpers_1.mockTransports,
|
|
164
|
+
}));
|
|
169
165
|
api.pushEvent('test');
|
|
170
|
-
expect(
|
|
171
|
-
message = {
|
|
172
|
-
type: const_1.USER_ACTION_END,
|
|
173
|
-
name: 'testAction',
|
|
174
|
-
id: 'parent-id',
|
|
175
|
-
startTime: (0, utils_1.dateNow)(),
|
|
176
|
-
endTime: (0, utils_1.dateNow)(),
|
|
177
|
-
duration: 0,
|
|
178
|
-
eventType: 'click',
|
|
179
|
-
};
|
|
180
|
-
api.pushEvent('test-2');
|
|
181
|
-
expect(actionBuffer.size()).toBe(1);
|
|
182
|
-
message = {
|
|
183
|
-
type: const_1.USER_ACTION_CANCEL,
|
|
184
|
-
name: 'testAction',
|
|
185
|
-
parentId: 'parent-id',
|
|
186
|
-
};
|
|
187
|
-
api.pushEvent('test-3');
|
|
188
|
-
expect(actionBuffer.size()).toBe(1);
|
|
166
|
+
expect(apiTestHelpers_1.mockTransports.execute).not.toHaveBeenCalled();
|
|
189
167
|
});
|
|
190
168
|
});
|
|
191
169
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.test.js","sourceRoot":"","sources":["../../../../../../src/api/events/initialize.test.ts"],"names":[],"mappings":";;AACA,+CAAkD;AAClD,6CAAgF;AAChF,qCAAsC;AACtC,oDAA6E;AAC7E,kCAAkF;AAClF,4CAA2C;AAG3C,2CAAmD;AAGnD,QAAQ,CAAC,YAAY,EAAE;IACrB,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,MAA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AAC,CAAC;YAEpC,OAAO,GAAG;gBACR,IAAI,EAAE,uBAAe;gBACrB,IAAI,EAAE,YAAY;gBAClB,EAAE,EAAE,WAAW;gBACf,SAAS,EAAE,IAAA,eAAO,GAAE;gBACpB,OAAO,EAAE,IAAA,eAAO,GAAE;gBAClB,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,OAAO;aACnB,CAAC;YAEF,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACxB,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAEpC,OAAO,GAAG;gBACR,IAAI,EAAE,0BAAkB;gBACxB,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,WAAW;aACtB,CAAC;YAEF,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACxB,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import type { TransportItem } from '../..';\nimport { initializeFaro } from '../../initialize';\nimport { mockConfig, mockInternalLogger, MockTransport } from '../../testUtils';\nimport { dateNow } from '../../utils';\nimport { mockMetas, mockTracesApi, mockTransports } from '../apiTestHelpers';\nimport { USER_ACTION_CANCEL, USER_ACTION_END, USER_ACTION_START } from '../const';\nimport { ItemBuffer } from '../ItemBuffer';\nimport type { API, APIEvent, ApiMessageBusMessages } from '../types';\n\nimport { initializeEventsAPI } from './initialize';\nimport type { EventEvent, PushEventOptions } from './types';\n\ndescribe('api.events', () => {\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('pushEvent', () => {\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.pushEvent('test', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n });\n\n it(\"doesn't filter events with same name and partially same values\", () => {\n api.pushEvent('test', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test', {\n a: '1',\n b: '2',\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter events with different name and same values\", () => {\n api.pushEvent('test1', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test2', {\n a: '1',\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"filters an event and doesn't filter the next different one\", () => {\n api.pushEvent('test1', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test1', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test2', {\n b: '1',\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.pushEvent('test');\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test');\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when skipDedupe is true\", () => {\n api.pushEvent('test');\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test', {}, undefined, { skipDedupe: true });\n expect(transport.items).toHaveLength(2);\n });\n\n it('uses traceId and spanId from custom context', () => {\n const spanContext: PushEventOptions['spanContext'] = {\n traceId: 'my-trace-id',\n spanId: 'my-span-id',\n };\n\n const mockGetTraceContext = jest.fn();\n jest.spyOn(api, 'getTraceContext').mockImplementationOnce(mockGetTraceContext);\n\n api.pushEvent('test', undefined, undefined, { spanContext });\n\n expect(mockGetTraceContext).not.toHaveBeenCalled();\n expect((transport.items[0]?.payload as EventEvent).trace).toStrictEqual({\n trace_id: 'my-trace-id',\n span_id: 'my-span-id',\n });\n });\n\n it('Sets the timestamp to the provided custom timestamp', () => {\n api.pushEvent('test', undefined, undefined, { timestampOverwriteMs: 123 });\n expect(transport.items).toHaveLength(1);\n expect((transport.items[0]?.payload as EventEvent).timestamp).toBe('1970-01-01T00:00:00.123Z');\n });\n\n it('stringifies all values in the attributes object', () => {\n api.pushEvent('test', {\n // @ts-expect-error\n a: 1,\n b: 'foo',\n // @ts-expect-error\n c: true,\n // @ts-expect-error\n d: { e: 'bar' },\n // @ts-expect-error\n g: null,\n // @ts-expect-error\n h: undefined,\n // @ts-expect-error\n i: [1, 2, 3],\n });\n\n // @ts-expect-error\n expect(transport.items[0]?.payload.attributes).toStrictEqual({\n a: '1',\n b: 'foo',\n c: 'true',\n d: '{\"e\":\"bar\"}',\n g: 'null',\n h: 'undefined',\n i: '[1,2,3]',\n });\n });\n\n it('does not stringify empty attributes', () => {\n api.pushEvent('test');\n api.pushEvent('test2', {});\n expect(transport.items).toHaveLength(2);\n expect((transport.items[0] as TransportItem<EventEvent>).payload.attributes).toBeUndefined();\n expect((transport.items[0] as TransportItem<EventEvent>).payload.attributes).toBeUndefined();\n });\n });\n });\n\n describe('User action', () => {\n it('buffers the error if a user action is in progress', () => {\n const internalLogger = mockInternalLogger;\n const config = mockConfig();\n\n const actionBuffer = new ItemBuffer<TransportItem<APIEvent>>();\n\n let message: ApiMessageBusMessages | undefined;\n\n const getMessage = () => message;\n\n message = {\n type: USER_ACTION_START,\n name: 'testAction',\n startTime: Date.now(),\n parentId: 'parent-id',\n };\n const api = initializeEventsAPI({\n unpatchedConsole: console,\n internalLogger,\n config,\n metas: mockMetas,\n transports: mockTransports,\n tracesApi: mockTracesApi,\n actionBuffer,\n getMessage,\n });\n\n api.pushEvent('test');\n expect(actionBuffer.size()).toBe(1);\n\n message = {\n type: USER_ACTION_END,\n name: 'testAction',\n id: 'parent-id',\n startTime: dateNow(),\n endTime: dateNow(),\n duration: 0,\n eventType: 'click',\n };\n\n api.pushEvent('test-2');\n expect(actionBuffer.size()).toBe(1);\n\n message = {\n type: USER_ACTION_CANCEL,\n name: 'testAction',\n parentId: 'parent-id',\n };\n\n api.pushEvent('test-3');\n expect(actionBuffer.size()).toBe(1);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"initialize.test.js","sourceRoot":"","sources":["../../../../../../src/api/events/initialize.test.ts"],"names":[],"mappings":";;;;;AACA,+CAAkD;AAClD,6CAAgF;AAChF,oDAAiG;AAEjG,yEAAmD;AAEnD,2CAAmD;AAGnD,QAAQ,CAAC,YAAY,EAAE;IACrB,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,CAAC;;YACT,KAAmB,SAAS,EAAE,EAA7B,GAAG,QAAA,EAAE,SAAS,QAAA,CAAgB;QACjC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,WAAW,EAAE;YACpB,EAAE,CAAC,wBAAwB,EAAE;gBAC3B,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;oBACpB,CAAC,EAAE,GAAG;iBACP,CAAC,CAAC;gBACH,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAExC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;oBACpB,CAA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AS;gBAChB,UAAU,EAAE,+BAAc;gBAC1B,SAAS,EAAE,8BAAa;gBACxB,cAAc,EAAE,mCAAkB;aACnC,CAAC,CAAC;YAEF,mCAAkB,CAAC,mBAAiC,CAAC,mBAAmB,CACvE,IAAI,oBAAU,CAAC;gBACb,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,KAAK;gBACd,UAAU,EAAE,+BAAc;aAC3B,CAAC,CACH,CAAC;YACF,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACtB,MAAM,CAAC,+BAAc,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import type { TransportItem } from '../..';\nimport { initializeFaro } from '../../initialize';\nimport { mockConfig, mockInternalLogger, MockTransport } from '../../testUtils';\nimport { mockMetas, mockTracesApi, mockTransports, mockUserActionsApi } from '../apiTestHelpers';\nimport type { API } from '../types';\nimport UserAction from '../userActions/userAction';\n\nimport { initializeEventsAPI } from './initialize';\nimport type { EventEvent, PushEventOptions } from './types';\n\ndescribe('api.events', () => {\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('pushEvent', () => {\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.pushEvent('test', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n });\n\n it(\"doesn't filter events with same name and partially same values\", () => {\n api.pushEvent('test', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test', {\n a: '1',\n b: '2',\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter events with different name and same values\", () => {\n api.pushEvent('test1', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test2', {\n a: '1',\n });\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"filters an event and doesn't filter the next different one\", () => {\n api.pushEvent('test1', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test1', {\n a: '1',\n });\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test2', {\n b: '1',\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.pushEvent('test');\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test');\n expect(transport.items).toHaveLength(2);\n });\n\n it(\"doesn't filter when skipDedupe is true\", () => {\n api.pushEvent('test');\n expect(transport.items).toHaveLength(1);\n\n api.pushEvent('test', {}, undefined, { skipDedupe: true });\n expect(transport.items).toHaveLength(2);\n });\n\n it('uses traceId and spanId from custom context', () => {\n const spanContext: PushEventOptions['spanContext'] = {\n traceId: 'my-trace-id',\n spanId: 'my-span-id',\n };\n\n const mockGetTraceContext = jest.fn();\n jest.spyOn(api, 'getTraceContext').mockImplementationOnce(mockGetTraceContext);\n\n api.pushEvent('test', undefined, undefined, { spanContext });\n\n expect(mockGetTraceContext).not.toHaveBeenCalled();\n expect((transport.items[0]?.payload as EventEvent).trace).toStrictEqual({\n trace_id: 'my-trace-id',\n span_id: 'my-span-id',\n });\n });\n\n it('Sets the timestamp to the provided custom timestamp', () => {\n api.pushEvent('test', undefined, undefined, { timestampOverwriteMs: 123 });\n expect(transport.items).toHaveLength(1);\n expect((transport.items[0]?.payload as EventEvent).timestamp).toBe('1970-01-01T00:00:00.123Z');\n });\n\n it('stringifies all values in the attributes object', () => {\n api.pushEvent('test', {\n // @ts-expect-error\n a: 1,\n b: 'foo',\n // @ts-expect-error\n c: true,\n // @ts-expect-error\n d: { e: 'bar' },\n // @ts-expect-error\n g: null,\n // @ts-expect-error\n h: undefined,\n // @ts-expect-error\n i: [1, 2, 3],\n });\n\n // @ts-expect-error\n expect(transport.items[0]?.payload.attributes).toStrictEqual({\n a: '1',\n b: 'foo',\n c: 'true',\n d: '{\"e\":\"bar\"}',\n g: 'null',\n h: 'undefined',\n i: '[1,2,3]',\n });\n });\n\n it('does not stringify empty attributes', () => {\n api.pushEvent('test');\n api.pushEvent('test2', {});\n expect(transport.items).toHaveLength(2);\n expect((transport.items[0] as TransportItem<EventEvent>).payload.attributes).toBeUndefined();\n expect((transport.items[0] as TransportItem<EventEvent>).payload.attributes).toBeUndefined();\n });\n });\n });\n\n describe('User action', () => {\n it('buffers the error if a user action is in progress', () => {\n const internalLogger = mockInternalLogger;\n const config = mockConfig();\n\n const api = initializeEventsAPI({\n unpatchedConsole: console,\n internalLogger,\n config,\n metas: mockMetas,\n transports: mockTransports,\n tracesApi: mockTracesApi,\n userActionsApi: mockUserActionsApi,\n });\n\n (mockUserActionsApi.getActiveUserAction as jest.Mock).mockReturnValueOnce(\n new UserAction({\n name: 'test',\n trigger: 'foo',\n transports: mockTransports,\n })\n );\n api.pushEvent('test');\n expect(mockTransports.execute).not.toHaveBeenCalled();\n });\n });\n});\n"]}
|
|
@@ -15,13 +15,12 @@ exports.initializeExceptionsAPI = initializeExceptionsAPI;
|
|
|
15
15
|
var transports_1 = require("../../transports");
|
|
16
16
|
var utils_1 = require("../../utils");
|
|
17
17
|
var date_1 = require("../../utils/date");
|
|
18
|
-
var const_1 = require("../const");
|
|
19
18
|
var utils_2 = require("../utils");
|
|
20
|
-
var
|
|
19
|
+
var const_1 = require("./const");
|
|
21
20
|
var stacktraceParser;
|
|
22
21
|
function initializeExceptionsAPI(_a) {
|
|
23
22
|
var _b;
|
|
24
|
-
var internalLogger = _a.internalLogger, config = _a.config, metas = _a.metas, transports = _a.transports, tracesApi = _a.tracesApi,
|
|
23
|
+
var internalLogger = _a.internalLogger, config = _a.config, metas = _a.metas, transports = _a.transports, tracesApi = _a.tracesApi, userActionsApi = _a.userActionsApi;
|
|
25
24
|
internalLogger.debug('Initializing exceptions API');
|
|
26
25
|
var lastPayload = null;
|
|
27
26
|
stacktraceParser = (_b = config.parseStacktrace) !== null && _b !== void 0 ? _b : stacktraceParser;
|
|
@@ -40,7 +39,7 @@ function initializeExceptionsAPI(_a) {
|
|
|
40
39
|
var ctx = (0, utils_1.stringifyObjectValues)(__assign(__assign({}, parseCause(originalError !== null && originalError !== void 0 ? originalError : error)), (context !== null && context !== void 0 ? context : {})));
|
|
41
40
|
var item = {
|
|
42
41
|
meta: metas.value,
|
|
43
|
-
payload: __assign(__assign({ type: type || error.name ||
|
|
42
|
+
payload: __assign(__assign({ type: type || error.name || const_1.defaultExceptionType, value: error.message, timestamp: timestampOverwriteMs ? (0, date_1.timestampToIsoString)(timestampOverwriteMs) : (0, utils_1.getCurrentTimestamp)(), trace: spanContext
|
|
44
43
|
? {
|
|
45
44
|
trace_id: spanContext.traceId,
|
|
46
45
|
span_id: spanContext.spanId,
|
|
@@ -66,9 +65,9 @@ function initializeExceptionsAPI(_a) {
|
|
|
66
65
|
}
|
|
67
66
|
lastPayload = testingPayload;
|
|
68
67
|
internalLogger.debug('Pushing exception\n', item);
|
|
69
|
-
var
|
|
70
|
-
if (
|
|
71
|
-
|
|
68
|
+
var activeUserAction = userActionsApi.getActiveUserAction();
|
|
69
|
+
if (activeUserAction) {
|
|
70
|
+
activeUserAction.addItem(item);
|
|
72
71
|
}
|
|
73
72
|
else {
|
|
74
73
|
transports.execute(item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../../src/api/exceptions/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../../../src/api/exceptions/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;AA2BA,0DA0GC;AAlID,+CAAqD;AAG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AAC;SAAM,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAA,eAAO,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC7E,KAAK,GAAG,IAAA,6BAAqB,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;SAAM,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,cAAc,CAAC,YAAsB,EAAE,KAA+B;IACrE,IAAA,OAAO,GAAkB,KAAK,QAAvB,EAAE,IAAI,GAAY,KAAK,KAAjB,EAAE,KAAK,GAAK,KAAK,MAAV,CAAW;IACvC,OAAO,IAAA,yBAAiB,EAAC,YAAY,EAAE,OAAO,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import type { Config, Patterns } 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 {\n deepEqual,\n getCurrentTimestamp,\n isArray,\n isEmpty,\n isError,\n isNull,\n isObject,\n stringifyExternalJson,\n stringifyObjectValues,\n} from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport type { TracesAPI } from '../traces';\nimport type { UserActionsAPI } from '../userActions';\nimport { shouldIgnoreEvent } from '../utils';\n\nimport { defaultExceptionType } from './const';\nimport type { ErrorWithIndexProperties, ExceptionEvent, ExceptionsAPI, StacktraceParser } from './types';\n\nlet stacktraceParser: StacktraceParser | undefined;\n\nexport function initializeExceptionsAPI({\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}): ExceptionsAPI {\n internalLogger.debug('Initializing exceptions API');\n\n let lastPayload: Pick<ExceptionEvent, 'type' | 'value' | 'stacktrace' | 'context'> | null = null;\n\n stacktraceParser = config.parseStacktrace ?? stacktraceParser;\n\n const changeStacktraceParser: ExceptionsAPI['changeStacktraceParser'] = (newStacktraceParser) => {\n internalLogger.debug('Changing stacktrace parser');\n\n stacktraceParser = newStacktraceParser ?? stacktraceParser;\n };\n\n const getStacktraceParser: ExceptionsAPI['getStacktraceParser'] = () => stacktraceParser;\n\n const { ignoreErrors = [], preserveOriginalError } = config;\n\n const pushError: ExceptionsAPI['pushError'] = (\n error,\n { skipDedupe, stackFrames, type, context, spanContext, timestampOverwriteMs, originalError } = {}\n ) => {\n if (isErrorIgnored(ignoreErrors, originalError ?? error)) {\n return;\n }\n try {\n const ctx = stringifyObjectValues({\n ...parseCause(originalError ?? error),\n ...(context ?? {}),\n });\n\n const item: TransportItem<ExceptionEvent<typeof preserveOriginalError>> = {\n meta: metas.value,\n payload: {\n type: type || error.name || defaultExceptionType,\n value: error.message,\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 ...(isEmpty(ctx) ? {} : { context: ctx }),\n ...(preserveOriginalError ? { originalError } : {}),\n },\n type: TransportItemType.EXCEPTION,\n };\n\n stackFrames = stackFrames ?? (error.stack ? stacktraceParser?.(error).frames : undefined);\n\n if (stackFrames?.length) {\n item.payload.stacktrace = {\n frames: stackFrames,\n };\n }\n\n const testingPayload = {\n type: item.payload.type,\n value: item.payload.value,\n stackTrace: item.payload.stacktrace,\n context: item.payload.context,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping error 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 exception\\n', item);\n\n const activeUserAction = userActionsApi.getActiveUserAction();\n if (activeUserAction) {\n activeUserAction.addItem(item);\n } else {\n transports.execute(item);\n }\n } catch (err) {\n internalLogger.error('Error pushing event', err);\n }\n };\n\n changeStacktraceParser(config.parseStacktrace);\n\n return {\n changeStacktraceParser,\n getStacktraceParser,\n pushError,\n };\n}\n\nfunction parseCause(error: ErrorWithIndexProperties): {} | { cause: string } {\n let cause = error.cause;\n\n if (isError(cause)) {\n cause = error.cause.toString();\n // typeof operator on null returns \"object\". This is a well-known quirk in JavaScript and is considered a bug that cannot be fixed due to backward compatibility issues.\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#typeof_null\n } else if (cause !== null && (isObject(error.cause) || isArray(error.cause))) {\n cause = stringifyExternalJson(error.cause);\n } else if (cause != null) {\n cause = error.cause.toString();\n }\n\n return cause == null ? {} : { cause };\n}\n\nfunction isErrorIgnored(ignoreErrors: Patterns, error: ErrorWithIndexProperties): boolean {\n const { message, name, stack } = error;\n return shouldIgnoreEvent(ignoreErrors, message + ' ' + name + ' ' + stack);\n}\n"]}
|