@cloudcare/browser-rum 2.1.6 → 2.2.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.
Files changed (134) hide show
  1. package/README.md +1 -2
  2. package/bundle/dataflux-rum.js +1 -1
  3. package/cjs/boot/buildEnv.js +1 -1
  4. package/cjs/boot/rum.js +57 -48
  5. package/cjs/boot/rumPublicApi.js +169 -134
  6. package/cjs/domain/assembly.js +58 -44
  7. package/cjs/domain/configuration.js +67 -0
  8. package/cjs/domain/contexts/internalContext.js +45 -0
  9. package/cjs/domain/contexts/urlContexts.js +68 -0
  10. package/cjs/domain/contexts/viewContexts.js +43 -0
  11. package/cjs/domain/domMutationCollection.js +44 -31
  12. package/cjs/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +25 -25
  13. package/cjs/domain/performanceCollection.js +55 -24
  14. package/cjs/domain/requestCollection.js +117 -0
  15. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +22 -4
  16. package/cjs/domain/rumEventsCollection/actions/clickChain.js +82 -0
  17. package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +78 -0
  18. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
  19. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +163 -0
  20. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +74 -0
  21. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +263 -0
  22. package/cjs/domain/rumEventsCollection/error/errorCollection.js +33 -53
  23. package/cjs/domain/rumEventsCollection/error/trackConsoleError.js +26 -0
  24. package/cjs/domain/rumEventsCollection/error/trackReportError.js +26 -0
  25. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +46 -17
  26. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +49 -9
  27. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +7 -5
  28. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +61 -24
  29. package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +91 -51
  30. package/cjs/domain/rumEventsCollection/view/trackViews.js +119 -86
  31. package/cjs/domain/rumEventsCollection/view/viewCollection.js +41 -31
  32. package/cjs/domain/rumSessionManager.js +95 -0
  33. package/cjs/domain/tracing/tracer.js +8 -9
  34. package/cjs/domain/trackEventCounts.js +9 -6
  35. package/cjs/domain/usr/index.js +30 -0
  36. package/cjs/domain/waitPageActivityEnd.js +163 -0
  37. package/cjs/transport/startRumBatch.js +38 -0
  38. package/esm/boot/buildEnv.js +1 -1
  39. package/esm/boot/rum.js +55 -48
  40. package/esm/boot/rumPublicApi.js +167 -135
  41. package/esm/domain/assembly.js +58 -44
  42. package/esm/domain/configuration.js +53 -0
  43. package/esm/domain/contexts/internalContext.js +38 -0
  44. package/esm/domain/contexts/urlContexts.js +58 -0
  45. package/esm/domain/contexts/viewContexts.js +32 -0
  46. package/esm/domain/domMutationCollection.js +43 -33
  47. package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +26 -24
  48. package/esm/domain/performanceCollection.js +56 -26
  49. package/esm/domain/requestCollection.js +102 -0
  50. package/esm/domain/rumEventsCollection/actions/actionCollection.js +23 -5
  51. package/esm/domain/rumEventsCollection/actions/clickChain.js +69 -0
  52. package/esm/domain/rumEventsCollection/actions/computeFrustration.js +64 -0
  53. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
  54. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +139 -0
  55. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +66 -0
  56. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +244 -0
  57. package/esm/domain/rumEventsCollection/error/errorCollection.js +32 -54
  58. package/esm/domain/rumEventsCollection/error/trackConsoleError.js +18 -0
  59. package/esm/domain/rumEventsCollection/error/trackReportError.js +18 -0
  60. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +30 -18
  61. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +31 -9
  62. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +8 -6
  63. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +43 -26
  64. package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +75 -51
  65. package/esm/domain/rumEventsCollection/view/trackViews.js +120 -85
  66. package/esm/domain/rumEventsCollection/view/viewCollection.js +42 -32
  67. package/esm/domain/rumSessionManager.js +80 -0
  68. package/esm/domain/tracing/skywalkingTracer.js +1 -1
  69. package/esm/domain/tracing/tracer.js +7 -8
  70. package/esm/domain/trackEventCounts.js +9 -6
  71. package/esm/domain/usr/index.js +17 -0
  72. package/esm/domain/waitPageActivityEnd.js +147 -0
  73. package/esm/transport/startRumBatch.js +30 -0
  74. package/package.json +3 -3
  75. package/src/boot/rum.js +79 -59
  76. package/src/boot/rumPublicApi.js +165 -171
  77. package/src/domain/assembly.js +77 -54
  78. package/src/domain/configuration.js +69 -0
  79. package/src/domain/contexts/internalContext.js +39 -0
  80. package/src/domain/contexts/urlContexts.js +76 -0
  81. package/src/domain/contexts/viewContexts.js +37 -0
  82. package/src/domain/domMutationCollection.js +48 -32
  83. package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +28 -28
  84. package/src/domain/performanceCollection.js +62 -45
  85. package/src/domain/requestCollection.js +103 -0
  86. package/src/domain/rumEventsCollection/actions/actionCollection.js +34 -11
  87. package/src/domain/rumEventsCollection/actions/clickChain.js +90 -0
  88. package/src/domain/rumEventsCollection/actions/computeFrustration.js +84 -0
  89. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +73 -62
  90. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +157 -0
  91. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +85 -0
  92. package/src/domain/rumEventsCollection/actions/trackClickActions.js +326 -0
  93. package/src/domain/rumEventsCollection/error/errorCollection.js +53 -69
  94. package/src/domain/rumEventsCollection/error/trackConsoleError.js +21 -0
  95. package/src/domain/rumEventsCollection/error/trackReportError.js +22 -0
  96. package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +29 -18
  97. package/src/domain/rumEventsCollection/resource/resourceCollection.js +39 -23
  98. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +9 -6
  99. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +63 -42
  100. package/src/domain/rumEventsCollection/view/trackViewMetrics.js +80 -61
  101. package/src/domain/rumEventsCollection/view/trackViews.js +171 -134
  102. package/src/domain/rumEventsCollection/view/viewCollection.js +69 -49
  103. package/src/domain/rumSessionManager.js +90 -0
  104. package/src/domain/tracing/jaegerTracer.js +5 -5
  105. package/src/domain/tracing/skywalkingTracer.js +3 -3
  106. package/src/domain/tracing/tracer.js +50 -38
  107. package/src/domain/tracing/w3cTraceParentTracer.js +5 -5
  108. package/src/domain/tracing/zipkinMultiTracer.js +5 -5
  109. package/src/domain/tracing/zipkinSingleTracer.js +5 -5
  110. package/src/domain/trackEventCounts.js +10 -6
  111. package/src/domain/usr/index.js +16 -0
  112. package/src/domain/waitPageActivityEnd.js +192 -0
  113. package/src/transport/startRumBatch.js +48 -0
  114. package/cjs/domain/internalContext.js +0 -34
  115. package/cjs/domain/parentContexts.js +0 -143
  116. package/cjs/domain/requestCollections.js +0 -131
  117. package/cjs/domain/rumEventsCollection/actions/trackActions.js +0 -114
  118. package/cjs/domain/rumSession.js +0 -82
  119. package/cjs/domain/trackPageActivities.js +0 -166
  120. package/cjs/transport/batch.js +0 -81
  121. package/esm/domain/internalContext.js +0 -27
  122. package/esm/domain/parentContexts.js +0 -130
  123. package/esm/domain/requestCollections.js +0 -118
  124. package/esm/domain/rumEventsCollection/actions/trackActions.js +0 -103
  125. package/esm/domain/rumSession.js +0 -70
  126. package/esm/domain/trackPageActivities.js +0 -149
  127. package/esm/transport/batch.js +0 -74
  128. package/src/domain/internalContext.js +0 -28
  129. package/src/domain/parentContexts.js +0 -171
  130. package/src/domain/requestCollections.js +0 -118
  131. package/src/domain/rumEventsCollection/actions/trackActions.js +0 -113
  132. package/src/domain/rumSession.js +0 -92
  133. package/src/domain/trackPageActivities.js +0 -170
  134. 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
