@grafana/faro-core 1.14.0 → 1.14.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/ItemBuffer.d.ts +7 -0
- package/dist/bundle/types/api/apiTestHelpers.d.ts +11 -0
- package/dist/bundle/types/api/const.d.ts +3 -0
- package/dist/bundle/types/api/events/initialize.d.ts +13 -2
- package/dist/bundle/types/api/events/types.d.ts +11 -0
- package/dist/bundle/types/api/exceptions/initialize.d.ts +13 -2
- package/dist/bundle/types/api/exceptions/types.d.ts +2 -0
- package/dist/bundle/types/api/index.d.ts +3 -1
- package/dist/bundle/types/api/initialize.d.ts +3 -1
- package/dist/bundle/types/api/logs/initialize.d.ts +13 -2
- package/dist/bundle/types/api/logs/types.d.ts +3 -1
- package/dist/bundle/types/api/measurements/initialize.d.ts +13 -1
- package/dist/bundle/types/api/measurements/types.d.ts +2 -0
- package/dist/bundle/types/api/meta/initialize.d.ts +14 -2
- package/dist/bundle/types/api/types.d.ts +37 -0
- package/dist/bundle/types/api/userActionLifecycleHandler.d.ts +13 -0
- package/dist/bundle/types/api/utils.d.ts +2 -0
- package/dist/bundle/types/config/types.d.ts +21 -12
- package/dist/bundle/types/index.d.ts +4 -4
- package/dist/bundle/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/bundle/types/transports/initialize.d.ts +2 -4
- package/dist/bundle/types/transports/types.d.ts +0 -1
- package/dist/bundle/types/utils/index.d.ts +2 -0
- package/dist/bundle/types/utils/reactive.d.ts +46 -0
- package/dist/bundle/types/version.d.ts +1 -1
- package/dist/cjs/api/ItemBuffer.js +27 -0
- package/dist/cjs/api/ItemBuffer.js.map +1 -0
- package/dist/cjs/api/apiTestHelpers.js +36 -0
- package/dist/cjs/api/apiTestHelpers.js.map +1 -0
- package/dist/cjs/api/const.js +7 -0
- package/dist/cjs/api/const.js.map +1 -0
- package/dist/cjs/api/events/initialize.js +15 -6
- package/dist/cjs/api/events/initialize.js.map +1 -1
- package/dist/cjs/api/events/types.js.map +1 -1
- package/dist/cjs/api/exceptions/initialize.js +59 -37
- package/dist/cjs/api/exceptions/initialize.js.map +1 -1
- package/dist/cjs/api/exceptions/types.js.map +1 -1
- package/dist/cjs/api/index.js +7 -1
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/initialize.js +16 -2
- package/dist/cjs/api/initialize.js.map +1 -1
- package/dist/cjs/api/logs/initialize.js +15 -6
- package/dist/cjs/api/logs/initialize.js.map +1 -1
- package/dist/cjs/api/logs/types.js.map +1 -1
- package/dist/cjs/api/measurements/initialize.js +12 -3
- package/dist/cjs/api/measurements/initialize.js.map +1 -1
- package/dist/cjs/api/measurements/types.js.map +1 -1
- package/dist/cjs/api/meta/initialize.js +2 -1
- package/dist/cjs/api/meta/initialize.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/api/userActionLifecycleHandler.js +59 -0
- package/dist/cjs/api/userActionLifecycleHandler.js.map +1 -0
- package/dist/cjs/api/utils.js +11 -0
- package/dist/cjs/api/utils.js.map +1 -0
- package/dist/cjs/config/types.js.map +1 -1
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/transports/initialize.js +1 -35
- package/dist/cjs/transports/initialize.js.map +1 -1
- package/dist/cjs/transports/registerInitial.js +0 -1
- package/dist/cjs/transports/registerInitial.js.map +1 -1
- package/dist/cjs/transports/types.js.map +1 -1
- package/dist/cjs/utils/index.js +4 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/reactive.js +104 -0
- package/dist/cjs/utils/reactive.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/api/ItemBuffer.js +21 -0
- package/dist/esm/api/ItemBuffer.js.map +1 -0
- package/dist/esm/api/apiTestHelpers.js +33 -0
- package/dist/esm/api/apiTestHelpers.js.map +1 -0
- package/dist/esm/api/const.js +4 -0
- package/dist/esm/api/const.js.map +1 -0
- package/dist/esm/api/events/initialize.js +15 -7
- package/dist/esm/api/events/initialize.js.map +1 -1
- package/dist/esm/api/events/types.js.map +1 -1
- package/dist/esm/api/exceptions/initialize.js +56 -35
- package/dist/esm/api/exceptions/initialize.js.map +1 -1
- package/dist/esm/api/exceptions/types.js.map +1 -1
- package/dist/esm/api/index.js +2 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/initialize.js +15 -1
- package/dist/esm/api/initialize.js.map +1 -1
- package/dist/esm/api/logs/initialize.js +12 -4
- package/dist/esm/api/logs/initialize.js.map +1 -1
- package/dist/esm/api/logs/types.js.map +1 -1
- package/dist/esm/api/measurements/initialize.js +12 -4
- package/dist/esm/api/measurements/initialize.js.map +1 -1
- package/dist/esm/api/measurements/types.js.map +1 -1
- package/dist/esm/api/meta/initialize.js +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/userActionLifecycleHandler.js +43 -0
- package/dist/esm/api/userActionLifecycleHandler.js.map +1 -0
- package/dist/esm/api/utils.js +7 -0
- package/dist/esm/api/utils.js.map +1 -0
- package/dist/esm/config/types.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/transports/initialize.js +0 -28
- package/dist/esm/transports/initialize.js.map +1 -1
- package/dist/esm/transports/registerInitial.js +0 -1
- package/dist/esm/transports/registerInitial.js.map +1 -1
- package/dist/esm/transports/types.js.map +1 -1
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/reactive.js +93 -0
- package/dist/esm/utils/reactive.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/spec/core/src/api/ItemBuffer.js +27 -0
- package/dist/spec/core/src/api/ItemBuffer.js.map +1 -0
- package/dist/spec/core/src/api/apiTestHelpers.js +36 -0
- package/dist/spec/core/src/api/apiTestHelpers.js.map +1 -0
- package/dist/spec/core/src/api/const.js +7 -0
- package/dist/spec/core/src/api/const.js.map +1 -0
- package/dist/spec/core/src/api/events/initialize.js +15 -6
- package/dist/spec/core/src/api/events/initialize.js.map +1 -1
- package/dist/spec/core/src/api/events/initialize.test.js +57 -0
- package/dist/spec/core/src/api/events/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/events/types.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.js +59 -37
- package/dist/spec/core/src/api/exceptions/initialize.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.test.js +83 -3
- package/dist/spec/core/src/api/exceptions/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/types.js.map +1 -1
- package/dist/spec/core/src/api/index.js +7 -1
- package/dist/spec/core/src/api/index.js.map +1 -1
- package/dist/spec/core/src/api/initialize.js +16 -2
- package/dist/spec/core/src/api/initialize.js.map +1 -1
- package/dist/spec/core/src/api/initialize.test.js +73 -0
- package/dist/spec/core/src/api/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/itemBuffer.test.js +36 -0
- package/dist/spec/core/src/api/itemBuffer.test.js.map +1 -0
- package/dist/spec/core/src/api/logs/initialize.js +15 -6
- package/dist/spec/core/src/api/logs/initialize.js.map +1 -1
- package/dist/spec/core/src/api/logs/initialize.test.js +98 -0
- package/dist/spec/core/src/api/logs/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/logs/types.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.js +12 -3
- package/dist/spec/core/src/api/measurements/initialize.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.test.js +105 -0
- package/dist/spec/core/src/api/measurements/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/measurements/types.js.map +1 -1
- package/dist/spec/core/src/api/meta/initialize.js +2 -1
- package/dist/spec/core/src/api/meta/initialize.js.map +1 -1
- package/dist/spec/core/src/api/meta/initilialize.test.js +1 -3
- package/dist/spec/core/src/api/meta/initilialize.test.js.map +1 -1
- package/dist/spec/core/src/api/types.js.map +1 -1
- package/dist/spec/core/src/api/userActionLifecycleHandler.js +59 -0
- package/dist/spec/core/src/api/userActionLifecycleHandler.js.map +1 -0
- package/dist/spec/core/src/api/userActionLifecycleHandler.test.js +152 -0
- package/dist/spec/core/src/api/userActionLifecycleHandler.test.js.map +1 -0
- package/dist/spec/core/src/api/utils.js +11 -0
- package/dist/spec/core/src/api/utils.js.map +1 -0
- package/dist/spec/core/src/api/utils.test.js +20 -0
- package/dist/spec/core/src/api/utils.test.js.map +1 -0
- package/dist/spec/core/src/config/types.js.map +1 -1
- package/dist/spec/core/src/index.js +8 -2
- package/dist/spec/core/src/index.js.map +1 -1
- package/dist/spec/core/src/transports/initialize.js +1 -35
- package/dist/spec/core/src/transports/initialize.js.map +1 -1
- package/dist/spec/core/src/transports/registerInitial.js +0 -1
- package/dist/spec/core/src/transports/registerInitial.js.map +1 -1
- package/dist/spec/core/src/transports/transports.test.js +0 -16
- package/dist/spec/core/src/transports/transports.test.js.map +1 -1
- package/dist/spec/core/src/transports/types.js.map +1 -1
- package/dist/spec/core/src/utils/index.js +4 -1
- package/dist/spec/core/src/utils/index.js.map +1 -1
- package/dist/spec/core/src/utils/reactive.js +104 -0
- package/dist/spec/core/src/utils/reactive.js.map +1 -0
- package/dist/spec/core/src/utils/reactive.test.js +104 -0
- package/dist/spec/core/src/utils/reactive.test.js.map +1 -0
- package/dist/spec/core/src/version.js +1 -1
- package/dist/spec/core/src/version.js.map +1 -1
- package/dist/types/api/ItemBuffer.d.ts +7 -0
- package/dist/types/api/apiTestHelpers.d.ts +11 -0
- package/dist/types/api/const.d.ts +3 -0
- package/dist/types/api/events/initialize.d.ts +13 -2
- package/dist/types/api/events/types.d.ts +11 -0
- package/dist/types/api/exceptions/initialize.d.ts +13 -2
- package/dist/types/api/exceptions/types.d.ts +2 -0
- package/dist/types/api/index.d.ts +3 -1
- package/dist/types/api/initialize.d.ts +3 -1
- package/dist/types/api/logs/initialize.d.ts +13 -2
- package/dist/types/api/logs/types.d.ts +3 -1
- package/dist/types/api/measurements/initialize.d.ts +13 -1
- package/dist/types/api/measurements/types.d.ts +2 -0
- package/dist/types/api/meta/initialize.d.ts +14 -2
- package/dist/types/api/types.d.ts +37 -0
- package/dist/types/api/userActionLifecycleHandler.d.ts +13 -0
- package/dist/types/api/utils.d.ts +2 -0
- package/dist/types/config/types.d.ts +21 -12
- package/dist/types/core/src/api/ItemBuffer.d.ts +7 -0
- package/dist/types/core/src/api/apiTestHelpers.d.ts +11 -0
- package/dist/types/core/src/api/const.d.ts +3 -0
- package/dist/types/core/src/api/events/initialize.d.ts +13 -2
- package/dist/types/core/src/api/events/types.d.ts +11 -0
- package/dist/types/core/src/api/exceptions/initialize.d.ts +13 -2
- package/dist/types/core/src/api/exceptions/types.d.ts +2 -0
- package/dist/types/core/src/api/index.d.ts +3 -1
- package/dist/types/core/src/api/initialize.d.ts +3 -1
- package/dist/types/core/src/api/initialize.test.d.ts +1 -0
- package/dist/types/core/src/api/itemBuffer.test.d.ts +1 -0
- package/dist/types/core/src/api/logs/initialize.d.ts +13 -2
- package/dist/types/core/src/api/logs/types.d.ts +3 -1
- package/dist/types/core/src/api/measurements/initialize.d.ts +13 -1
- package/dist/types/core/src/api/measurements/types.d.ts +2 -0
- package/dist/types/core/src/api/meta/initialize.d.ts +14 -2
- package/dist/types/core/src/api/types.d.ts +37 -0
- package/dist/types/core/src/api/userActionLifecycleHandler.d.ts +13 -0
- package/dist/types/core/src/api/userActionLifecycleHandler.test.d.ts +1 -0
- package/dist/types/core/src/api/utils.d.ts +2 -0
- package/dist/types/core/src/api/utils.test.d.ts +1 -0
- package/dist/types/core/src/config/types.d.ts +21 -12
- package/dist/types/core/src/index.d.ts +4 -4
- package/dist/types/core/src/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/core/src/transports/initialize.d.ts +2 -4
- package/dist/types/core/src/transports/types.d.ts +0 -1
- package/dist/types/core/src/utils/index.d.ts +2 -0
- package/dist/types/core/src/utils/reactive.d.ts +46 -0
- package/dist/types/core/src/utils/reactive.test.d.ts +1 -0
- package/dist/types/core/src/version.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/transports/initialize.d.ts +2 -4
- package/dist/types/transports/types.d.ts +0 -1
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/reactive.d.ts +46 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiTestHelpers.js","sourceRoot":"","sources":["../../../src/api/apiTestHelpers.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,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;AAEF,MAAM,CAAC,MAAM,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;AAEF,MAAM,CAAC,MAAM,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","sourcesContent":["import type { Transports } from '../transports';\n\nimport type { TracesAPI } from './traces/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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/api/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,8BAA8B,GAAG,mBAAmB,CAAC;AAClE,MAAM,CAAC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAC9D,MAAM,CAAC,MAAM,+BAA+B,GAAG,oBAAoB,CAAC","sourcesContent":["export const USER_ACTION_START_MESSAGE_TYPE = 'user-action-start';\nexport const USER_ACTION_END_MESSAGE_TYPE = 'user-action-end';\nexport const USER_ACTION_CANCEL_MESSAGE_TYPE = 'user-action-cancel';\n"]}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { TransportItemType } from '../../transports';
|
|
2
|
-
import { deepEqual, getCurrentTimestamp, isNull, stringifyObjectValues } from '../../utils';
|
|
2
|
+
import { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';
|
|
3
3
|
import { timestampToIsoString } from '../../utils/date';
|
|
4
|
-
|
|
4
|
+
import { USER_ACTION_START_MESSAGE_TYPE } from '../const';
|
|
5
|
+
export function initializeEventsAPI({ internalLogger, config, metas, transports, tracesApi, actionBuffer, getMessage, }) {
|
|
5
6
|
let lastPayload = null;
|
|
6
|
-
const pushEvent = (name, attributes, domain, { skipDedupe, spanContext, timestampOverwriteMs } = {}) => {
|
|
7
|
+
const pushEvent = (name, attributes, domain, { skipDedupe, spanContext, timestampOverwriteMs, customPayloadTransformer = (payload) => payload } = {}) => {
|
|
7
8
|
try {
|
|
9
|
+
const attrs = stringifyObjectValues(attributes);
|
|
8
10
|
const item = {
|
|
9
11
|
meta: metas.value,
|
|
10
|
-
payload: {
|
|
12
|
+
payload: customPayloadTransformer({
|
|
11
13
|
name,
|
|
12
14
|
domain: domain !== null && domain !== void 0 ? domain : config.eventDomain,
|
|
13
|
-
attributes:
|
|
15
|
+
attributes: isEmpty(attrs) ? undefined : attrs,
|
|
14
16
|
timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(),
|
|
15
17
|
trace: spanContext
|
|
16
18
|
? {
|
|
@@ -18,7 +20,7 @@ export function initializeEventsAPI(_unpatchedConsole, internalLogger, config, m
|
|
|
18
20
|
span_id: spanContext.spanId,
|
|
19
21
|
}
|
|
20
22
|
: tracesApi.getTraceContext(),
|
|
21
|
-
},
|
|
23
|
+
}),
|
|
22
24
|
type: TransportItemType.EVENT,
|
|
23
25
|
};
|
|
24
26
|
const testingPayload = {
|
|
@@ -32,7 +34,13 @@ export function initializeEventsAPI(_unpatchedConsole, internalLogger, config, m
|
|
|
32
34
|
}
|
|
33
35
|
lastPayload = testingPayload;
|
|
34
36
|
internalLogger.debug('Pushing event\n', item);
|
|
35
|
-
|
|
37
|
+
const msg = getMessage();
|
|
38
|
+
if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {
|
|
39
|
+
actionBuffer.addItem(item);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
transports.execute(item);
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
catch (err) {
|
|
38
46
|
internalLogger.error('Error pushing event', err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/events/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/events/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAO1D,MAAM,UAAU,mBAAmB,CAAC,EAClC,cAAc,EACd,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,GAUX;IACC,IAAI,WAAW,GAA8D,IAAI,CAAC;IAElF,MAAM,SAAS,GAA2B,CACxC,IAAI,EACJ,UAAU,EACV,MAAM,EACN,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,wBAAwB,GAAG,CAAC,OAAmB,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,EACnH,EAAE;QACF,IAAI;YACF,MAAM,KAAK,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;YAEhD,MAAM,IAAI,GAA8B;gBACtC,IAAI,EAAE,KAA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AC5B;iBAAM;gBACL,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC1B;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC,CAAC;IAEF,OAAO;QACL,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItemType } from '../../transports';\nimport type { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport { USER_ACTION_START_MESSAGE_TYPE } from '../const';\nimport type { ItemBuffer } from '../ItemBuffer';\nimport type { TracesAPI } from '../traces';\nimport type { ApiMessageBusMessages } from '../types';\n\nimport type { EventEvent, EventsAPI } from './types';\n\nexport function initializeEventsAPI({\n internalLogger,\n config,\n metas,\n transports,\n tracesApi,\n actionBuffer,\n getMessage,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n actionBuffer: ItemBuffer<TransportItem>;\n getMessage: () => ApiMessageBusMessages | undefined;\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 msg = getMessage();\n if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {\n actionBuffer.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/events/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\n\nexport type EventAttributes = Record<string, string>;\n\nexport interface EventEvent {\n name: string;\n timestamp: string;\n\n domain?: string;\n attributes?: EventAttributes;\n trace?: TraceContext;\n}\n\nexport interface PushEventOptions {\n skipDedupe?: boolean;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\nexport interface EventsAPI {\n pushEvent: (name: string, attributes?: EventAttributes, domain?: string, options?: PushEventOptions) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/events/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\nimport type { UserAction } from '../types';\n\nexport type EventAttributes = Record<string, string>;\n\nexport interface EventEvent {\n name: string;\n timestamp: string;\n\n domain?: string;\n attributes?: EventAttributes;\n trace?: TraceContext;\n\n action?: UserAction;\n}\n\nexport interface PushEventOptions {\n skipDedupe?: boolean;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n\n /**\n * Allows manual transformation of the payload before adding it to the internal buffer.\n *\n * @param payload - The event payload to be transformed.\n * @returns The transformed event payload.\n *\n * @remarks This should be used sparingly and only in special cases where custom payload processing cannot be deferred to the before-send hook.\n */\n customPayloadTransformer?: (payload: EventEvent) => EventEvent;\n}\n\nexport interface EventsAPI {\n pushEvent: (name: string, attributes?: EventAttributes, domain?: string, options?: PushEventOptions) => void;\n}\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { TransportItemType } from '../../transports';
|
|
2
|
-
import { deepEqual, getCurrentTimestamp, isArray, isError, isNull, isObject, stringifyExternalJson, stringifyObjectValues, } from '../../utils';
|
|
2
|
+
import { deepEqual, getCurrentTimestamp, isArray, isEmpty, isError, isNull, isObject, stringifyExternalJson, stringifyObjectValues, } from '../../utils';
|
|
3
3
|
import { timestampToIsoString } from '../../utils/date';
|
|
4
|
+
import { USER_ACTION_START_MESSAGE_TYPE } from '../const';
|
|
5
|
+
import { shouldIgnoreEvent } from '../utils';
|
|
4
6
|
import { defaultExceptionType } from './const';
|
|
5
7
|
let stacktraceParser;
|
|
6
|
-
export function initializeExceptionsAPI(
|
|
8
|
+
export function initializeExceptionsAPI({ internalLogger, config, metas, transports, tracesApi, actionBuffer, getMessage, }) {
|
|
7
9
|
var _a;
|
|
8
10
|
internalLogger.debug('Initializing exceptions API');
|
|
9
11
|
let lastPayload = null;
|
|
@@ -13,43 +15,58 @@ export function initializeExceptionsAPI(_unpatchedConsole, internalLogger, confi
|
|
|
13
15
|
stacktraceParser = newStacktraceParser !== null && newStacktraceParser !== void 0 ? newStacktraceParser : stacktraceParser;
|
|
14
16
|
};
|
|
15
17
|
const getStacktraceParser = () => stacktraceParser;
|
|
18
|
+
const { ignoreErrors = [] } = config;
|
|
16
19
|
const pushError = (error, { skipDedupe, stackFrames, type, context, spanContext, timestampOverwriteMs } = {}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
if (isErrorIgnored(ignoreErrors, error)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const ctx = stringifyObjectValues(Object.assign(Object.assign({}, parseCause(error)), (context !== null && context !== void 0 ? context : {})));
|
|
25
|
+
const item = {
|
|
26
|
+
meta: metas.value,
|
|
27
|
+
payload: {
|
|
28
|
+
type: type || error.name || defaultExceptionType,
|
|
29
|
+
value: error.message,
|
|
30
|
+
timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(),
|
|
31
|
+
trace: spanContext
|
|
32
|
+
? {
|
|
33
|
+
trace_id: spanContext.traceId,
|
|
34
|
+
span_id: spanContext.spanId,
|
|
35
|
+
}
|
|
36
|
+
: tracesApi.getTraceContext(),
|
|
37
|
+
context: isEmpty(ctx) ? undefined : ctx,
|
|
38
|
+
},
|
|
39
|
+
type: TransportItemType.EXCEPTION,
|
|
40
|
+
};
|
|
41
|
+
stackFrames = stackFrames !== null && stackFrames !== void 0 ? stackFrames : (error.stack ? stacktraceParser === null || stacktraceParser === void 0 ? void 0 : stacktraceParser(error).frames : undefined);
|
|
42
|
+
if (stackFrames === null || stackFrames === void 0 ? void 0 : stackFrames.length) {
|
|
43
|
+
item.payload.stacktrace = {
|
|
44
|
+
frames: stackFrames,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const testingPayload = {
|
|
48
|
+
type: item.payload.type,
|
|
49
|
+
value: item.payload.value,
|
|
50
|
+
stackTrace: item.payload.stacktrace,
|
|
51
|
+
context: item.payload.context,
|
|
38
52
|
};
|
|
53
|
+
if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {
|
|
54
|
+
internalLogger.debug('Skipping error push because it is the same as the last one\n', item.payload);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
lastPayload = testingPayload;
|
|
58
|
+
internalLogger.debug('Pushing exception\n', item);
|
|
59
|
+
const msg = getMessage();
|
|
60
|
+
if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {
|
|
61
|
+
actionBuffer.addItem(item);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
transports.execute(item);
|
|
65
|
+
}
|
|
39
66
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
value: item.payload.value,
|
|
43
|
-
stackTrace: item.payload.stacktrace,
|
|
44
|
-
context: item.payload.context,
|
|
45
|
-
};
|
|
46
|
-
if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {
|
|
47
|
-
internalLogger.debug('Skipping error push because it is the same as the last one\n', item.payload);
|
|
48
|
-
return;
|
|
67
|
+
catch (err) {
|
|
68
|
+
internalLogger.error('Error pushing event', err);
|
|
49
69
|
}
|
|
50
|
-
lastPayload = testingPayload;
|
|
51
|
-
internalLogger.debug('Pushing exception\n', item);
|
|
52
|
-
transports.execute(item);
|
|
53
70
|
};
|
|
54
71
|
changeStacktraceParser(config.parseStacktrace);
|
|
55
72
|
return {
|
|
@@ -73,4 +90,8 @@ function parseCause(error) {
|
|
|
73
90
|
}
|
|
74
91
|
return cause == null ? {} : { cause };
|
|
75
92
|
}
|
|
93
|
+
function isErrorIgnored(ignoreErrors, error) {
|
|
94
|
+
const { message, name, stack } = error;
|
|
95
|
+
return shouldIgnoreEvent(ignoreErrors, message + ' ' + name + ' ' + stack);
|
|
96
|
+
}
|
|
76
97
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/exceptions/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,OAAO,EACP,OAAO,EACP,MAAM,EACN,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/exceptions/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,OAAO,EACP,OAAO,EACP,OAAO,EACP,MAAM,EACN,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAI1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAG/C,IAAI,gBAA8C,CAAC;AAEnD,MAAM,UAAU,uBAAuB,CAAC,EACtC,cAAc,EACd,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,GAUX;;IACC,cAAc,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAEpD,IAAI,WAAW,GAA6E,IAAI,CAAC;IAEjG,gBAAgB,GAAG,MAAA,MAAM,CAAC,eAAe,mCAAI,gBAAgB,CAAC;IAE9D,MAAM,sBAAsB,GAA4C,CAAC,mBAAmB,EAAE,EAAE;QAC9F,cAAc,CAAC,KAAK,CAAC,4BAA4B,CAAC,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AAM,CAAC,eAAe,CAAC,CAAC;IAE/C,OAAO;QACL,sBAAsB;QACtB,mBAAmB;QACnB,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAA+B;IACjD,IAAI,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAExB,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC/B,wKAAwK;QACxK,sGAAsG;KACvG;SAAM,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;QAC5E,KAAK,GAAG,qBAAqB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KAC5C;SAAM,IAAI,KAAK,IAAI,IAAI,EAAE;QACxB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;KAChC;IAED,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,cAAc,CAAC,YAAsB,EAAE,KAA+B;IAC7E,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACvC,OAAO,iBAAiB,CAAC,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 { USER_ACTION_START_MESSAGE_TYPE } from '../const';\nimport type { ItemBuffer } from '../ItemBuffer';\nimport type { TracesAPI } from '../traces';\nimport type { ApiMessageBusMessages } from '../types';\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 actionBuffer,\n getMessage,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n actionBuffer: ItemBuffer<TransportItem>;\n getMessage: () => ApiMessageBusMessages | undefined;\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 = [] } = config;\n\n const pushError: ExceptionsAPI['pushError'] = (\n error,\n { skipDedupe, stackFrames, type, context, spanContext, timestampOverwriteMs } = {}\n ) => {\n if (isErrorIgnored(ignoreErrors, error)) {\n return;\n }\n try {\n const ctx = stringifyObjectValues({\n ...parseCause(error),\n ...(context ?? {}),\n });\n\n const item: TransportItem<ExceptionEvent> = {\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 context: isEmpty(ctx) ? undefined : ctx,\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 msg = getMessage();\n if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {\n actionBuffer.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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n\n bundleid?: string;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport type ExceptionContext = Record<string, string>;\n\nexport interface ExceptionEvent {\n timestamp: string;\n type: string;\n value: string;\n\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n context?: ExceptionContext;\n}\n\nexport interface PushErrorOptions {\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n context?: ExceptionContext;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\n// ts type is missing the cause property\nexport type ErrorWithIndexProperties = Error & {\n cause?: any;\n};\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: ErrorWithIndexProperties, options?: PushErrorOptions) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\nimport type { UserAction } from '../types';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n\n bundleid?: string;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport type ExceptionContext = Record<string, string>;\n\nexport interface ExceptionEvent {\n timestamp: string;\n type: string;\n value: string;\n\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n context?: ExceptionContext;\n\n action?: UserAction;\n}\n\nexport interface PushErrorOptions {\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n context?: ExceptionContext;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\n// ts type is missing the cause property\nexport type ErrorWithIndexProperties = Error & {\n cause?: any;\n};\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: ErrorWithIndexProperties, options?: PushErrorOptions) => void;\n}\n"]}
|
package/dist/esm/api/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { initializeAPI } from './initialize';
|
|
2
2
|
export { defaultExceptionType, defaultErrorArgsSerializer } from './exceptions';
|
|
3
3
|
export { defaultLogArgsSerializer } from './logs';
|
|
4
|
+
export { apiMessageBus } from './initialize';
|
|
5
|
+
export { USER_ACTION_CANCEL_MESSAGE_TYPE, USER_ACTION_END_MESSAGE_TYPE, USER_ACTION_START_MESSAGE_TYPE } from './const';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAa7C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAWhF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AASlD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,+BAA+B,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export { initializeAPI } from './initialize';\nexport type {\n API,\n APIEvent,\n ApiMessageBusMessages,\n UserActionCancelMessage,\n UserActionEndMessage,\n UserActionStartMessage,\n UserAction,\n} from './types';\n\nexport type { EventAttributes, EventEvent, EventsAPI, PushEventOptions } from './events';\n\nexport { defaultExceptionType, defaultErrorArgsSerializer } from './exceptions';\nexport type {\n ExceptionEvent,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n PushErrorOptions,\n Stacktrace,\n StacktraceParser,\n} from './exceptions';\n\nexport { defaultLogArgsSerializer } from './logs';\nexport type { LogContext, LogEvent, LogArgsSerializer, LogsAPI, PushLogOptions } from './logs';\n\nexport type { MeasurementEvent, MeasurementsAPI, PushMeasurementOptions } from './measurements';\n\nexport type { MetaAPI } from './meta';\n\nexport type { OTELApi, TraceContext, TraceEvent, TracesAPI } from './traces';\n\nexport { apiMessageBus } from './initialize';\n\nexport { USER_ACTION_CANCEL_MESSAGE_TYPE, USER_ACTION_END_MESSAGE_TYPE, USER_ACTION_START_MESSAGE_TYPE } from './const';\n"]}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
import { Observable } from '../utils';
|
|
1
2
|
import { initializeEventsAPI } from './events';
|
|
2
3
|
import { initializeExceptionsAPI } from './exceptions';
|
|
3
4
|
import { initializeLogsAPI } from './logs';
|
|
4
5
|
import { initializeMeasurementsAPI } from './measurements';
|
|
5
6
|
import { initializeMetaAPI } from './meta';
|
|
6
7
|
import { initializeTracesAPI } from './traces';
|
|
8
|
+
import { createUserActionLifecycleHandler } from './userActionLifecycleHandler';
|
|
9
|
+
export const apiMessageBus = new Observable();
|
|
7
10
|
export function initializeAPI(unpatchedConsole, internalLogger, config, metas, transports) {
|
|
8
11
|
internalLogger.debug('Initializing API');
|
|
12
|
+
const { actionBuffer, getMessage } = createUserActionLifecycleHandler({ apiMessageBus, transports, config });
|
|
9
13
|
const tracesApi = initializeTracesAPI(unpatchedConsole, internalLogger, config, metas, transports);
|
|
10
|
-
|
|
14
|
+
const props = {
|
|
15
|
+
unpatchedConsole,
|
|
16
|
+
internalLogger,
|
|
17
|
+
config,
|
|
18
|
+
metas,
|
|
19
|
+
transports,
|
|
20
|
+
tracesApi,
|
|
21
|
+
actionBuffer,
|
|
22
|
+
getMessage,
|
|
23
|
+
};
|
|
24
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, tracesApi), initializeExceptionsAPI(props)), initializeMetaAPI(props)), initializeLogsAPI(props)), initializeMeasurementsAPI(props)), initializeEventsAPI(props));
|
|
11
25
|
}
|
|
12
26
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/api/initialize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/api/initialize.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAEhF,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,UAAU,EAAyB,CAAC;AAErE,MAAM,UAAU,aAAa,CAC3B,gBAAkC,EAClC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB;IAEtB,cAAc,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAEzC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,gCAAgC,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IAE7G,MAAM,SAAS,GAAG,mBAAmB,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IAEnG,MAAM,KAAK,GAAG;QACZ,gBAAgB;QAChB,cAAc;QACd,MAAM;QACN,KAAK;QACL,UAAU;QACV,SAAS;QACT,YAAY;QACZ,UAAU;KACX,CAAC;IAEF,+FACK,SAAS,GACT,uBAAuB,CAAC,KAAK,CAAC,GAC9B,iBAAiB,CAAC,KAAK,CAAC,GACxB,iBAAiB,CAAC,KAAK,CAAC,GACxB,yBAAyB,CAAC,KAAK,CAAC,GAChC,mBAAmB,CAAC,KAAK,CAAC,EAC7B;AACJ,CAAC","sourcesContent":["import type { Config } from '../config';\nimport type { InternalLogger } from '../internalLogger';\nimport type { Metas } from '../metas';\nimport type { Transports } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\nimport { Observable } from '../utils';\n\nimport { initializeEventsAPI } from './events';\nimport { initializeExceptionsAPI } from './exceptions';\nimport { initializeLogsAPI } from './logs';\nimport { initializeMeasurementsAPI } from './measurements';\nimport { initializeMetaAPI } from './meta';\nimport { initializeTracesAPI } from './traces';\nimport type { API, ApiMessageBusMessages } from './types';\nimport { createUserActionLifecycleHandler } from './userActionLifecycleHandler';\n\nexport const apiMessageBus = new Observable<ApiMessageBusMessages>();\n\nexport function initializeAPI(\n unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports\n): API {\n internalLogger.debug('Initializing API');\n\n const { actionBuffer, getMessage } = createUserActionLifecycleHandler({ apiMessageBus, transports, config });\n\n const tracesApi = initializeTracesAPI(unpatchedConsole, internalLogger, config, metas, transports);\n\n const props = {\n unpatchedConsole,\n internalLogger,\n config,\n metas,\n transports,\n tracesApi,\n actionBuffer,\n getMessage,\n };\n\n return {\n ...tracesApi,\n ...initializeExceptionsAPI(props),\n ...initializeMetaAPI(props),\n ...initializeLogsAPI(props),\n ...initializeMeasurementsAPI(props),\n ...initializeEventsAPI(props),\n };\n}\n"]}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { TransportItemType } from '../../transports';
|
|
2
|
-
import { deepEqual, defaultLogLevel, getCurrentTimestamp, isNull, stringifyObjectValues } from '../../utils';
|
|
2
|
+
import { deepEqual, defaultLogLevel, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';
|
|
3
3
|
import { timestampToIsoString } from '../../utils/date';
|
|
4
|
+
import { USER_ACTION_START_MESSAGE_TYPE } from '../const';
|
|
4
5
|
import { defaultLogArgsSerializer } from './const';
|
|
5
|
-
export function initializeLogsAPI(
|
|
6
|
+
export function initializeLogsAPI({ internalLogger, config, metas, transports, tracesApi, actionBuffer, getMessage, }) {
|
|
6
7
|
var _a;
|
|
7
8
|
internalLogger.debug('Initializing logs API');
|
|
8
9
|
let lastPayload = null;
|
|
9
10
|
const logArgsSerializer = (_a = config.logArgsSerializer) !== null && _a !== void 0 ? _a : defaultLogArgsSerializer;
|
|
10
11
|
const pushLog = (args, { context, level, skipDedupe, spanContext, timestampOverwriteMs } = {}) => {
|
|
11
12
|
try {
|
|
13
|
+
const ctx = stringifyObjectValues(context);
|
|
12
14
|
const item = {
|
|
13
15
|
type: TransportItemType.LOG,
|
|
14
16
|
payload: {
|
|
15
17
|
message: logArgsSerializer(args),
|
|
16
18
|
level: level !== null && level !== void 0 ? level : defaultLogLevel,
|
|
17
|
-
context:
|
|
19
|
+
context: isEmpty(ctx) ? undefined : ctx,
|
|
18
20
|
timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(),
|
|
19
21
|
trace: spanContext
|
|
20
22
|
? {
|
|
@@ -36,7 +38,13 @@ export function initializeLogsAPI(_unpatchedConsole, internalLogger, config, met
|
|
|
36
38
|
}
|
|
37
39
|
lastPayload = testingPayload;
|
|
38
40
|
internalLogger.debug('Pushing log\n', item);
|
|
39
|
-
|
|
41
|
+
const msg = getMessage();
|
|
42
|
+
if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {
|
|
43
|
+
actionBuffer.addItem(item);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
transports.execute(item);
|
|
47
|
+
}
|
|
40
48
|
}
|
|
41
49
|
catch (err) {
|
|
42
50
|
internalLogger.error('Error pushing log\n', err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/logs/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/logs/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,EAAc,MAAM,kBAAkB,CAAC;AAEhF,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;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAK1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGnD,MAAM,UAAU,iBAAiB,CAAC,EAChC,cAAc,EACd,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,GAUX;;IACC,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAE9C,IAAI,WAAW,GAA2D,IAAI,CAAC;IAE/E,MAAM,iBAAiB,GAAG,MAAA,MAAM,CAAC,iBAAiB,mCAAI,wBAAwB,CAAC;IAE/E,MAAM,OAAO,GAAuB,CAClC,IA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E7B,cAAc,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;YAE5C,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;YACzB,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,8BAA8B,EAAE;gBACtD,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC5B;iBAAM;gBACL,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC1B;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;SAClD;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 { TransportItem, TransportItemType, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, defaultLogLevel, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport { USER_ACTION_START_MESSAGE_TYPE } from '../const';\nimport type { ItemBuffer } from '../ItemBuffer';\nimport type { TracesAPI } from '../traces';\nimport type { ApiMessageBusMessages } from '../types';\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 actionBuffer,\n getMessage,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n actionBuffer: ItemBuffer<TransportItem>;\n getMessage: () => ApiMessageBusMessages | undefined;\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 msg = getMessage();\n if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {\n actionBuffer.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/logs/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { LogLevel } from '../../utils';\nimport type { TraceContext } from '../traces';\n\nexport type LogContext = Record<string, string>;\n\nexport interface LogEvent {\n context: LogContext;\n level: LogLevel;\n message: string;\n timestamp: string;\n\n trace?: TraceContext;\n}\n\nexport interface PushLogOptions {\n context?: LogContext;\n level?: LogLevel;\n skipDedupe?: boolean;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\nexport interface LogsAPI {\n pushLog: (args: unknown[], options?: PushLogOptions) => void;\n}\n\nexport type LogArgsSerializer = (args: unknown[]) => string;\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/logs/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { LogLevel } from '../../utils';\nimport type { TraceContext } from '../traces';\nimport type { UserAction } from '../types';\n\nexport type LogContext = Record<string, string>;\n\nexport interface LogEvent {\n context: LogContext | undefined;\n level: LogLevel;\n message: string;\n timestamp: string;\n\n trace?: TraceContext;\n action?: UserAction;\n}\n\nexport interface PushLogOptions {\n context?: LogContext;\n level?: LogLevel;\n skipDedupe?: boolean;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\nexport interface LogsAPI {\n pushLog: (args: unknown[], options?: PushLogOptions) => void;\n}\n\nexport type LogArgsSerializer = (args: unknown[]) => string;\n"]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { TransportItemType } from '../../transports';
|
|
2
|
-
import { deepEqual, getCurrentTimestamp, isNull, stringifyObjectValues } from '../../utils';
|
|
2
|
+
import { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';
|
|
3
3
|
import { timestampToIsoString } from '../../utils/date';
|
|
4
|
-
|
|
4
|
+
import { USER_ACTION_START_MESSAGE_TYPE } from '../const';
|
|
5
|
+
export function initializeMeasurementsAPI({ internalLogger, config, metas, transports, tracesApi, actionBuffer, getMessage, }) {
|
|
5
6
|
internalLogger.debug('Initializing measurements API');
|
|
6
7
|
let lastPayload = null;
|
|
7
8
|
const pushMeasurement = (payload, { skipDedupe, context, spanContext, timestampOverwriteMs } = {}) => {
|
|
8
9
|
try {
|
|
10
|
+
const ctx = stringifyObjectValues(context);
|
|
9
11
|
const item = {
|
|
10
12
|
type: TransportItemType.MEASUREMENT,
|
|
11
13
|
payload: Object.assign(Object.assign({}, payload), { trace: spanContext
|
|
@@ -13,7 +15,7 @@ export function initializeMeasurementsAPI(_unpatchedConsole, internalLogger, con
|
|
|
13
15
|
trace_id: spanContext.traceId,
|
|
14
16
|
span_id: spanContext.spanId,
|
|
15
17
|
}
|
|
16
|
-
: tracesApi.getTraceContext(), timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(), context:
|
|
18
|
+
: tracesApi.getTraceContext(), timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(), context: isEmpty(ctx) ? undefined : ctx }),
|
|
17
19
|
meta: metas.value,
|
|
18
20
|
};
|
|
19
21
|
const testingPayload = {
|
|
@@ -27,7 +29,13 @@ export function initializeMeasurementsAPI(_unpatchedConsole, internalLogger, con
|
|
|
27
29
|
}
|
|
28
30
|
lastPayload = testingPayload;
|
|
29
31
|
internalLogger.debug('Pushing measurement\n', item);
|
|
30
|
-
|
|
32
|
+
const msg = getMessage();
|
|
33
|
+
if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {
|
|
34
|
+
actionBuffer.addItem(item);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
transports.execute(item);
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
catch (err) {
|
|
33
41
|
internalLogger.error('Error pushing measurement\n', err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,O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AC,OAAO;aAC9B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE;gBAClG,cAAc,CAAC,KAAK,CAAC,oEAAoE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEzG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;YACzB,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,8BAA8B,EAAE;gBACtD,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC5B;iBAAM;gBACL,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC1B;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SAC1D;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 { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport { USER_ACTION_START_MESSAGE_TYPE } from '../const';\nimport type { ItemBuffer } from '../ItemBuffer';\nimport type { TracesAPI } from '../traces';\nimport type { ApiMessageBusMessages } from '../types';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI({\n internalLogger,\n config,\n metas,\n transports,\n tracesApi,\n actionBuffer,\n getMessage,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n actionBuffer: ItemBuffer<TransportItem>;\n getMessage: () => ApiMessageBusMessages | undefined;\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 msg = getMessage();\n if (msg && msg.type === USER_ACTION_START_MESSAGE_TYPE) {\n actionBuffer.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":"types.js","sourceRoot":"","sources":["../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\n\nexport type MeasurementContext = Record<string, string>;\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n timestamp: string;\n trace?: TraceContext;\n context?: MeasurementContext;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n context?: MeasurementContext;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (\n payload: Omit<MeasurementEvent, 'timestamp'> & Partial<Pick<MeasurementEvent, 'timestamp'>>,\n options?: PushMeasurementOptions\n ) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\nimport type { UserAction } from '../types';\n\nexport type MeasurementContext = Record<string, string>;\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n timestamp: string;\n trace?: TraceContext;\n context?: MeasurementContext;\n\n action?: UserAction;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n context?: MeasurementContext;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (\n payload: Omit<MeasurementEvent, 'timestamp'> & Partial<Pick<MeasurementEvent, 'timestamp'>>,\n options?: PushMeasurementOptions\n ) => void;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isEmpty, isString } from '../../utils/is';
|
|
2
|
-
export function initializeMetaAPI(
|
|
2
|
+
export function initializeMetaAPI({ internalLogger, metas, }) {
|
|
3
3
|
internalLogger.debug('Initializing meta API');
|
|
4
4
|
let metaSession = undefined;
|
|
5
5
|
let metaUser = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/meta/initialize.ts"],"names":[],"mappings":"AAKA,OA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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 { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { isEmpty, isString } from '../../utils/is';\nimport type { ItemBuffer } from '../ItemBuffer';\nimport type { TracesAPI } from '../traces';\nimport type { ApiMessageBusMessages } from '../types';\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 actionBuffer: ItemBuffer<TransportItem>;\n getMessage: () => ApiMessageBusMessages | undefined;\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 { 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';\n\nexport type APIEvent = LogEvent | ExceptionEvent | MeasurementEvent | TraceEvent | EventEvent;\n\nexport type API = LogsAPI & ExceptionsAPI & MeasurementsAPI & TracesAPI & MetaAPI & EventsAPI;\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_ACTION_CANCEL_MESSAGE_TYPE,\n USER_ACTION_END_MESSAGE_TYPE,\n USER_ACTION_START_MESSAGE_TYPE,\n} from './const';\nimport 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';\n\nexport type APIEvent = LogEvent | ExceptionEvent | MeasurementEvent | TraceEvent | EventEvent;\n\nexport type API = LogsAPI & ExceptionsAPI & MeasurementsAPI & TracesAPI & MetaAPI & EventsAPI;\n\nexport type ApiMessageBusMessages = UserActionStartMessage | UserActionEndMessage | UserActionCancelMessage;\n\nexport type UserActionMessageType =\n | typeof USER_ACTION_START_MESSAGE_TYPE\n | typeof USER_ACTION_END_MESSAGE_TYPE\n | typeof USER_ACTION_CANCEL_MESSAGE_TYPE;\n\nexport type UserActionStartMessage = {\n type: typeof USER_ACTION_START_MESSAGE_TYPE;\n name: string;\n startTime: number;\n\n /**\n * Unique identifier of the parent user action to which this action belongs.\n */\n parentId: string;\n};\n\nexport type UserActionEndMessage = {\n type: typeof USER_ACTION_END_MESSAGE_TYPE;\n name: string;\n startTime: number;\n endTime: number;\n duration: number;\n eventType: string;\n\n /**\n * Unique identifier for the user action. Will be undefined for messages related to child actions.\n */\n id: string;\n};\n\nexport type UserActionCancelMessage = {\n type: typeof USER_ACTION_CANCEL_MESSAGE_TYPE;\n name: string;\n\n /**\n * Unique identifier of the parent user action to which this action belongs.\n */\n parentId?: string;\n};\n\nexport type UserAction = {\n name: string;\n id?: string;\n parentId?: string;\n};\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TransportItemType } from '../transports';
|
|
2
|
+
import { USER_ACTION_CANCEL_MESSAGE_TYPE, USER_ACTION_END_MESSAGE_TYPE, USER_ACTION_START_MESSAGE_TYPE } from './const';
|
|
3
|
+
import { ItemBuffer } from './ItemBuffer';
|
|
4
|
+
export function createUserActionLifecycleHandler({ apiMessageBus, transports, config, }) {
|
|
5
|
+
const actionBuffer = new ItemBuffer();
|
|
6
|
+
const trackUserActionsExcludeItem = config.trackUserActionsExcludeItem;
|
|
7
|
+
let message;
|
|
8
|
+
apiMessageBus.subscribe((msg) => {
|
|
9
|
+
if (msg.type === USER_ACTION_START_MESSAGE_TYPE) {
|
|
10
|
+
message = msg;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (msg.type === USER_ACTION_END_MESSAGE_TYPE) {
|
|
14
|
+
const { id, name } = msg;
|
|
15
|
+
actionBuffer.flushBuffer((item) => {
|
|
16
|
+
if (isExcludeFromUserAction(item, trackUserActionsExcludeItem)) {
|
|
17
|
+
transports.execute(item);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const userActionItem = Object.assign(Object.assign({}, item), { payload: Object.assign(Object.assign({}, item.payload), { action: {
|
|
21
|
+
parentId: id,
|
|
22
|
+
name,
|
|
23
|
+
} }) });
|
|
24
|
+
transports.execute(userActionItem);
|
|
25
|
+
});
|
|
26
|
+
message = undefined;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (msg.type === USER_ACTION_CANCEL_MESSAGE_TYPE) {
|
|
30
|
+
message = undefined;
|
|
31
|
+
actionBuffer.flushBuffer((item) => {
|
|
32
|
+
transports.execute(item);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const getMessage = () => message;
|
|
37
|
+
return { actionBuffer, getMessage };
|
|
38
|
+
}
|
|
39
|
+
function isExcludeFromUserAction(item, trackUserActionsExcludeItem) {
|
|
40
|
+
return ((trackUserActionsExcludeItem === null || trackUserActionsExcludeItem === void 0 ? void 0 : trackUserActionsExcludeItem(item)) ||
|
|
41
|
+
(item.type === TransportItemType.MEASUREMENT && item.payload.type === 'web-vitals'));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=userActionLifecycleHandler.js.map
|