@cloudcare/browser-rum 2.1.6 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +57 -48
- package/cjs/boot/rumPublicApi.js +169 -134
- package/cjs/domain/assembly.js +58 -44
- package/cjs/domain/configuration.js +75 -0
- package/cjs/domain/contexts/internalContext.js +45 -0
- package/cjs/domain/contexts/urlContexts.js +68 -0
- package/cjs/domain/contexts/viewContexts.js +43 -0
- package/cjs/domain/domMutationCollection.js +44 -31
- package/cjs/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +25 -25
- package/cjs/domain/performanceCollection.js +55 -24
- package/cjs/domain/requestCollection.js +117 -0
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +22 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +82 -0
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +78 -0
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +163 -0
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +74 -0
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +263 -0
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +33 -53
- package/cjs/domain/rumEventsCollection/error/trackConsoleError.js +26 -0
- package/cjs/domain/rumEventsCollection/error/trackReportError.js +26 -0
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +46 -17
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +49 -9
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +7 -5
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +61 -24
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +91 -51
- package/cjs/domain/rumEventsCollection/view/trackViews.js +119 -86
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +41 -31
- package/cjs/domain/rumSessionManager.js +95 -0
- package/cjs/domain/tracing/tracer.js +8 -9
- package/cjs/domain/trackEventCounts.js +9 -6
- package/cjs/domain/usr/index.js +30 -0
- package/cjs/domain/waitPageActivityEnd.js +163 -0
- package/cjs/transport/startRumBatch.js +38 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.js +55 -48
- package/esm/boot/rumPublicApi.js +167 -135
- package/esm/domain/assembly.js +58 -44
- package/esm/domain/configuration.js +60 -0
- package/esm/domain/contexts/internalContext.js +38 -0
- package/esm/domain/contexts/urlContexts.js +58 -0
- package/esm/domain/contexts/viewContexts.js +32 -0
- package/esm/domain/domMutationCollection.js +43 -33
- package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +26 -24
- package/esm/domain/performanceCollection.js +56 -26
- package/esm/domain/requestCollection.js +102 -0
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +23 -5
- package/esm/domain/rumEventsCollection/actions/clickChain.js +69 -0
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +64 -0
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +139 -0
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +66 -0
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +244 -0
- package/esm/domain/rumEventsCollection/error/errorCollection.js +32 -54
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js +18 -0
- package/esm/domain/rumEventsCollection/error/trackReportError.js +18 -0
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +30 -18
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +31 -9
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +8 -6
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +43 -26
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +75 -51
- package/esm/domain/rumEventsCollection/view/trackViews.js +120 -85
- package/esm/domain/rumEventsCollection/view/viewCollection.js +42 -32
- package/esm/domain/rumSessionManager.js +80 -0
- package/esm/domain/tracing/skywalkingTracer.js +1 -1
- package/esm/domain/tracing/tracer.js +7 -8
- package/esm/domain/trackEventCounts.js +9 -6
- package/esm/domain/usr/index.js +17 -0
- package/esm/domain/waitPageActivityEnd.js +147 -0
- package/esm/transport/startRumBatch.js +30 -0
- package/package.json +3 -3
- package/src/boot/rum.js +79 -59
- package/src/boot/rumPublicApi.js +165 -171
- package/src/domain/assembly.js +77 -54
- package/src/domain/configuration.js +92 -0
- package/src/domain/contexts/internalContext.js +39 -0
- package/src/domain/contexts/urlContexts.js +76 -0
- package/src/domain/contexts/viewContexts.js +37 -0
- package/src/domain/domMutationCollection.js +48 -32
- package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +28 -28
- package/src/domain/performanceCollection.js +62 -45
- package/src/domain/requestCollection.js +103 -0
- package/src/domain/rumEventsCollection/actions/actionCollection.js +34 -11
- package/src/domain/rumEventsCollection/actions/clickChain.js +90 -0
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +84 -0
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +73 -62
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +157 -0
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +85 -0
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +326 -0
- package/src/domain/rumEventsCollection/error/errorCollection.js +53 -69
- package/src/domain/rumEventsCollection/error/trackConsoleError.js +21 -0
- package/src/domain/rumEventsCollection/error/trackReportError.js +22 -0
- package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +29 -18
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +39 -23
- package/src/domain/rumEventsCollection/view/trackFirstHidden.js +9 -6
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +63 -42
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +80 -61
- package/src/domain/rumEventsCollection/view/trackViews.js +171 -134
- package/src/domain/rumEventsCollection/view/viewCollection.js +69 -49
- package/src/domain/rumSessionManager.js +90 -0
- package/src/domain/tracing/jaegerTracer.js +5 -5
- package/src/domain/tracing/skywalkingTracer.js +3 -3
- package/src/domain/tracing/tracer.js +50 -38
- package/src/domain/tracing/w3cTraceParentTracer.js +5 -5
- package/src/domain/tracing/zipkinMultiTracer.js +5 -5
- package/src/domain/tracing/zipkinSingleTracer.js +5 -5
- package/src/domain/trackEventCounts.js +10 -6
- package/src/domain/usr/index.js +16 -0
- package/src/domain/waitPageActivityEnd.js +192 -0
- package/src/transport/startRumBatch.js +48 -0
- package/cjs/domain/internalContext.js +0 -34
- package/cjs/domain/parentContexts.js +0 -143
- package/cjs/domain/requestCollections.js +0 -131
- package/cjs/domain/rumEventsCollection/actions/trackActions.js +0 -114
- package/cjs/domain/rumSession.js +0 -82
- package/cjs/domain/trackPageActivities.js +0 -166
- package/cjs/transport/batch.js +0 -81
- package/esm/domain/internalContext.js +0 -27
- package/esm/domain/parentContexts.js +0 -130
- package/esm/domain/requestCollections.js +0 -118
- package/esm/domain/rumEventsCollection/actions/trackActions.js +0 -103
- package/esm/domain/rumSession.js +0 -70
- package/esm/domain/trackPageActivities.js +0 -149
- package/esm/transport/batch.js +0 -74
- package/src/domain/internalContext.js +0 -28
- package/src/domain/parentContexts.js +0 -171
- package/src/domain/requestCollections.js +0 -118
- package/src/domain/rumEventsCollection/actions/trackActions.js +0 -113
- package/src/domain/rumSession.js +0 -92
- package/src/domain/trackPageActivities.js +0 -170
- package/src/transport/batch.js +0 -85
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {base64Encode, urlParse} from '@cloudcare/browser-core'
|
|
2
2
|
// start SkyWalking
|
|
3
3
|
function uuid() {
|
|
4
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c)
|
|
4
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c){
|
|
5
5
|
/* tslint:disable */
|
|
6
|
-
|
|
6
|
+
var r = (Math.random() * 16) | 0;
|
|
7
7
|
/* tslint:disable */
|
|
8
|
-
|
|
8
|
+
var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
9
9
|
|
|
10
10
|
return v.toString(16);
|
|
11
11
|
});
|
|
@@ -6,41 +6,42 @@ import {
|
|
|
6
6
|
TraceType,
|
|
7
7
|
getOrigin
|
|
8
8
|
} from '@cloudcare/browser-core'
|
|
9
|
-
import { DDtraceTracer} from './ddtraceTracer'
|
|
10
|
-
import { SkyWalkingTracer} from './skywalkingTracer'
|
|
11
|
-
import { JaegerTracer} from './jaegerTracer'
|
|
12
|
-
import { ZipkinSingleTracer} from './zipkinSingleTracer'
|
|
13
|
-
import { ZipkinMultiTracer} from './zipkinMultiTracer'
|
|
14
|
-
import { W3cTraceParentTracer} from './w3cTraceParentTracer'
|
|
9
|
+
import { DDtraceTracer } from './ddtraceTracer'
|
|
10
|
+
import { SkyWalkingTracer } from './skywalkingTracer'
|
|
11
|
+
import { JaegerTracer } from './jaegerTracer'
|
|
12
|
+
import { ZipkinSingleTracer } from './zipkinSingleTracer'
|
|
13
|
+
import { ZipkinMultiTracer } from './zipkinMultiTracer'
|
|
14
|
+
import { W3cTraceParentTracer } from './w3cTraceParentTracer'
|
|
15
15
|
|
|
16
|
-
export function
|
|
16
|
+
export function clearTracingIfNeeded(context) {
|
|
17
17
|
if (context.status === 0 && !context.isAborted) {
|
|
18
18
|
context.traceId = undefined
|
|
19
19
|
context.spanId = undefined
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function startTracer(configuration) {
|
|
23
|
+
export function startTracer(configuration, sessionManager) {
|
|
24
24
|
return {
|
|
25
|
-
|
|
25
|
+
clearTracingIfNeeded: clearTracingIfNeeded,
|
|
26
26
|
traceFetch: function (context) {
|
|
27
27
|
return injectHeadersIfTracingAllowed(
|
|
28
28
|
configuration,
|
|
29
29
|
context,
|
|
30
|
+
sessionManager,
|
|
30
31
|
function (tracingHeaders) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (
|
|
33
|
+
context.input instanceof Request &&
|
|
34
|
+
(!context.init || !context.init.headers)
|
|
35
|
+
) {
|
|
34
36
|
context.input = new Request(context.input)
|
|
35
|
-
each(tracingHeaders, function(value,key) {
|
|
37
|
+
each(tracingHeaders, function (value, key) {
|
|
36
38
|
context.input.headers.append(key, value)
|
|
37
39
|
})
|
|
38
|
-
|
|
39
40
|
} else {
|
|
40
41
|
context.init = shallowClone(context.init)
|
|
41
42
|
var headers = []
|
|
42
43
|
if (context.init.headers instanceof Headers) {
|
|
43
|
-
context.init.headers.forEach(function(value, key) {
|
|
44
|
+
context.init.headers.forEach(function (value, key) {
|
|
44
45
|
headers.push([key, value])
|
|
45
46
|
})
|
|
46
47
|
} else if (isArray(context.init.headers)) {
|
|
@@ -55,13 +56,14 @@ export function startTracer(configuration) {
|
|
|
55
56
|
// context.init.headers = headers.concat(objectEntries(tracingHeaders))
|
|
56
57
|
// 转换成对象,兼容部分
|
|
57
58
|
var headersMap = {}
|
|
58
|
-
each(
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
each(
|
|
60
|
+
headers.concat(objectEntries(tracingHeaders)),
|
|
61
|
+
function (header) {
|
|
62
|
+
headersMap[header[0]] = header[1]
|
|
63
|
+
}
|
|
64
|
+
)
|
|
61
65
|
context.init.headers = headersMap
|
|
62
|
-
|
|
63
66
|
}
|
|
64
|
-
|
|
65
67
|
}
|
|
66
68
|
)
|
|
67
69
|
},
|
|
@@ -69,6 +71,7 @@ export function startTracer(configuration) {
|
|
|
69
71
|
return injectHeadersIfTracingAllowed(
|
|
70
72
|
configuration,
|
|
71
73
|
context,
|
|
74
|
+
sessionManager,
|
|
72
75
|
function (tracingHeaders) {
|
|
73
76
|
each(tracingHeaders, function (value, name) {
|
|
74
77
|
xhr.setRequestHeader(name, value)
|
|
@@ -93,32 +96,41 @@ function isAllowedUrl(configuration, requestUrl) {
|
|
|
93
96
|
return flag
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
export function injectHeadersIfTracingAllowed(
|
|
97
|
-
|
|
99
|
+
export function injectHeadersIfTracingAllowed(
|
|
100
|
+
configuration,
|
|
101
|
+
context,
|
|
102
|
+
sessionManager,
|
|
103
|
+
inject
|
|
104
|
+
) {
|
|
105
|
+
if (
|
|
106
|
+
!isAllowedUrl(configuration, context.url) ||
|
|
107
|
+
!configuration.traceType ||
|
|
108
|
+
!sessionManager.findTrackedSession()
|
|
109
|
+
) {
|
|
98
110
|
return
|
|
99
111
|
}
|
|
100
|
-
var tracer
|
|
101
|
-
switch(configuration.traceType) {
|
|
102
|
-
case TraceType.DDTRACE:
|
|
103
|
-
tracer = new DDtraceTracer()
|
|
104
|
-
break
|
|
112
|
+
var tracer
|
|
113
|
+
switch (configuration.traceType) {
|
|
114
|
+
case TraceType.DDTRACE:
|
|
115
|
+
tracer = new DDtraceTracer()
|
|
116
|
+
break
|
|
105
117
|
case TraceType.SKYWALKING_V3:
|
|
106
|
-
tracer = new SkyWalkingTracer(configuration, context.url)
|
|
107
|
-
break
|
|
118
|
+
tracer = new SkyWalkingTracer(configuration, context.url)
|
|
119
|
+
break
|
|
108
120
|
case TraceType.ZIPKIN_MULTI_HEADER:
|
|
109
|
-
tracer = new ZipkinMultiTracer(configuration)
|
|
110
|
-
break
|
|
121
|
+
tracer = new ZipkinMultiTracer(configuration)
|
|
122
|
+
break
|
|
111
123
|
case TraceType.JAEGER:
|
|
112
|
-
tracer = new JaegerTracer(configuration)
|
|
113
|
-
break
|
|
124
|
+
tracer = new JaegerTracer(configuration)
|
|
125
|
+
break
|
|
114
126
|
case TraceType.W3C_TRACEPARENT:
|
|
115
|
-
tracer = new W3cTraceParentTracer(configuration)
|
|
116
|
-
break
|
|
127
|
+
tracer = new W3cTraceParentTracer(configuration)
|
|
128
|
+
break
|
|
117
129
|
case TraceType.ZIPKIN_SINGLE_HEADER:
|
|
118
|
-
tracer = new ZipkinSingleTracer(configuration)
|
|
119
|
-
break
|
|
130
|
+
tracer = new ZipkinSingleTracer(configuration)
|
|
131
|
+
break
|
|
120
132
|
default:
|
|
121
|
-
break
|
|
133
|
+
break
|
|
122
134
|
}
|
|
123
135
|
if (!tracer || !tracer.isTracingSupported()) {
|
|
124
136
|
return
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// === Generate a random 64-bit number in fixed-length hex format
|
|
2
2
|
function randomTraceId() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (
|
|
6
|
-
|
|
3
|
+
var digits = '0123456789abcdef';
|
|
4
|
+
var n = '';
|
|
5
|
+
for (var i = 0; i < 16; i += 1) {
|
|
6
|
+
var rand = Math.floor(Math.random() * 16);
|
|
7
7
|
n += digits[rand];
|
|
8
8
|
}
|
|
9
9
|
return n;
|
|
@@ -14,7 +14,7 @@ function randomTraceId() {
|
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function W3cTraceParentTracer(configuration) {
|
|
17
|
-
|
|
17
|
+
var rootSpanId = randomTraceId();
|
|
18
18
|
this._traceId = randomTraceId() + rootSpanId
|
|
19
19
|
this._spanId = rootSpanId
|
|
20
20
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// === Generate a random 64-bit number in fixed-length hex format
|
|
2
2
|
function randomTraceId() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (
|
|
6
|
-
|
|
3
|
+
var digits = '0123456789abcdef';
|
|
4
|
+
var n = '';
|
|
5
|
+
for (var i = 0; i < 16; i += 1) {
|
|
6
|
+
var rand = Math.floor(Math.random() * 16);
|
|
7
7
|
n += digits[rand];
|
|
8
8
|
}
|
|
9
9
|
return n;
|
|
@@ -14,7 +14,7 @@ function randomTraceId() {
|
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function ZipkinMultiTracer(configuration) {
|
|
17
|
-
|
|
17
|
+
var rootSpanId = randomTraceId();
|
|
18
18
|
if (configuration.traceId128Bit) {
|
|
19
19
|
// 128bit生成traceid
|
|
20
20
|
this._traceId = randomTraceId() + rootSpanId
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// === Generate a random 64-bit number in fixed-length hex format
|
|
2
2
|
function randomTraceId() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (
|
|
6
|
-
|
|
3
|
+
var digits = '0123456789abcdef';
|
|
4
|
+
var n = '';
|
|
5
|
+
for (var i = 0; i < 16; i += 1) {
|
|
6
|
+
var rand = Math.floor(Math.random() * 16);
|
|
7
7
|
n += digits[rand];
|
|
8
8
|
}
|
|
9
9
|
return n;
|
|
@@ -14,7 +14,7 @@ function randomTraceId() {
|
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function ZipkinSingleTracer(configuration) {
|
|
17
|
-
|
|
17
|
+
var rootSpanId = randomTraceId();
|
|
18
18
|
this._traceId = randomTraceId() + rootSpanId
|
|
19
19
|
this._spanId = rootSpanId
|
|
20
20
|
}
|
|
@@ -8,20 +8,24 @@ export function trackEventCounts(lifeCycle, callback) {
|
|
|
8
8
|
errorCount: 0,
|
|
9
9
|
longTaskCount: 0,
|
|
10
10
|
resourceCount: 0,
|
|
11
|
-
|
|
11
|
+
actionCount: 0,
|
|
12
|
+
frustrationCount: 0,
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
var subscription = lifeCycle.subscribe(
|
|
15
|
-
LifeCycleEventType.
|
|
16
|
-
function (
|
|
17
|
-
|
|
18
|
-
switch (rawRumEvent.type) {
|
|
16
|
+
LifeCycleEventType.RUM_EVENT_COLLECTED,
|
|
17
|
+
function (event) {
|
|
18
|
+
switch (event.type) {
|
|
19
19
|
case RumEventType.ERROR:
|
|
20
20
|
eventCounts.errorCount += 1
|
|
21
|
+
|
|
21
22
|
callback(eventCounts)
|
|
22
23
|
break
|
|
23
24
|
case RumEventType.ACTION:
|
|
24
|
-
|
|
25
|
+
if (event.action.frustration) {
|
|
26
|
+
eventCounts.frustrationCount += event.action.frustration.type.length
|
|
27
|
+
}
|
|
28
|
+
eventCounts.actionCount += 1
|
|
25
29
|
callback(eventCounts)
|
|
26
30
|
break
|
|
27
31
|
case RumEventType.LONG_TASK:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getCookie, setCookie, UUID, ONE_HOUR } from '@cloudcare/browser-core'
|
|
2
|
+
export var ANONYMOUS_ID_COOKIE_NAME = '_dataflulx_usr_id'
|
|
3
|
+
export var ANONYMOUS_ID_EXPIRATION = 60 * 24 * ONE_HOUR
|
|
4
|
+
|
|
5
|
+
export var startCacheUsrCache = function(configuration) {
|
|
6
|
+
var usrCacheId = getCookie(ANONYMOUS_ID_COOKIE_NAME)
|
|
7
|
+
if (!usrCacheId) {
|
|
8
|
+
usrCacheId = UUID()
|
|
9
|
+
setCookie(ANONYMOUS_ID_COOKIE_NAME, usrCacheId, ANONYMOUS_ID_EXPIRATION, configuration.cookieOptions)
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
getId: function() {
|
|
13
|
+
return usrCacheId
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Observable,
|
|
3
|
+
each,
|
|
4
|
+
timeStampNow,
|
|
5
|
+
LifeCycleEventType,
|
|
6
|
+
some,
|
|
7
|
+
matchList,
|
|
8
|
+
instrumentMethodAndCallOriginal
|
|
9
|
+
} from '@cloudcare/browser-core'
|
|
10
|
+
|
|
11
|
+
// Delay to wait for a page activity to validate the tracking process
|
|
12
|
+
export var PAGE_ACTIVITY_VALIDATION_DELAY = 100
|
|
13
|
+
// Delay to wait after a page activity to end the tracking process
|
|
14
|
+
export var PAGE_ACTIVITY_END_DELAY = 100
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Wait for the page activity end
|
|
18
|
+
*
|
|
19
|
+
* Detection lifecycle:
|
|
20
|
+
* ```
|
|
21
|
+
* Wait page activity end
|
|
22
|
+
* .-------------------'--------------------.
|
|
23
|
+
* v v
|
|
24
|
+
* [Wait for a page activity ] [Wait for a maximum duration]
|
|
25
|
+
* [timeout: VALIDATION_DELAY] [ timeout: maxDuration ]
|
|
26
|
+
* / \ |
|
|
27
|
+
* v v |
|
|
28
|
+
* [No page activity] [Page activity] |
|
|
29
|
+
* | |,----------------------. |
|
|
30
|
+
* v v | |
|
|
31
|
+
* (Discard) [Wait for a page activity] | |
|
|
32
|
+
* [ timeout: END_DELAY ] | |
|
|
33
|
+
* / \ | |
|
|
34
|
+
* v v | |
|
|
35
|
+
* [No page activity] [Page activity] | |
|
|
36
|
+
* | | | |
|
|
37
|
+
* | '------------' |
|
|
38
|
+
* '-----------. ,--------------------'
|
|
39
|
+
* v
|
|
40
|
+
* (End)
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Note: by assuming that maxDuration is greater than VALIDATION_DELAY, we are sure that if the
|
|
44
|
+
* process is still alive after maxDuration, it has been validated.
|
|
45
|
+
*/
|
|
46
|
+
export function waitPageActivityEnd(
|
|
47
|
+
lifeCycle,
|
|
48
|
+
domMutationObservable,
|
|
49
|
+
configuration,
|
|
50
|
+
pageActivityEndCallback,
|
|
51
|
+
maxDuration
|
|
52
|
+
) {
|
|
53
|
+
var pageActivityObservable = createPageActivityObservable(
|
|
54
|
+
lifeCycle,
|
|
55
|
+
domMutationObservable,
|
|
56
|
+
configuration
|
|
57
|
+
)
|
|
58
|
+
return doWaitPageActivityEnd(
|
|
59
|
+
pageActivityObservable,
|
|
60
|
+
pageActivityEndCallback,
|
|
61
|
+
maxDuration
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function doWaitPageActivityEnd(
|
|
66
|
+
pageActivityObservable,
|
|
67
|
+
pageActivityEndCallback,
|
|
68
|
+
maxDuration
|
|
69
|
+
) {
|
|
70
|
+
var pageActivityEndTimeoutId
|
|
71
|
+
var hasCompleted = false
|
|
72
|
+
|
|
73
|
+
var validationTimeoutId = setTimeout(function () {
|
|
74
|
+
complete({ hadActivity: false })
|
|
75
|
+
}, PAGE_ACTIVITY_VALIDATION_DELAY)
|
|
76
|
+
var maxDurationTimeoutId =
|
|
77
|
+
maxDuration &&
|
|
78
|
+
setTimeout(function () {
|
|
79
|
+
return complete({ hadActivity: true, end: timeStampNow() })
|
|
80
|
+
}, maxDuration)
|
|
81
|
+
|
|
82
|
+
var pageActivitySubscription = pageActivityObservable.subscribe(function (
|
|
83
|
+
data
|
|
84
|
+
) {
|
|
85
|
+
var isBusy = data.isBusy
|
|
86
|
+
clearTimeout(validationTimeoutId)
|
|
87
|
+
clearTimeout(pageActivityEndTimeoutId)
|
|
88
|
+
var lastChangeTime = timeStampNow()
|
|
89
|
+
if (!isBusy) {
|
|
90
|
+
pageActivityEndTimeoutId = setTimeout(function () {
|
|
91
|
+
complete({ hadActivity: true, end: lastChangeTime })
|
|
92
|
+
}, PAGE_ACTIVITY_END_DELAY)
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
var stop = function () {
|
|
97
|
+
hasCompleted = true
|
|
98
|
+
clearTimeout(validationTimeoutId)
|
|
99
|
+
clearTimeout(pageActivityEndTimeoutId)
|
|
100
|
+
clearTimeout(maxDurationTimeoutId)
|
|
101
|
+
pageActivitySubscription.unsubscribe()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function complete(event) {
|
|
105
|
+
if (hasCompleted) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
stop()
|
|
109
|
+
pageActivityEndCallback(event)
|
|
110
|
+
}
|
|
111
|
+
return { stop: stop }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function createPageActivityObservable(
|
|
115
|
+
lifeCycle,
|
|
116
|
+
domMutationObservable,
|
|
117
|
+
configuration
|
|
118
|
+
) {
|
|
119
|
+
var observable = new Observable(function () {
|
|
120
|
+
var subscriptions = []
|
|
121
|
+
var firstRequestIndex
|
|
122
|
+
var pendingRequestsCount = 0
|
|
123
|
+
|
|
124
|
+
subscriptions.push(
|
|
125
|
+
domMutationObservable.subscribe(notifyPageActivity),
|
|
126
|
+
lifeCycle.subscribe(
|
|
127
|
+
LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
|
|
128
|
+
function (entries) {
|
|
129
|
+
if (
|
|
130
|
+
some(entries, function (entry) {
|
|
131
|
+
return (
|
|
132
|
+
entry.entryType === 'resource' &&
|
|
133
|
+
!isExcludedUrl(configuration, entry.name)
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
) {
|
|
137
|
+
notifyPageActivity()
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
),
|
|
141
|
+
lifeCycle.subscribe(
|
|
142
|
+
LifeCycleEventType.REQUEST_STARTED,
|
|
143
|
+
function (startEvent) {
|
|
144
|
+
if (isExcludedUrl(configuration, startEvent.url)) {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
if (firstRequestIndex === undefined) {
|
|
148
|
+
firstRequestIndex = startEvent.requestIndex
|
|
149
|
+
}
|
|
150
|
+
pendingRequestsCount += 1
|
|
151
|
+
notifyPageActivity()
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
lifeCycle.subscribe(
|
|
155
|
+
LifeCycleEventType.REQUEST_COMPLETED,
|
|
156
|
+
function (request) {
|
|
157
|
+
if (
|
|
158
|
+
isExcludedUrl(configuration, request.url) ||
|
|
159
|
+
firstRequestIndex === undefined ||
|
|
160
|
+
// If the request started before the tracking start, ignore it
|
|
161
|
+
request.requestIndex < firstRequestIndex
|
|
162
|
+
) {
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
pendingRequestsCount -= 1
|
|
166
|
+
notifyPageActivity()
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
trackWindowOpen(notifyPageActivity)
|
|
172
|
+
return function () {
|
|
173
|
+
each(subscriptions, function (s) {
|
|
174
|
+
s.unsubscribe()
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function notifyPageActivity() {
|
|
179
|
+
observable.notify({ isBusy: pendingRequestsCount > 0 })
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
return observable
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function isExcludedUrl(configuration, requestUrl) {
|
|
187
|
+
return matchList(configuration.excludedActivityUrls, requestUrl)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function trackWindowOpen(callback) {
|
|
191
|
+
return instrumentMethodAndCallOriginal(window, 'open', { before: callback })
|
|
192
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Batch, createHttpRequest, LifeCycleEventType, RumEventType } from '@cloudcare/browser-core'
|
|
2
|
+
|
|
3
|
+
export function startRumBatch(
|
|
4
|
+
configuration,
|
|
5
|
+
lifeCycle,
|
|
6
|
+
reportError
|
|
7
|
+
) {
|
|
8
|
+
var batch = makeRumBatch(configuration, lifeCycle, reportError)
|
|
9
|
+
|
|
10
|
+
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, function(serverRumEvent){
|
|
11
|
+
if (serverRumEvent.type === RumEventType.VIEW) {
|
|
12
|
+
batch.upsert(serverRumEvent, serverRumEvent.view.id)
|
|
13
|
+
} else {
|
|
14
|
+
batch.add(serverRumEvent)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function makeRumBatch(
|
|
22
|
+
configuration,
|
|
23
|
+
lifeCycle,
|
|
24
|
+
reportError
|
|
25
|
+
) {
|
|
26
|
+
var primaryBatch = createRumBatch(configuration.datakitUrl, function() {
|
|
27
|
+
lifeCycle.notify(LifeCycleEventType.BEFORE_UNLOAD)
|
|
28
|
+
})
|
|
29
|
+
function createRumBatch(endpointUrl, unloadCallback) {
|
|
30
|
+
return new Batch(
|
|
31
|
+
createHttpRequest(endpointUrl, configuration.batchBytesLimit, reportError),
|
|
32
|
+
configuration.batchMessagesLimit,
|
|
33
|
+
configuration.batchBytesLimit,
|
|
34
|
+
configuration.messageBytesLimit,
|
|
35
|
+
configuration.flushTimeout,
|
|
36
|
+
unloadCallback
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
add: function(message){
|
|
42
|
+
primaryBatch.add(message)
|
|
43
|
+
},
|
|
44
|
+
upsert: function(message, key){
|
|
45
|
+
primaryBatch.upsert(message, key)
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.startInternalContext = startInternalContext;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal context keep returning v1 format
|
|
10
|
-
* to not break compatibility with logs data format
|
|
11
|
-
*/
|
|
12
|
-
function startInternalContext(applicationId, session, parentContexts) {
|
|
13
|
-
return {
|
|
14
|
-
get: function get(startTime) {
|
|
15
|
-
var viewContext = parentContexts.findView(startTime);
|
|
16
|
-
|
|
17
|
-
if (session.isTracked() && viewContext && viewContext.session.id) {
|
|
18
|
-
var actionContext = parentContexts.findAction(startTime);
|
|
19
|
-
return {
|
|
20
|
-
application: {
|
|
21
|
-
id: applicationId
|
|
22
|
-
},
|
|
23
|
-
session: {
|
|
24
|
-
id: viewContext.session.id
|
|
25
|
-
},
|
|
26
|
-
userAction: actionContext ? {
|
|
27
|
-
id: actionContext.userAction.id
|
|
28
|
-
} : undefined,
|
|
29
|
-
view: viewContext.view
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|