@cloudcare/browser-core 3.0.23 → 3.1.0
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/cjs/browser/addEventListener.js +11 -14
- package/cjs/browser/addEventListener.js.map +1 -0
- package/cjs/browser/cookie.js +3 -14
- package/cjs/browser/cookie.js.map +1 -0
- package/cjs/browser/fetchObservable.js +8 -23
- package/cjs/browser/fetchObservable.js.map +1 -0
- package/cjs/browser/htmlDomUtils.js +3 -9
- package/cjs/browser/htmlDomUtils.js.map +1 -0
- package/cjs/browser/pageExitObservable.js +3 -9
- package/cjs/browser/pageExitObservable.js.map +1 -0
- package/cjs/browser/runOnReadyState.js +2 -4
- package/cjs/browser/runOnReadyState.js.map +1 -0
- package/cjs/browser/scroll.js +32 -0
- package/cjs/browser/scroll.js.map +1 -0
- package/cjs/browser/xhrObservable.js +2 -21
- package/cjs/browser/xhrObservable.js.map +1 -0
- package/cjs/configuration/configuration.js +9 -20
- package/cjs/configuration/configuration.js.map +1 -0
- package/cjs/configuration/transportConfiguration.js +6 -20
- package/cjs/configuration/transportConfiguration.js.map +1 -0
- package/cjs/console/consoleObservable.js +7 -21
- package/cjs/console/consoleObservable.js.map +1 -0
- package/cjs/dataMap.js +24 -10
- package/cjs/dataMap.js.map +1 -0
- package/cjs/error/trackRuntimeError.js +3 -7
- package/cjs/error/trackRuntimeError.js.map +1 -0
- package/cjs/helper/boundedBuffer.js +2 -6
- package/cjs/helper/boundedBuffer.js.map +1 -0
- package/cjs/helper/byteUtils.js +6 -16
- package/cjs/helper/byteUtils.js.map +1 -0
- package/cjs/helper/catchUserErrors.js +2 -4
- package/cjs/helper/catchUserErrors.js.map +1 -0
- package/cjs/helper/contextHistory.js +21 -37
- package/cjs/helper/contextHistory.js.map +1 -0
- package/cjs/helper/createEventRateLimiter.js +2 -10
- package/cjs/helper/createEventRateLimiter.js.map +1 -0
- package/cjs/helper/deviceInfo.js +10 -64
- package/cjs/helper/deviceInfo.js.map +1 -0
- package/cjs/helper/display.js +2 -5
- package/cjs/helper/display.js.map +1 -0
- package/cjs/helper/enums.js +8 -2
- package/cjs/helper/enums.js.map +1 -0
- package/cjs/helper/errorTools.js +38 -40
- package/cjs/helper/errorTools.js.map +1 -0
- package/cjs/helper/eventEmitter.js +2 -6
- package/cjs/helper/eventEmitter.js.map +1 -0
- package/cjs/helper/getZoneJsOriginalValue.js +2 -5
- package/cjs/helper/getZoneJsOriginalValue.js.map +1 -0
- package/cjs/helper/instrumentMethod.js +11 -21
- package/cjs/helper/instrumentMethod.js.map +1 -0
- package/cjs/helper/lifeCycle.js +2 -9
- package/cjs/helper/lifeCycle.js.map +1 -0
- package/cjs/helper/limitModification.js +4 -22
- package/cjs/helper/limitModification.js.map +1 -0
- package/cjs/helper/mobileUtil.js +2 -20
- package/cjs/helper/mobileUtil.js.map +1 -0
- package/cjs/helper/monitor.js +50 -0
- package/cjs/helper/monitor.js.map +1 -0
- package/cjs/helper/observable.js +2 -9
- package/cjs/helper/observable.js.map +1 -0
- package/cjs/helper/readBytesFromStream.js +8 -16
- package/cjs/helper/readBytesFromStream.js.map +1 -0
- package/cjs/helper/sanitize.js +38 -61
- package/cjs/helper/sanitize.js.map +1 -0
- package/cjs/helper/serialisation/contextManager.js +5 -15
- package/cjs/helper/serialisation/contextManager.js.map +1 -0
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js +2 -7
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js.map +1 -0
- package/cjs/helper/serialisation/jsonStringify.js +6 -12
- package/cjs/helper/serialisation/jsonStringify.js.map +1 -0
- package/cjs/helper/serialisation/rowData.js +3 -10
- package/cjs/helper/serialisation/rowData.js.map +1 -0
- package/cjs/helper/timer.js +5 -9
- package/cjs/helper/timer.js.map +1 -0
- package/cjs/helper/tools.js +58 -463
- package/cjs/helper/tools.js.map +1 -0
- package/cjs/helper/urlPolyfill.js +5 -18
- package/cjs/helper/urlPolyfill.js.map +1 -0
- package/cjs/index.js +35 -93
- package/cjs/index.js.map +1 -0
- package/cjs/init.js +24 -36
- package/cjs/init.js.map +1 -0
- package/cjs/report/reportObservable.js +8 -26
- package/cjs/report/reportObservable.js.map +1 -0
- package/cjs/session/sessionConstants.js +2 -3
- package/cjs/session/sessionConstants.js.map +1 -0
- package/cjs/session/sessionCookieStore.js +11 -46
- package/cjs/session/sessionCookieStore.js.map +1 -0
- package/cjs/session/sessionManagement.js +2 -19
- package/cjs/session/sessionManagement.js.map +1 -0
- package/cjs/session/sessionStore.js +3 -28
- package/cjs/session/sessionStore.js.map +1 -0
- package/cjs/synthetics/syntheticsWorkerValues.js +2 -6
- package/cjs/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/cjs/synthetics/usr.js +2 -8
- package/cjs/synthetics/usr.js.map +1 -0
- package/cjs/telemetry/telemetry.js +125 -0
- package/cjs/telemetry/telemetry.js.map +1 -0
- package/cjs/telemetry/types.js +17 -0
- package/cjs/telemetry/types.js.map +1 -0
- package/cjs/tracekit/computeStackTrace.js +4 -34
- package/cjs/tracekit/computeStackTrace.js.map +1 -0
- package/cjs/tracekit/index.js +2 -3
- package/cjs/tracekit/index.js.map +1 -0
- package/cjs/tracekit/tracekit.js +3 -18
- package/cjs/tracekit/tracekit.js.map +1 -0
- package/cjs/transport/batch.js +7 -56
- package/cjs/transport/batch.js.map +1 -0
- package/cjs/transport/eventBridge.js +2 -7
- package/cjs/transport/eventBridge.js.map +1 -0
- package/cjs/transport/flushController.js +8 -21
- package/cjs/transport/flushController.js.map +1 -0
- package/cjs/transport/httpRequest.js +8 -20
- package/cjs/transport/httpRequest.js.map +1 -0
- package/cjs/transport/index.js +2 -6
- package/cjs/transport/index.js.map +1 -0
- package/cjs/transport/sendWithRetryStrategy.js +4 -23
- package/cjs/transport/sendWithRetryStrategy.js.map +1 -0
- package/cjs/transport/startBatchWithReplica.js +2 -7
- package/cjs/transport/startBatchWithReplica.js.map +1 -0
- package/cjs/user/index.js +2 -3
- package/cjs/user/index.js.map +1 -0
- package/cjs/user/user.js +3 -8
- package/cjs/user/user.js.map +1 -0
- package/cjs/worker.js +2 -2
- package/cjs/worker.js.map +1 -0
- package/esm/browser/addEventListener.js +11 -10
- package/esm/browser/addEventListener.js.map +1 -0
- package/esm/browser/cookie.js +3 -6
- package/esm/browser/cookie.js.map +1 -0
- package/esm/browser/fetchObservable.js +8 -17
- package/esm/browser/fetchObservable.js.map +1 -0
- package/esm/browser/htmlDomUtils.js +3 -2
- package/esm/browser/htmlDomUtils.js.map +1 -0
- package/esm/browser/pageExitObservable.js +3 -2
- package/esm/browser/pageExitObservable.js.map +1 -0
- package/esm/browser/runOnReadyState.js +2 -1
- package/esm/browser/runOnReadyState.js.map +1 -0
- package/esm/browser/scroll.js +25 -0
- package/esm/browser/scroll.js.map +1 -0
- package/esm/browser/xhrObservable.js +2 -14
- package/esm/browser/xhrObservable.js.map +1 -0
- package/esm/configuration/configuration.js +9 -9
- package/esm/configuration/configuration.js.map +1 -0
- package/esm/configuration/transportConfiguration.js +6 -17
- package/esm/configuration/transportConfiguration.js.map +1 -0
- package/esm/console/consoleObservable.js +7 -12
- package/esm/console/consoleObservable.js.map +1 -0
- package/esm/dataMap.js +24 -8
- package/esm/dataMap.js.map +1 -0
- package/esm/error/trackRuntimeError.js +4 -3
- package/esm/error/trackRuntimeError.js.map +1 -0
- package/esm/helper/boundedBuffer.js +2 -4
- package/esm/helper/boundedBuffer.js.map +1 -0
- package/esm/helper/byteUtils.js +6 -13
- package/esm/helper/byteUtils.js.map +1 -0
- package/esm/helper/catchUserErrors.js +2 -2
- package/esm/helper/catchUserErrors.js.map +1 -0
- package/esm/helper/contextHistory.js +21 -33
- package/esm/helper/contextHistory.js.map +1 -0
- package/esm/helper/createEventRateLimiter.js +2 -6
- package/esm/helper/createEventRateLimiter.js.map +1 -0
- package/esm/helper/deviceInfo.js +10 -62
- package/esm/helper/deviceInfo.js.map +1 -0
- package/esm/helper/display.js +2 -3
- package/esm/helper/display.js.map +1 -0
- package/esm/helper/enums.js +6 -1
- package/esm/helper/enums.js.map +1 -0
- package/esm/helper/errorTools.js +36 -28
- package/esm/helper/errorTools.js.map +1 -0
- package/esm/helper/eventEmitter.js +2 -5
- package/esm/helper/eventEmitter.js.map +1 -0
- package/esm/helper/getZoneJsOriginalValue.js +2 -4
- package/esm/helper/getZoneJsOriginalValue.js.map +1 -0
- package/esm/helper/instrumentMethod.js +11 -16
- package/esm/helper/instrumentMethod.js.map +1 -0
- package/esm/helper/lifeCycle.js +2 -5
- package/esm/helper/lifeCycle.js.map +1 -0
- package/esm/helper/limitModification.js +5 -20
- package/esm/helper/limitModification.js.map +1 -0
- package/esm/helper/mobileUtil.js +2 -16
- package/esm/helper/mobileUtil.js.map +1 -0
- package/esm/helper/monitor.js +39 -0
- package/esm/helper/monitor.js.map +1 -0
- package/esm/helper/observable.js +2 -7
- package/esm/helper/observable.js.map +1 -0
- package/esm/helper/readBytesFromStream.js +8 -15
- package/esm/helper/readBytesFromStream.js.map +1 -0
- package/esm/helper/sanitize.js +40 -57
- package/esm/helper/sanitize.js.map +1 -0
- package/esm/helper/serialisation/contextManager.js +5 -9
- package/esm/helper/serialisation/contextManager.js.map +1 -0
- package/esm/helper/serialisation/heavyCustomerDataWarning.js +5 -4
- package/esm/helper/serialisation/heavyCustomerDataWarning.js.map +1 -0
- package/esm/helper/serialisation/jsonStringify.js +7 -10
- package/esm/helper/serialisation/jsonStringify.js.map +1 -0
- package/esm/helper/serialisation/rowData.js +3 -4
- package/esm/helper/serialisation/rowData.js.map +1 -0
- package/esm/helper/timer.js +5 -3
- package/esm/helper/timer.js.map +1 -0
- package/esm/helper/tools.js +58 -273
- package/esm/helper/tools.js.map +1 -0
- package/esm/helper/urlPolyfill.js +5 -9
- package/esm/helper/urlPolyfill.js.map +1 -0
- package/esm/index.js +5 -1
- package/esm/index.js.map +1 -0
- package/esm/init.js +25 -31
- package/esm/init.js.map +1 -0
- package/esm/report/reportObservable.js +8 -19
- package/esm/report/reportObservable.js.map +1 -0
- package/esm/session/sessionConstants.js +2 -1
- package/esm/session/sessionConstants.js.map +1 -0
- package/esm/session/sessionCookieStore.js +11 -38
- package/esm/session/sessionCookieStore.js.map +1 -0
- package/esm/session/sessionManagement.js +2 -8
- package/esm/session/sessionManagement.js.map +1 -0
- package/esm/session/sessionStore.js +4 -22
- package/esm/session/sessionStore.js.map +1 -0
- package/esm/synthetics/syntheticsWorkerValues.js +2 -1
- package/esm/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/esm/synthetics/usr.js +2 -3
- package/esm/synthetics/usr.js.map +1 -0
- package/esm/telemetry/telemetry.js +111 -0
- package/esm/telemetry/telemetry.js.map +1 -0
- package/esm/telemetry/types.js +9 -0
- package/esm/telemetry/types.js.map +1 -0
- package/esm/tracekit/computeStackTrace.js +4 -31
- package/esm/tracekit/computeStackTrace.js.map +1 -0
- package/esm/tracekit/index.js +2 -1
- package/esm/tracekit/index.js.map +1 -0
- package/esm/tracekit/tracekit.js +5 -14
- package/esm/tracekit/tracekit.js.map +1 -0
- package/esm/transport/batch.js +9 -47
- package/esm/transport/batch.js.map +1 -0
- package/esm/transport/eventBridge.js +2 -5
- package/esm/transport/eventBridge.js.map +1 -0
- package/esm/transport/flushController.js +11 -20
- package/esm/transport/flushController.js.map +1 -0
- package/esm/transport/httpRequest.js +8 -18
- package/esm/transport/httpRequest.js.map +1 -0
- package/esm/transport/index.js +2 -1
- package/esm/transport/index.js.map +1 -0
- package/esm/transport/sendWithRetryStrategy.js +4 -17
- package/esm/transport/sendWithRetryStrategy.js.map +1 -0
- package/esm/transport/startBatchWithReplica.js +2 -3
- package/esm/transport/startBatchWithReplica.js.map +1 -0
- package/esm/user/index.js.map +1 -0
- package/esm/user/user.js +4 -5
- package/esm/user/user.js.map +1 -0
- package/esm/worker.js.map +1 -0
- package/package.json +2 -2
- package/src/browser/addEventListener.js +8 -7
- package/src/browser/fetchObservable.js +12 -3
- package/src/browser/scroll.js +25 -0
- package/src/configuration/configuration.js +16 -0
- package/src/configuration/transportConfiguration.js +2 -2
- package/src/console/consoleObservable.js +4 -2
- package/src/dataMap.js +17 -3
- package/src/error/trackRuntimeError.js +2 -2
- package/src/helper/contextHistory.js +3 -3
- package/src/helper/enums.js +4 -0
- package/src/helper/errorTools.js +55 -24
- package/src/helper/instrumentMethod.js +5 -2
- package/src/helper/monitor.js +44 -0
- package/src/helper/observable.js +10 -8
- package/src/helper/readBytesFromStream.js +5 -5
- package/src/helper/timer.js +3 -3
- package/src/helper/tools.js +2 -17
- package/src/index.js +4 -0
- package/src/init.js +19 -21
- package/src/report/reportObservable.js +6 -5
- package/src/telemetry/telemetry.js +164 -0
- package/src/telemetry/types.js +9 -0
- package/src/transport/batch.js +4 -4
- package/src/transport/httpRequest.js +5 -4
package/src/helper/enums.js
CHANGED
package/src/helper/errorTools.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { each, noop } from './tools'
|
|
2
2
|
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
3
3
|
import { computeStackTrace } from '../tracekit'
|
|
4
|
-
|
|
4
|
+
import { callMonitored } from '../helper/monitor'
|
|
5
|
+
export var NO_ERROR_STACK_PRESENT_MESSAGE =
|
|
6
|
+
'No stack, consider using an instance of Error'
|
|
5
7
|
export var ErrorSource = {
|
|
6
8
|
AGENT: 'agent',
|
|
7
9
|
CONSOLE: 'console',
|
|
@@ -19,34 +21,62 @@ export function computeRawError(data) {
|
|
|
19
21
|
var nonErrorPrefix = data.nonErrorPrefix
|
|
20
22
|
var source = data.source
|
|
21
23
|
var handling = data.handling
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
24
|
+
var isErrorInstance = originalError instanceof Error
|
|
25
|
+
var message = computeMessage(
|
|
26
|
+
stackTrace,
|
|
27
|
+
isErrorInstance,
|
|
28
|
+
nonErrorPrefix,
|
|
29
|
+
originalError
|
|
30
|
+
)
|
|
31
|
+
var stack = hasUsableStack(isErrorInstance, stackTrace)
|
|
32
|
+
? toStackTraceString(stackTrace)
|
|
33
|
+
: NO_ERROR_STACK_PRESENT_MESSAGE
|
|
34
|
+
var causes = isErrorInstance
|
|
35
|
+
? flattenErrorCauses(originalError, source)
|
|
36
|
+
: undefined
|
|
37
|
+
var type = stackTrace && stackTrace.name
|
|
37
38
|
|
|
38
39
|
return {
|
|
39
40
|
startClocks: startClocks,
|
|
40
41
|
source: source,
|
|
41
42
|
handling: handling,
|
|
42
43
|
originalError: originalError,
|
|
43
|
-
message:
|
|
44
|
-
stack:
|
|
44
|
+
message: message,
|
|
45
|
+
stack: stack,
|
|
45
46
|
handlingStack: handlingStack,
|
|
46
|
-
type:
|
|
47
|
-
causes:
|
|
47
|
+
type: type,
|
|
48
|
+
causes: causes
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
function computeMessage(
|
|
52
|
+
stackTrace,
|
|
53
|
+
isErrorInstance,
|
|
54
|
+
nonErrorPrefix,
|
|
55
|
+
originalError
|
|
56
|
+
) {
|
|
57
|
+
// Favor stackTrace message only if tracekit has really been able to extract something meaningful (message + name)
|
|
58
|
+
// TODO rework tracekit integration to avoid scattering error building logic
|
|
59
|
+
return stackTrace && stackTrace.message && stackTrace && stackTrace.name
|
|
60
|
+
? stackTrace.message
|
|
61
|
+
: !isErrorInstance
|
|
62
|
+
? nonErrorPrefix + ' ' + jsonStringify(sanitize(originalError))
|
|
63
|
+
: 'Empty message'
|
|
64
|
+
}
|
|
65
|
+
function hasUsableStack(isErrorInstance, stackTrace) {
|
|
66
|
+
if (stackTrace === undefined) {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
if (isErrorInstance) {
|
|
70
|
+
return true
|
|
71
|
+
}
|
|
72
|
+
// handle cases where tracekit return stack = [] or stack = [{url: undefined, line: undefined, column: undefined}]
|
|
73
|
+
// TODO rework tracekit integration to avoid generating those unusable stack
|
|
74
|
+
return (
|
|
75
|
+
stackTrace.stack.length > 0 &&
|
|
76
|
+
(stackTrace.stack.length > 1 || stackTrace.stack[0].url !== undefined)
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
50
80
|
export function formatUnknownError(
|
|
51
81
|
stackTrace,
|
|
52
82
|
errorObject,
|
|
@@ -97,10 +127,11 @@ export function createHandlingStack() {
|
|
|
97
127
|
noop()
|
|
98
128
|
}
|
|
99
129
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
callMonitored(function () {
|
|
131
|
+
var stackTrace = computeStackTrace(error)
|
|
132
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip)
|
|
133
|
+
formattedStack = toStackTraceString(stackTrace)
|
|
134
|
+
})
|
|
104
135
|
|
|
105
136
|
return formattedStack
|
|
106
137
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { noop } from './tools'
|
|
2
2
|
import { setTimeout } from './timer'
|
|
3
|
+
import { callMonitored } from './monitor'
|
|
3
4
|
export function instrumentMethod(object, method, instrumentationFactory) {
|
|
4
5
|
var original = object[method]
|
|
5
6
|
|
|
@@ -29,14 +30,16 @@ export function instrumentMethodAndCallOriginal(object, method, aliasOption) {
|
|
|
29
30
|
return function () {
|
|
30
31
|
var result
|
|
31
32
|
if (aliasOption && aliasOption.before) {
|
|
32
|
-
aliasOption.before
|
|
33
|
+
callMonitored(aliasOption.before, this, arguments)
|
|
34
|
+
// aliasOption.before.apply(this, arguments)
|
|
33
35
|
}
|
|
34
36
|
if (typeof original === 'function') {
|
|
35
37
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
36
38
|
result = original.apply(this, arguments)
|
|
37
39
|
}
|
|
38
40
|
if (aliasOption && aliasOption.after) {
|
|
39
|
-
aliasOption.after
|
|
41
|
+
callMonitored(aliasOption.after, this, arguments)
|
|
42
|
+
// aliasOption.after.apply(this, arguments)
|
|
40
43
|
}
|
|
41
44
|
return result
|
|
42
45
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ConsoleApiName, display } from './display'
|
|
2
|
+
var onMonitorErrorCollected
|
|
3
|
+
var debugMode = false
|
|
4
|
+
|
|
5
|
+
export function startMonitorErrorCollection(newOnMonitorErrorCollected) {
|
|
6
|
+
onMonitorErrorCollected = newOnMonitorErrorCollected
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function setDebugMode(newDebugMode) {
|
|
10
|
+
debugMode = newDebugMode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resetMonitor() {
|
|
14
|
+
onMonitorErrorCollected = undefined
|
|
15
|
+
debugMode = false
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function monitor(fn) {
|
|
19
|
+
return function () {
|
|
20
|
+
return callMonitored(fn, this, arguments)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function callMonitored(fn, context, args) {
|
|
25
|
+
try {
|
|
26
|
+
return fn.apply(context, args)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
displayIfDebugEnabled(ConsoleApiName.error, e)
|
|
29
|
+
if (onMonitorErrorCollected) {
|
|
30
|
+
try {
|
|
31
|
+
onMonitorErrorCollected(e)
|
|
32
|
+
} catch (e) {
|
|
33
|
+
displayIfDebugEnabled(ConsoleApiName.error, e)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function displayIfDebugEnabled(api) {
|
|
40
|
+
var args = [].slice.call(arguments, 1)
|
|
41
|
+
if (debugMode) {
|
|
42
|
+
display.apply(null, [api, '[MONITOR]'].concat(args))
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/helper/observable.js
CHANGED
|
@@ -12,14 +12,14 @@ _Observable.prototype = {
|
|
|
12
12
|
this.observers.push(f)
|
|
13
13
|
var _this = this
|
|
14
14
|
return {
|
|
15
|
-
unsubscribe: function() {
|
|
16
|
-
_this.observers = filter(_this.observers, function(other) {
|
|
15
|
+
unsubscribe: function () {
|
|
16
|
+
_this.observers = filter(_this.observers, function (other) {
|
|
17
17
|
return f !== other
|
|
18
18
|
})
|
|
19
19
|
if (!_this.observers.length && _this.onLastUnsubscribe) {
|
|
20
20
|
_this.onLastUnsubscribe()
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
notify: function (data) {
|
|
@@ -32,12 +32,14 @@ export var Observable = _Observable
|
|
|
32
32
|
|
|
33
33
|
export function mergeObservables() {
|
|
34
34
|
var observables = [].slice.call(arguments)
|
|
35
|
-
var globalObservable = new Observable(function(){
|
|
36
|
-
var subscriptions = map(observables, function(observable) {
|
|
37
|
-
|
|
35
|
+
var globalObservable = new Observable(function () {
|
|
36
|
+
var subscriptions = map(observables, function (observable) {
|
|
37
|
+
return observable.subscribe(function (data) {
|
|
38
|
+
return globalObservable.notify(data)
|
|
39
|
+
})
|
|
38
40
|
})
|
|
39
|
-
return function() {
|
|
40
|
-
return each(subscriptions, function(subscription) {
|
|
41
|
+
return function () {
|
|
42
|
+
return each(subscriptions, function (subscription) {
|
|
41
43
|
return subscription.unsubscribe()
|
|
42
44
|
})
|
|
43
45
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { noop, each } from './tools'
|
|
2
|
-
|
|
2
|
+
import { monitor } from './monitor'
|
|
3
3
|
/**
|
|
4
4
|
* Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of
|
|
5
5
|
* the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
|
|
@@ -14,7 +14,7 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
14
14
|
|
|
15
15
|
function readMore() {
|
|
16
16
|
reader.read().then(
|
|
17
|
-
function (result) {
|
|
17
|
+
monitor(function (result) {
|
|
18
18
|
if (result.done) {
|
|
19
19
|
onDone()
|
|
20
20
|
return
|
|
@@ -30,10 +30,10 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
30
30
|
} else {
|
|
31
31
|
readMore()
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
function (error) {
|
|
33
|
+
}),
|
|
34
|
+
monitor(function (error) {
|
|
35
35
|
callback(error)
|
|
36
|
-
}
|
|
36
|
+
})
|
|
37
37
|
)
|
|
38
38
|
}
|
|
39
39
|
|
package/src/helper/timer.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getZoneJsOriginalValue } from './getZoneJsOriginalValue'
|
|
2
2
|
import { getGlobalObject } from '../init'
|
|
3
|
-
|
|
3
|
+
import { monitor } from './monitor'
|
|
4
4
|
export function setTimeout(callback, delay) {
|
|
5
5
|
return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(
|
|
6
|
-
callback,
|
|
6
|
+
monitor(callback),
|
|
7
7
|
delay
|
|
8
8
|
)
|
|
9
9
|
}
|
|
@@ -13,7 +13,7 @@ export function clearTimeout(timeoutId) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function setInterval(callback, delay) {
|
|
16
|
-
return getZoneJsOriginalValue(window, 'setInterval')(callback, delay)
|
|
16
|
+
return getZoneJsOriginalValue(window, 'setInterval')(monitor(callback), delay)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function clearInterval(timeoutId) {
|
package/src/helper/tools.js
CHANGED
|
@@ -232,6 +232,7 @@ export var matchList = function (list, value, useStartsWith) {
|
|
|
232
232
|
}
|
|
233
233
|
// https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
|
|
234
234
|
export var cssEscape = function (str) {
|
|
235
|
+
str = str + ''
|
|
235
236
|
if (window.CSS && window.CSS.escape) {
|
|
236
237
|
return window.CSS.escape(str)
|
|
237
238
|
}
|
|
@@ -1649,23 +1650,6 @@ export function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
|
1649
1650
|
}
|
|
1650
1651
|
}
|
|
1651
1652
|
|
|
1652
|
-
export function requestIdleCallback(callback, opts) {
|
|
1653
|
-
// Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
|
|
1654
|
-
// browser is busy rendering frames (ex: when frames are below 60fps). When not available, the
|
|
1655
|
-
// fallback on 'requestAnimationFrame' will still ensure the mutations are processed after any
|
|
1656
|
-
// browser rendering process (Layout, Recalculate Style, etc.), so we can serialize DOM nodes
|
|
1657
|
-
// efficiently.
|
|
1658
|
-
if (window.requestIdleCallback) {
|
|
1659
|
-
var id = window.requestIdleCallback(callback, opts)
|
|
1660
|
-
return function () {
|
|
1661
|
-
return window.cancelIdleCallback(id)
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
var id = window.requestAnimationFrame(callback)
|
|
1665
|
-
return function () {
|
|
1666
|
-
return window.cancelAnimationFrame(id)
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
1653
|
export function objectHasValue(object, value) {
|
|
1670
1654
|
return some(keys(object), function (key) {
|
|
1671
1655
|
return object[key] === value
|
|
@@ -1689,6 +1673,7 @@ export function tryToClone(response) {
|
|
|
1689
1673
|
}
|
|
1690
1674
|
export function isHashAnAnchor(hash) {
|
|
1691
1675
|
var correspondingId = hash.substr(1)
|
|
1676
|
+
if (!correspondingId) return false
|
|
1692
1677
|
return !!document.getElementById(correspondingId)
|
|
1693
1678
|
}
|
|
1694
1679
|
export function getPathFromHash(hash) {
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './error/trackRuntimeError'
|
|
|
9
9
|
export * from './console/consoleObservable'
|
|
10
10
|
export * from './report/reportObservable'
|
|
11
11
|
export * from './helper/display'
|
|
12
|
+
export * from './helper/monitor'
|
|
12
13
|
export * from './helper/sanitize'
|
|
13
14
|
export * from './helper/eventEmitter'
|
|
14
15
|
export * from './helper/lifeCycle'
|
|
@@ -31,6 +32,7 @@ export * from './browser/pageExitObservable'
|
|
|
31
32
|
export * from './browser/htmlDomUtils'
|
|
32
33
|
export * from './browser/addEventListener'
|
|
33
34
|
export * from './browser/runOnReadyState'
|
|
35
|
+
export * from './browser/scroll'
|
|
34
36
|
|
|
35
37
|
export * from './dataMap'
|
|
36
38
|
export * from './init'
|
|
@@ -46,3 +48,5 @@ export * from './helper/serialisation/heavyCustomerDataWarning'
|
|
|
46
48
|
export * from './helper/serialisation/jsonStringify'
|
|
47
49
|
export * from './helper/serialisation/rowData'
|
|
48
50
|
export * from './user'
|
|
51
|
+
|
|
52
|
+
export * from './telemetry/telemetry'
|
package/src/init.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
callback()
|
|
6
|
-
}
|
|
7
|
-
})
|
|
8
|
-
return global
|
|
9
|
-
}
|
|
1
|
+
import { each, assign } from './helper/tools'
|
|
2
|
+
import { setDebugMode } from './helper/monitor'
|
|
3
|
+
import { catchUserErrors } from './helper/catchUserErrors'
|
|
4
|
+
|
|
10
5
|
export function makePublicApi(stub) {
|
|
11
|
-
var publicApi =
|
|
12
|
-
|
|
13
|
-
callback
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
var publicApi = assign(
|
|
7
|
+
{
|
|
8
|
+
onReady: function (callback) {
|
|
9
|
+
callback()
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
stub
|
|
13
|
+
)
|
|
16
14
|
|
|
17
15
|
// Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
18
16
|
// as much as possible but of course it's not a real protection.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
Object.defineProperty(publicApi, '_setDebug', {
|
|
18
|
+
get: function () {
|
|
19
|
+
return setDebugMode
|
|
20
|
+
},
|
|
21
|
+
enumerable: false
|
|
22
|
+
})
|
|
25
23
|
|
|
26
24
|
return publicApi
|
|
27
25
|
}
|
|
@@ -30,7 +28,7 @@ export function defineGlobal(global, name, api) {
|
|
|
30
28
|
global[name] = api
|
|
31
29
|
if (existingGlobalVariable && existingGlobalVariable.q) {
|
|
32
30
|
each(existingGlobalVariable.q, function (fn) {
|
|
33
|
-
fn()
|
|
31
|
+
catchUserErrors(fn, 'onReady callback threw an error:')()
|
|
34
32
|
})
|
|
35
33
|
}
|
|
36
34
|
}
|
|
@@ -3,16 +3,17 @@ import { mergeObservables, Observable } from '../helper/observable'
|
|
|
3
3
|
import { includes, safeTruncate, filter, each } from '../helper/tools'
|
|
4
4
|
import { addEventListener } from '../browser/addEventListener'
|
|
5
5
|
import { DOM_EVENT } from '../helper/enums'
|
|
6
|
+
import { monitor } from '../helper/monitor'
|
|
6
7
|
export var RawReportType = {
|
|
7
8
|
intervention: 'intervention',
|
|
8
9
|
deprecation: 'deprecation',
|
|
9
10
|
cspViolation: 'csp_violation'
|
|
10
11
|
}
|
|
11
|
-
export function initReportObservable(apis) {
|
|
12
|
+
export function initReportObservable(configuration, apis) {
|
|
12
13
|
var observables = []
|
|
13
14
|
|
|
14
15
|
if (includes(apis, RawReportType.cspViolation)) {
|
|
15
|
-
observables.push(createCspViolationReportObservable())
|
|
16
|
+
observables.push(createCspViolationReportObservable(configuration))
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
var reportTypes = filter(apis, function (api) {
|
|
@@ -30,11 +31,11 @@ function createReportObservable(reportTypes) {
|
|
|
30
31
|
return
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
var handleReports = function (reports) {
|
|
34
|
+
var handleReports = monitor(function (reports) {
|
|
34
35
|
each(reports, function (report) {
|
|
35
36
|
observable.notify(buildRawReportFromReport(report))
|
|
36
37
|
})
|
|
37
|
-
}
|
|
38
|
+
})
|
|
38
39
|
|
|
39
40
|
var observer = new window.ReportingObserver(handleReports, {
|
|
40
41
|
types: reportTypes,
|
|
@@ -50,7 +51,7 @@ function createReportObservable(reportTypes) {
|
|
|
50
51
|
return observable
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
function createCspViolationReportObservable() {
|
|
54
|
+
function createCspViolationReportObservable(configuration) {
|
|
54
55
|
var observable = new Observable(function () {
|
|
55
56
|
var handleCspViolation = function (event) {
|
|
56
57
|
observable.notify(buildRawReportFromCspViolation(event))
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ConsoleApiName } from '../helper/display'
|
|
2
|
+
import {
|
|
3
|
+
toStackTraceString,
|
|
4
|
+
NO_ERROR_STACK_PRESENT_MESSAGE
|
|
5
|
+
} from '../helper/errorTools'
|
|
6
|
+
import { computeStackTrace } from '../tracekit'
|
|
7
|
+
import { Observable } from '../helper/observable'
|
|
8
|
+
import {
|
|
9
|
+
displayIfDebugEnabled,
|
|
10
|
+
startMonitorErrorCollection
|
|
11
|
+
} from '..//helper/monitor'
|
|
12
|
+
import {
|
|
13
|
+
startsWith,
|
|
14
|
+
assign,
|
|
15
|
+
performDraw,
|
|
16
|
+
timeStampNow,
|
|
17
|
+
extend2Lev
|
|
18
|
+
} from '../helper/tools'
|
|
19
|
+
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
20
|
+
import { NonErrorPrefix } from '../helper/enums'
|
|
21
|
+
import { TelemetryStatusType, TelemetryType } from './types'
|
|
22
|
+
|
|
23
|
+
const ALLOWED_FRAME_URLS = [
|
|
24
|
+
'https://static.guance.com',
|
|
25
|
+
'http://localhost',
|
|
26
|
+
'<anonymous>'
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
export var TelemetryService = {
|
|
30
|
+
LOGS: 'browser-logs-sdk',
|
|
31
|
+
RUM: 'browser-rum-sdk'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var telemetryConfiguration = {
|
|
35
|
+
maxEventsPerPage: 0,
|
|
36
|
+
sentEventCount: 0,
|
|
37
|
+
telemetryEnabled: false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var onRawTelemetryEventCollected
|
|
41
|
+
|
|
42
|
+
export function startTelemetry(telemetryService, configuration) {
|
|
43
|
+
let contextProvider
|
|
44
|
+
var observable = new Observable()
|
|
45
|
+
telemetryConfiguration.telemetryEnabled =
|
|
46
|
+
configuration.telemetryEnabled &&
|
|
47
|
+
performDraw(configuration.telemetrySampleRate)
|
|
48
|
+
|
|
49
|
+
onRawTelemetryEventCollected = function (rawEvent) {
|
|
50
|
+
if (telemetryConfiguration.telemetryEnabled) {
|
|
51
|
+
var event = toTelemetryEvent(telemetryService, rawEvent)
|
|
52
|
+
observable.notify(event)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
startMonitorErrorCollection(addTelemetryError)
|
|
56
|
+
|
|
57
|
+
assign(telemetryConfiguration, {
|
|
58
|
+
maxEventsPerPage: configuration.maxTelemetryEventsPerPage,
|
|
59
|
+
sentEventCount: 0
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function toTelemetryEvent(telemetryService, event) {
|
|
63
|
+
return extend2Lev(
|
|
64
|
+
{
|
|
65
|
+
type: 'telemetry',
|
|
66
|
+
date: timeStampNow(),
|
|
67
|
+
service: telemetryService,
|
|
68
|
+
version: __BUILD_ENV__SDK_VERSION__,
|
|
69
|
+
source: 'browser',
|
|
70
|
+
telemetry: event // https://github.com/microsoft/TypeScript/issues/48457
|
|
71
|
+
},
|
|
72
|
+
contextProvider !== undefined ? contextProvider() : {}
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
setContextProvider: function (provider) {
|
|
78
|
+
contextProvider = provider
|
|
79
|
+
},
|
|
80
|
+
observable: observable,
|
|
81
|
+
enabled: telemetryConfiguration.telemetryEnabled
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resetTelemetry() {
|
|
86
|
+
onRawTelemetryEventCollected = undefined
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function addTelemetryDebug(message, context) {
|
|
90
|
+
displayIfDebugEnabled(ConsoleApiName.debug, message, context)
|
|
91
|
+
addTelemetry(
|
|
92
|
+
assign(
|
|
93
|
+
{
|
|
94
|
+
type: TelemetryType.log,
|
|
95
|
+
message: message,
|
|
96
|
+
status: TelemetryStatusType.debug
|
|
97
|
+
},
|
|
98
|
+
context
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function addTelemetryError(e, context) {
|
|
104
|
+
addTelemetry(
|
|
105
|
+
assign(
|
|
106
|
+
{
|
|
107
|
+
type: TelemetryType.log,
|
|
108
|
+
status: TelemetryStatusType.error
|
|
109
|
+
},
|
|
110
|
+
formatError(e),
|
|
111
|
+
context
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function addTelemetryConfiguration(configuration) {
|
|
117
|
+
if (telemetryConfiguration.telemetryEnabled) {
|
|
118
|
+
addTelemetry({
|
|
119
|
+
type: TelemetryType.configuration,
|
|
120
|
+
configuration: configuration
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function addTelemetry(event) {
|
|
126
|
+
if (
|
|
127
|
+
onRawTelemetryEventCollected &&
|
|
128
|
+
telemetryConfiguration.sentEventCount <
|
|
129
|
+
telemetryConfiguration.maxEventsPerPage
|
|
130
|
+
) {
|
|
131
|
+
telemetryConfiguration.sentEventCount += 1
|
|
132
|
+
onRawTelemetryEventCollected(event)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function formatError(e) {
|
|
137
|
+
if (e instanceof Error) {
|
|
138
|
+
var stackTrace = computeStackTrace(e)
|
|
139
|
+
return {
|
|
140
|
+
error: {
|
|
141
|
+
kind: stackTrace.name,
|
|
142
|
+
stack: toStackTraceString(scrubCustomerFrames(stackTrace))
|
|
143
|
+
},
|
|
144
|
+
message: stackTrace.message
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
error: {
|
|
149
|
+
stack: NO_ERROR_STACK_PRESENT_MESSAGE
|
|
150
|
+
},
|
|
151
|
+
message: NonErrorPrefix.UNCAUGHT + ' ' + jsonStringify(e)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function scrubCustomerFrames(stackTrace) {
|
|
156
|
+
stackTrace.stack = stackTrace.stack.filter(
|
|
157
|
+
(frame) =>
|
|
158
|
+
!frame.url ||
|
|
159
|
+
ALLOWED_FRAME_URLS.some(function (allowedFrameUrl) {
|
|
160
|
+
return startsWith(frame.url, allowedFrameUrl)
|
|
161
|
+
})
|
|
162
|
+
)
|
|
163
|
+
return stackTrace
|
|
164
|
+
}
|
package/src/transport/batch.js
CHANGED
|
@@ -76,13 +76,13 @@ export var processedMessageByDataMap = function (message) {
|
|
|
76
76
|
}
|
|
77
77
|
})
|
|
78
78
|
if (
|
|
79
|
-
message.
|
|
80
|
-
isObject(message.
|
|
81
|
-
!isEmptyObject(message.
|
|
79
|
+
message.context &&
|
|
80
|
+
isObject(message.context) &&
|
|
81
|
+
!isEmptyObject(message.context)
|
|
82
82
|
) {
|
|
83
83
|
// 自定义tag, 存储成field
|
|
84
84
|
var _tagKeys = []
|
|
85
|
-
each(message.
|
|
85
|
+
each(message.context, function (_value, _key) {
|
|
86
86
|
// 如果和之前tag重名,则舍弃
|
|
87
87
|
if (filterFileds.indexOf(_key) > -1) return
|
|
88
88
|
filterFileds.push(_key)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'
|
|
2
2
|
import { addEventListener } from '../browser/addEventListener'
|
|
3
|
+
import { monitor } from '../helper/monitor'
|
|
3
4
|
/**
|
|
4
5
|
* Use POST request without content type to:
|
|
5
6
|
* - avoid CORS preflight requests
|
|
@@ -74,15 +75,15 @@ export function fetchKeepAliveStrategy(
|
|
|
74
75
|
keepalive: true,
|
|
75
76
|
mode: 'cors'
|
|
76
77
|
}).then(
|
|
77
|
-
function (response) {
|
|
78
|
+
monitor(function (response) {
|
|
78
79
|
if (typeof onResponse === 'function') {
|
|
79
80
|
onResponse({ status: response.status, type: response.type })
|
|
80
81
|
}
|
|
81
|
-
},
|
|
82
|
-
function () {
|
|
82
|
+
}),
|
|
83
|
+
monitor(function () {
|
|
83
84
|
// failed to queue the request
|
|
84
85
|
sendXHR(url, data, onResponse)
|
|
85
|
-
}
|
|
86
|
+
})
|
|
86
87
|
)
|
|
87
88
|
} else {
|
|
88
89
|
sendXHR(url, data, onResponse)
|