- const r = (Math.random() * 16) | 0;
6
+ var r = (Math.random() * 16) | 0;
7
7
  /* tslint:disable */
8
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
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 clearTracingIfCancelled(context) {
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
- clearTracingIfCancelled: clearTracingIfCancelled,
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
- // if (context.input instanceof Request && (context.init))
32
-
33
- if (context.input instanceof Request && (!context.init || !context.init.headers)) {
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(headers.concat(objectEntries(tracingHeaders)), function(header){
59
- headersMap[header[0]] = header[1]
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(configuration, context, inject) {
97
- if (!isAllowedUrl(configuration, context.url) || !configuration.traceType) {
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
- const digits = '0123456789abcdef';
4
- let n = '';
5
- for (let i = 0; i < 16; i += 1) {
6
- const rand = Math.floor(Math.random() * 16);
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
- const rootSpanId = randomTraceId();
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
- const digits = '0123456789abcdef';
4
- let n = '';
5
- for (let i = 0; i < 16; i += 1) {
6
- const rand = Math.floor(Math.random() * 16);
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
- const rootSpanId = randomTraceId();
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
- const digits = '0123456789abcdef';
4
- let n = '';
5
- for (let i = 0; i < 16; i += 1) {
6
- const rand = Math.floor(Math.random() * 16);
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
- const rootSpanId = randomTraceId();
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
- userActionCount: 0
11
+ actionCount: 0,
12
+ frustrationCount: 0,
12
13
  }
13
14
 
14
15
  var subscription = lifeCycle.subscribe(
15
- LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
16
- function (data) {
17
- var rawRumEvent = data.rawRumEvent
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
- eventCounts.userActionCount += 1
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
- }