@grafana/faro-core 1.18.2 → 2.0.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- 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/instrumentations/initialize.js +1 -1
- package/dist/cjs/instrumentations/initialize.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/instrumentations/initialize.js +1 -1
- package/dist/esm/instrumentations/initialize.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/instrumentations/initialize.js +1 -1
- package/dist/spec/core/src/instrumentations/initialize.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/transports/batchExecutor.test.js +10 -10
- package/dist/spec/core/src/transports/batchExecutor.test.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 +9 -9
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/logs/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACtH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/logs/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACtH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGnD,MAAM,UAAU,iBAAiB,CAAC,EAChC,cAAc,EACd,MAAM,EAC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AAI,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,4DAA4D,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEjG,OAAO;YACT,CAAC;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;YAE5C,MAAM,gBAAgB,GAAG,cAAc,CAAC,mBAAmB,EAAE,CAAC;YAC9D,IAAI,gBAAgB,EAAE,CAAC;gBACrB,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACjC,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,OAAO;KACR,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, defaultLogLevel, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport type { TracesAPI } from '../traces';\nimport type { UserActionsAPI } from '../userActions';\n\nimport { defaultLogArgsSerializer } from './const';\nimport type { LogEvent, LogsAPI } from './types';\n\nexport function initializeLogsAPI({\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}): LogsAPI {\n internalLogger.debug('Initializing logs API');\n\n let lastPayload: Pick<LogEvent, 'message' | 'level' | 'context'> | null = null;\n\n const logArgsSerializer = config.logArgsSerializer ?? defaultLogArgsSerializer;\n\n const pushLog: LogsAPI['pushLog'] = (\n args,\n { context, level, skipDedupe, spanContext, timestampOverwriteMs } = {}\n ) => {\n try {\n const ctx = stringifyObjectValues(context);\n\n const item: TransportItem<LogEvent> = {\n type: TransportItemType.LOG,\n payload: {\n message: logArgsSerializer(args),\n level: level ?? defaultLogLevel,\n context: isEmpty(ctx) ? undefined : ctx,\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 meta: metas.value,\n };\n\n const testingPayload = {\n message: item.payload.message,\n level: item.payload.level,\n context: item.payload.context,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping log push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing log\\n', item);\n\n 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 log\\n', err);\n }\n };\n\n return {\n pushLog,\n };\n}\n"]}
|
|
@@ -1,8 +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
|
-
|
|
5
|
-
export function initializeMeasurementsAPI({ internalLogger, config, metas, transports, tracesApi, actionBuffer, getMessage, }) {
|
|
4
|
+
export function initializeMeasurementsAPI({ internalLogger, config, metas, transports, tracesApi, userActionsApi, }) {
|
|
6
5
|
internalLogger.debug('Initializing measurements API');
|
|
7
6
|
let lastPayload = null;
|
|
8
7
|
const pushMeasurement = (payload, { skipDedupe, context, spanContext, timestampOverwriteMs } = {}) => {
|
|
@@ -29,9 +28,9 @@ export function initializeMeasurementsAPI({ internalLogger, config, metas, trans
|
|
|
29
28
|
}
|
|
30
29
|
lastPayload = testingPayload;
|
|
31
30
|
internalLogger.debug('Pushing measurement\n', item);
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
31
|
+
const activeUserAction = userActionsApi.getActiveUserAction();
|
|
32
|
+
if (activeUserAction) {
|
|
33
|
+
activeUserAction.addItem(item);
|
|
35
34
|
}
|
|
36
35
|
else {
|
|
37
36
|
transports.execute(item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/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":["../../../../src/api/measurements/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;AAMxD,MAAM,UAAU,yBAAyB,CAAC,EACxC,cAAc,EACd,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,cAAc,GASf;IACC,cAAc,CAAC,K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C;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,MAAM,gBAAgB,GAAG,cAAc,CAAC,mBAAmB,EAAE,CAAC;YAC9D,IAAI,gBAAgB,EAAE,CAAC;gBACrB,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACjC,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,6BAA6B,EAAE,GAAG,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe;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';\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 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 measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/meta/initialize.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/meta/initialize.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAKnD,MAAM,UAAU,iBAAiB,CAAC,EAChC,cAAc,EACd,KAAK,GAQN;IACC,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAE9C,IAAI,WAAW,GAA8B,SAAS,CAAC;IACvD,IAAI,QAAQ,GAA8B,SAAS,CAAC;IACpD,IAAI,QAAQ,GAA8B,SAAS,CAAC;IACpD,IAAI,QAAQ,GAA8B,SAAS,CAAC;IAEpD,MAAM,OAA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CAAE,IAAI,0CAAE,IAAI,OAAK,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAA,EAAE,CAAC;YACxC,OAAO;QACT,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC;QAE9B,QAAQ,GAAG;YACT,IAAI;SACL,CAAC;QAEF,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEpB,IAAI,YAAY,EAAE,CAAC;YACjB,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,OAAO,GAAuB,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;IAE3D,MAAM,OAAO,GAAuB,CAAC,IAAI,EAAE,EAAE;;QAC3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;YAC7B,CAAC,iCAIM,CAAC,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,OAAO,EAAE,CAAC,KAChC,EAAE,EAAE,IAAI,IAEZ,CAAC,CAAC,IAAI,CAAC;QAET,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QAED,QAAQ,GAAG;YACT,IAAI,EAAE,QAAQ;SACf,CAAC;QAEF,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAuB,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;IAE3D,OAAO;QACL,OAAO;QACP,SAAS,EAAE,OAA+B;QAC1C,UAAU;QACV,YAAY,EAAE,UAAqC;QACnD,UAAU;QACV,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Meta, Metas } from '../../metas';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { isEmpty, isString } from '../../utils/is';\nimport type { TracesAPI } from '../traces';\n\nimport type { MetaAPI } from './types';\n\nexport function initializeMetaAPI({\n internalLogger,\n metas,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n}): MetaAPI {\n internalLogger.debug('Initializing meta API');\n\n let metaSession: Partial<Meta> | undefined = undefined;\n let metaUser: Partial<Meta> | undefined = undefined;\n let metaView: Partial<Meta> | undefined = undefined;\n let metaPage: Partial<Meta> | undefined = undefined;\n\n const setUser: MetaAPI['setUser'] = (user) => {\n if (metaUser) {\n metas.remove(metaUser);\n }\n\n metaUser = {\n user,\n };\n\n metas.add(metaUser);\n };\n\n const setSession: MetaAPI['setSession'] = (session, options) => {\n const newOverrides = options?.overrides;\n const overrides = newOverrides\n ? {\n overrides: {\n ...metaSession?.session?.overrides,\n ...newOverrides,\n },\n }\n : {};\n\n if (metaSession) {\n metas.remove(metaSession);\n }\n\n metaSession = {\n session: {\n // if session is undefined, session manager force creates a new session\n ...(isEmpty(session) ? undefined : session),\n ...overrides,\n },\n };\n\n metas.add(metaSession);\n };\n\n const getSession: MetaAPI['getSession'] = () => metas.value.session;\n\n const setView: MetaAPI['setView'] = (view, options) => {\n if (options?.overrides) {\n setSession(getSession(), { overrides: options.overrides });\n }\n\n if (metaView?.view?.name === view?.name) {\n return;\n }\n\n const previousView = metaView;\n\n metaView = {\n view,\n };\n\n metas.add(metaView);\n\n if (previousView) {\n metas.remove(previousView);\n }\n };\n\n const getView: MetaAPI['getView'] = () => metas.value.view;\n\n const setPage: MetaAPI['setPage'] = (page) => {\n const pageMeta = isString(page)\n ? {\n // metaPage is available once setPage() has been called.\n // This is because page self updating metas like page need to be added as a function\n // Thus we call getPage in case metaPage is empty\n ...(metaPage?.page ?? getPage()),\n id: page,\n }\n : page;\n\n if (metaPage) {\n metas.remove(metaPage);\n }\n\n metaPage = {\n page: pageMeta,\n };\n\n metas.add(metaPage);\n };\n\n const getPage: MetaAPI['getPage'] = () => metas.value.page;\n\n return {\n setUser,\n resetUser: setUser as MetaAPI['resetUser'],\n setSession,\n resetSession: setSession as MetaAPI['resetSession'],\n getSession,\n setView,\n getView,\n setPage,\n getPage,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { EventEvent, EventsAPI } from './events';\nimport type { ExceptionEvent, ExceptionsAPI } from './exceptions';\nimport type { LogEvent, LogsAPI } from './logs';\nimport type { MeasurementEvent, MeasurementsAPI } from './measurements';\nimport type { MetaAPI } from './meta';\nimport type { TraceEvent, TracesAPI } from './traces';\nimport type { UserActionsAPI } from './userActions';\n\nexport type UserAction = {\n name: string;\n id?: string;\n parentId?: string;\n};\n\nexport type APIEvent = LogEvent | ExceptionEvent | MeasurementEvent | TraceEvent | EventEvent;\n\nexport type API = LogsAPI & ExceptionsAPI & MeasurementsAPI & TracesAPI & MetaAPI & EventsAPI & UserActionsAPI;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const userActionStartByApiCallEventName = 'faroApiCall';
|
|
2
|
+
export const userActionStart = 'user_action_start';
|
|
3
|
+
export var UserActionSeverity;
|
|
4
|
+
(function (UserActionSeverity) {
|
|
5
|
+
UserActionSeverity["Normal"] = "normal";
|
|
6
|
+
UserActionSeverity["Critical"] = "critical";
|
|
7
|
+
})(UserActionSeverity || (UserActionSeverity = {}));
|
|
8
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../src/api/userActions/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iCAAiC,GAAG,aAAa,CAAC;AAE/D,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAEnD,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,uCAAiB,CAAA;IACjB,2CAAqB,CAAA;AACvB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["export const userActionStartByApiCallEventName = 'faroApiCall';\n\nexport const userActionStart = 'user_action_start';\n\nexport enum UserActionSeverity {\n Normal = 'normal',\n Critical = 'critical',\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/userActions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,eAAe,EAA4B,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { type UserActionsAPI, UserActionState, type UserActionInterface } from './types';\nexport { UserActionSeverity } from './const';\n\nexport { initializeUserActionsAPI, userActionsMessageBus } from './initialize';\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {} from '../..';
|
|
2
|
+
import { Observable } from '../../utils/reactive';
|
|
3
|
+
import { userActionStart, userActionStartByApiCallEventName } from './const';
|
|
4
|
+
import { UserActionState, } from './types';
|
|
5
|
+
import UserAction from './userAction';
|
|
6
|
+
export const userActionsMessageBus = new Observable();
|
|
7
|
+
export function initializeUserActionsAPI({ transports, internalLogger, config, }) {
|
|
8
|
+
const trackUserActionsExcludeItem = config.trackUserActionsExcludeItem;
|
|
9
|
+
// Currently running user action. It can be in either started or halted
|
|
10
|
+
// state
|
|
11
|
+
let activeUserAction;
|
|
12
|
+
// If there is a an action already running, return undefined to indicate
|
|
13
|
+
// we were not able to create one.
|
|
14
|
+
const startUserAction = (name, attributes, options) => {
|
|
15
|
+
const currentRunningUserAction = getActiveUserAction();
|
|
16
|
+
if (currentRunningUserAction === undefined) {
|
|
17
|
+
const userAction = new UserAction({
|
|
18
|
+
name,
|
|
19
|
+
transports,
|
|
20
|
+
attributes,
|
|
21
|
+
trigger: (options === null || options === void 0 ? void 0 : options.triggerName) || userActionStartByApiCallEventName,
|
|
22
|
+
trackUserActionsExcludeItem,
|
|
23
|
+
});
|
|
24
|
+
userAction
|
|
25
|
+
.filter((v) => [UserActionState.Ended, UserActionState.Cancelled].includes(v))
|
|
26
|
+
.first()
|
|
27
|
+
.subscribe(() => {
|
|
28
|
+
activeUserAction = undefined;
|
|
29
|
+
});
|
|
30
|
+
userActionsMessageBus.notify({
|
|
31
|
+
type: userActionStart,
|
|
32
|
+
userAction: userAction,
|
|
33
|
+
});
|
|
34
|
+
activeUserAction = userAction;
|
|
35
|
+
return activeUserAction;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
internalLogger.error('Attempted to create a new user action while one is already running. This is not possible.');
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const getActiveUserAction = () => {
|
|
43
|
+
return activeUserAction;
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
startUserAction,
|
|
47
|
+
getActiveUserAction,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=initialize.js.map
|
|
@@ -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;AA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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,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAyB,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAiB,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAgD,eAAe,EAAE,MAAM,SAAS,CAAC;AAExF,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAC3C,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,UAAU;IAmBhD,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,2BAA2B,EAC3B,QAAQ,GAAG,kBAAkB,CAAC,MAAM,GAUrC;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI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AI,CAAC,QAAQ,IAC9B,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,GAE3C,SAAS,EACT;YACE,oBAAoB,EAAE,IAAI,CAAC,SAAS;YACpC,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;gBACpC,OAAO,CAAC,MAAM,GAAG;oBACf,EAAE,EAAE,IAAI,CAAC,EAAE;oBACX,IAAI,EAAE,IAAI,CAAC,IAAI;iBAChB,CAAC;gBAEF,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CACF,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAED,SAAS,uBAAuB,CAC9B,IAA6B,EAC7B,2BAAkE;IAElE,OAAO,CACL,CAAA,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAG,IAAI,CAAC;QACnC,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC,WAAW,IAAK,IAAI,CAAC,OAA4B,CAAC,IAAI,KAAK,YAAY,CAAC,CAC1G,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,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,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,qBAAqB,GACtB,MAAM,OAAO,CAAC;AAiCf,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAoBzG,OAAO,EACL,IAAI,EACJ,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,OAAO,CAAC;AAGf,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAW9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,YAAY,EACZ,OAAO,EACP,cAAc,EACd,UAAU,EACV,YAAY,EACZ,KAAK,EACL,KAAK,EACL,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,IAAI,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"]}
|
|
@@ -31,7 +31,7 @@ export function initializeInstrumentations(unpatchedConsole, internalLogger, con
|
|
|
31
31
|
}
|
|
32
32
|
return null;
|
|
33
33
|
}, null);
|
|
34
|
-
if (
|
|
34
|
+
if (existingInstrumentationIndex === null) {
|
|
35
35
|
internalLogger.warn(`Instrumentation "${instrumentationToRemove.name}" is not added`);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/instrumentations/initialize.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,0BAA0B,CACxC,gBAAkC,EAClC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB,EACtB,GAAQ;IAER,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,MAAM,gBAAgB,GAAsB,EAAE,CAAC;IAE/C,MAAM,GAAG,GAA4B,CAAC,GAAG,mBAAmB,EAAE,EAAE;QAC9D,cAAc,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAEhD,mBAAmB,CAAC,OAAO,CAAC,CAAC,kBAAkB,EAAE,EAAE;YACjD,cAAc,CAAC,KAAK,CAAC,WAAW,kBAAkB,CAAC,IAAI,mBAAmB,CAAC,CAAC;YAE5E,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAClC,CAAC,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC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C;QAElD,wBAAwB,CAAC,OAAO,CAAC,CAAC,uBAAuB,EAAE,EAAE;;YAC3D,cAAc,CAAC,KAAK,CAAC,aAAa,uBAAuB,CAAC,IAAI,mBAAmB,CAAC,CAAC;YAEnF,MAAM,4BAA4B,GAAG,gBAAgB,CAAC,MAAM,CAC1D,CAAC,GAAG,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,EAAE;gBACvD,IAAI,GAAG,KAAK,IAAI,IAAI,uBAAuB,CAAC,IAAI,KAAK,uBAAuB,CAAC,IAAI,EAAE,CAAC;oBAClF,OAAO,sBAAsB,CAAC;gBAChC,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC,EACD,IAAI,CACL,CAAC;YAEF,IAAI,4BAA4B,KAAK,IAAI,EAAE,CAAC;gBAC1C,cAAc,CAAC,IAAI,CAAC,oBAAoB,uBAAuB,CAAC,IAAI,gBAAgB,CAAC,CAAC;gBAEtF,OAAO;YACT,CAAC;YAED,MAAA,MAAA,gBAAgB,CAAC,4BAA4B,CAAE,EAAC,OAAO,kDAAI,CAAC;YAE5D,gBAAgB,CAAC,MAAM,CAAC,4BAA4B,EAAE,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,GAAG;QACH,IAAI,gBAAgB;YAClB,OAAO,CAAC,GAAG,gBAAgB,CAAC,CAAC;QAC/B,CAAC;QACD,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { API } from '../api';\nimport type { Config } from '../config';\nimport type { InternalLogger } from '../internalLogger';\nimport type { Metas } from '../metas';\nimport type { Transports } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\n\nimport type { Instrumentation, Instrumentations } from './types';\n\nexport function initializeInstrumentations(\n unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n api: API\n): Instrumentations {\n internalLogger.debug('Initializing instrumentations');\n\n const instrumentations: Instrumentation[] = [];\n\n const add: Instrumentations['add'] = (...newInstrumentations) => {\n internalLogger.debug('Adding instrumentations');\n\n newInstrumentations.forEach((newInstrumentation) => {\n internalLogger.debug(`Adding \"${newInstrumentation.name}\" instrumentation`);\n\n const exists = instrumentations.some(\n (existingInstrumentation) => existingInstrumentation.name === newInstrumentation.name\n );\n\n if (exists) {\n internalLogger.warn(`Instrumentation ${newInstrumentation.name} is already added`);\n\n return;\n }\n\n newInstrumentation.unpatchedConsole = unpatchedConsole;\n newInstrumentation.internalLogger = internalLogger;\n newInstrumentation.config = config;\n newInstrumentation.metas = metas;\n newInstrumentation.transports = transports;\n newInstrumentation.api = api;\n\n instrumentations.push(newInstrumentation);\n\n newInstrumentation.initialize();\n });\n };\n\n const remove: Instrumentations['remove'] = (...instrumentationsToRemove) => {\n internalLogger.debug('Removing instrumentations');\n\n instrumentationsToRemove.forEach((instrumentationToRemove) => {\n internalLogger.debug(`Removing \"${instrumentationToRemove.name}\" instrumentation`);\n\n const existingInstrumentationIndex = instrumentations.reduce<number | null>(\n (acc, existingInstrumentation, existingTransportIndex) => {\n if (acc === null && existingInstrumentation.name === instrumentationToRemove.name) {\n return existingTransportIndex;\n }\n\n return null;\n },\n null\n );\n\n if (existingInstrumentationIndex === null) {\n internalLogger.warn(`Instrumentation \"${instrumentationToRemove.name}\" is not added`);\n\n return;\n }\n\n instrumentations[existingInstrumentationIndex]!.destroy?.();\n\n instrumentations.splice(existingInstrumentationIndex, 1);\n });\n };\n\n return {\n add,\n get instrumentations() {\n return [...instrumentations];\n },\n remove,\n };\n}\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,YAAY,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.0.0-beta';\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;oBAC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import 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"]}
|