@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
package/esm/transport/batch.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { LifeCycleEventType, HttpRequest, Batch, RumEventType, JsBirdge, processedMessageByDataMap } from '@cloudcare/browser-core';
|
|
2
|
-
|
|
3
|
-
var setBridgeData = function setBridgeData(serverRumEvent, jsBirdge) {
|
|
4
|
-
var rowData = processedMessageByDataMap(serverRumEvent).rowData;
|
|
5
|
-
|
|
6
|
-
if (rowData) {
|
|
7
|
-
jsBirdge.sendEvent({
|
|
8
|
-
name: 'rum',
|
|
9
|
-
data: rowData
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
var setBatchData = function setBatchData(serverRumEvent, rumBatch) {
|
|
15
|
-
if (serverRumEvent.type === RumEventType.VIEW) {
|
|
16
|
-
rumBatch.upsert(serverRumEvent, serverRumEvent.view.id);
|
|
17
|
-
} else {
|
|
18
|
-
rumBatch.add(serverRumEvent);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export function startRumBatch(configuration, lifeCycle) {
|
|
23
|
-
var rumBatch = makeRumBatch(configuration, lifeCycle);
|
|
24
|
-
var jsBirdge;
|
|
25
|
-
|
|
26
|
-
if (configuration.isJsBirdge) {
|
|
27
|
-
jsBirdge = new JsBirdge(configuration);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, function (serverRumEvent) {
|
|
31
|
-
// 处理webview 情况
|
|
32
|
-
if (jsBirdge && jsBirdge.bridge) {
|
|
33
|
-
setBridgeData(serverRumEvent, jsBirdge);
|
|
34
|
-
} else {
|
|
35
|
-
setBatchData(serverRumEvent, rumBatch);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
stop: function stop() {
|
|
40
|
-
rumBatch.stop();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function makeRumBatch(configuration, lifeCycle) {
|
|
46
|
-
var primaryBatch = createRumBatch(configuration.datakitUrl, function () {
|
|
47
|
-
lifeCycle.notify(LifeCycleEventType.BEFORE_UNLOAD);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
function createRumBatch(endpointUrl, unloadCallback) {
|
|
51
|
-
return new Batch(new HttpRequest(endpointUrl, configuration.batchBytesLimit, configuration.isLineProtocolToJson), configuration.maxBatchSize, configuration.batchBytesLimit, configuration.maxMessageSize, configuration.flushTimeout, configuration.isLineProtocolToJson, unloadCallback);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var stopped = false;
|
|
55
|
-
return {
|
|
56
|
-
add: function add(message) {
|
|
57
|
-
if (stopped) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
primaryBatch.add(message);
|
|
62
|
-
},
|
|
63
|
-
stop: function stop() {
|
|
64
|
-
stopped = true;
|
|
65
|
-
},
|
|
66
|
-
upsert: function upsert(message, key) {
|
|
67
|
-
if (stopped) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
primaryBatch.upsert(message, key);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal context keep returning v1 format
|
|
3
|
-
* to not break compatibility with logs data format
|
|
4
|
-
*/
|
|
5
|
-
export function startInternalContext(applicationId, session, parentContexts) {
|
|
6
|
-
return {
|
|
7
|
-
get: function (startTime) {
|
|
8
|
-
var viewContext = parentContexts.findView(startTime)
|
|
9
|
-
if (session.isTracked() && viewContext && viewContext.session.id) {
|
|
10
|
-
const actionContext = parentContexts.findAction(startTime)
|
|
11
|
-
return {
|
|
12
|
-
application: {
|
|
13
|
-
id: applicationId
|
|
14
|
-
},
|
|
15
|
-
session: {
|
|
16
|
-
id: viewContext.session.id
|
|
17
|
-
},
|
|
18
|
-
userAction: actionContext
|
|
19
|
-
? {
|
|
20
|
-
id: actionContext.userAction.id
|
|
21
|
-
}
|
|
22
|
-
: undefined,
|
|
23
|
-
view: viewContext.view
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ONE_MINUTE,
|
|
3
|
-
each,
|
|
4
|
-
relativeNow,
|
|
5
|
-
replaceNumberCharByPath,
|
|
6
|
-
getQueryParamsFromUrl,
|
|
7
|
-
jsonStringify,
|
|
8
|
-
SESSION_TIME_OUT_DELAY,
|
|
9
|
-
LifeCycleEventType
|
|
10
|
-
} from '@cloudcare/browser-core'
|
|
11
|
-
export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY
|
|
12
|
-
export var ACTION_CONTEXT_TIME_OUT_DELAY = 5 * ONE_MINUTE // arbitrary
|
|
13
|
-
export var CLEAR_OLD_CONTEXTS_INTERVAL = ONE_MINUTE
|
|
14
|
-
|
|
15
|
-
export function startParentContexts(lifeCycle, session) {
|
|
16
|
-
var currentView
|
|
17
|
-
var currentAction
|
|
18
|
-
var currentSessionId
|
|
19
|
-
|
|
20
|
-
var previousViews = []
|
|
21
|
-
var previousActions = []
|
|
22
|
-
|
|
23
|
-
lifeCycle.subscribe(
|
|
24
|
-
LifeCycleEventType.VIEW_CREATED,
|
|
25
|
-
function (currentContext) {
|
|
26
|
-
currentView = currentContext
|
|
27
|
-
currentSessionId = session.getId()
|
|
28
|
-
}
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
lifeCycle.subscribe(
|
|
32
|
-
LifeCycleEventType.VIEW_UPDATED,
|
|
33
|
-
function (currentContext) {
|
|
34
|
-
// A view can be updated after its end. We have to ensure that the view being updated is the
|
|
35
|
-
// most recently created.
|
|
36
|
-
if (currentView && currentView.id === currentContext.id) {
|
|
37
|
-
currentView = currentContext
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
42
|
-
if (currentView) {
|
|
43
|
-
previousViews.unshift({
|
|
44
|
-
endTime: data.endClocks.relative,
|
|
45
|
-
context: buildCurrentViewContext(),
|
|
46
|
-
startTime: currentView.startClocks.relative
|
|
47
|
-
})
|
|
48
|
-
currentView = undefined
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
lifeCycle.subscribe(
|
|
52
|
-
LifeCycleEventType.AUTO_ACTION_CREATED,
|
|
53
|
-
function (currentContext) {
|
|
54
|
-
currentAction = currentContext
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
lifeCycle.subscribe(
|
|
59
|
-
LifeCycleEventType.AUTO_ACTION_COMPLETED,
|
|
60
|
-
function (action) {
|
|
61
|
-
if (currentAction) {
|
|
62
|
-
previousActions.unshift({
|
|
63
|
-
context: buildCurrentActionContext(),
|
|
64
|
-
endTime: currentAction.startClocks.relative + action.duration,
|
|
65
|
-
startTime: currentAction.startClocks.relative
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
currentAction = undefined
|
|
69
|
-
}
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_DISCARDED, function () {
|
|
73
|
-
currentAction = undefined
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
77
|
-
previousViews = []
|
|
78
|
-
previousActions = []
|
|
79
|
-
currentView = undefined
|
|
80
|
-
currentAction = undefined
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
var clearOldContextsInterval = window.setInterval(function () {
|
|
84
|
-
clearOldContexts(previousViews, VIEW_CONTEXT_TIME_OUT_DELAY)
|
|
85
|
-
clearOldContexts(previousActions, ACTION_CONTEXT_TIME_OUT_DELAY)
|
|
86
|
-
}, CLEAR_OLD_CONTEXTS_INTERVAL)
|
|
87
|
-
|
|
88
|
-
function clearOldContexts(previousContexts, timeOutDelay) {
|
|
89
|
-
var oldTimeThreshold = relativeNow() - timeOutDelay
|
|
90
|
-
while (
|
|
91
|
-
previousContexts.length > 0 &&
|
|
92
|
-
previousContexts[previousContexts.length - 1].startTime < oldTimeThreshold
|
|
93
|
-
) {
|
|
94
|
-
previousContexts.pop()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function buildCurrentViewContext() {
|
|
99
|
-
return {
|
|
100
|
-
session: {
|
|
101
|
-
id: currentSessionId
|
|
102
|
-
},
|
|
103
|
-
view: {
|
|
104
|
-
id: currentView.id,
|
|
105
|
-
referrer: currentView.referrer,
|
|
106
|
-
name: currentView.name,
|
|
107
|
-
url: currentView.location.href,
|
|
108
|
-
host: currentView.location.host,
|
|
109
|
-
path: currentView.location.pathname,
|
|
110
|
-
pathGroup: replaceNumberCharByPath(currentView.location.pathname),
|
|
111
|
-
urlQuery: jsonStringify(
|
|
112
|
-
getQueryParamsFromUrl(currentView.location.href)
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function buildCurrentActionContext() {
|
|
119
|
-
return { userAction: { id: currentAction.id } }
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function findContext(
|
|
123
|
-
buildContext,
|
|
124
|
-
previousContexts,
|
|
125
|
-
currentContext,
|
|
126
|
-
startTime
|
|
127
|
-
) {
|
|
128
|
-
if (startTime === undefined) {
|
|
129
|
-
return currentContext ? buildContext() : undefined
|
|
130
|
-
}
|
|
131
|
-
if (currentContext && startTime >= currentContext.startClocks.relative) {
|
|
132
|
-
return buildContext()
|
|
133
|
-
}
|
|
134
|
-
var flag = undefined
|
|
135
|
-
each(previousContexts, function (previousContext) {
|
|
136
|
-
if (startTime > previousContext.endTime) {
|
|
137
|
-
return false
|
|
138
|
-
}
|
|
139
|
-
if (startTime >= previousContext.startTime) {
|
|
140
|
-
flag = previousContext.context
|
|
141
|
-
return false
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
return flag
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
var parentContexts = {
|
|
148
|
-
findAction: function (startTime) {
|
|
149
|
-
return findContext(
|
|
150
|
-
buildCurrentActionContext,
|
|
151
|
-
previousActions,
|
|
152
|
-
currentAction,
|
|
153
|
-
startTime
|
|
154
|
-
)
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
findView: function (startTime) {
|
|
158
|
-
return findContext(
|
|
159
|
-
buildCurrentViewContext,
|
|
160
|
-
previousViews,
|
|
161
|
-
currentView,
|
|
162
|
-
startTime
|
|
163
|
-
)
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
stop: function () {
|
|
167
|
-
window.clearInterval(clearOldContextsInterval)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return parentContexts
|
|
171
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RequestType,
|
|
3
|
-
startXhrProxy,
|
|
4
|
-
startFetchProxy,
|
|
5
|
-
LifeCycleEventType
|
|
6
|
-
} from '@cloudcare/browser-core'
|
|
7
|
-
import { isAllowedRequestUrl } from './rumEventsCollection/resource/resourceUtils'
|
|
8
|
-
import { startTracer } from './tracing/tracer'
|
|
9
|
-
|
|
10
|
-
var nextRequestIndex = 1
|
|
11
|
-
|
|
12
|
-
export function startRequestCollection(lifeCycle, configuration) {
|
|
13
|
-
var tracer = startTracer(configuration)
|
|
14
|
-
trackXhr(lifeCycle, configuration, tracer)
|
|
15
|
-
trackFetch(lifeCycle, configuration, tracer)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function matchResponseHeaderByName(headers, name) {
|
|
19
|
-
// getResponseHeader会有跨域问题,所以用该方法匹配
|
|
20
|
-
var reg = new RegExp(name + ':(.*)[\n\r]*', 'i')
|
|
21
|
-
var matchs = headers.match(reg)
|
|
22
|
-
if (matchs && matchs.length > 1) {
|
|
23
|
-
return matchs[1].replace(/\s*/g, '')
|
|
24
|
-
}
|
|
25
|
-
return ''
|
|
26
|
-
}
|
|
27
|
-
function matchContentEncoding(endcoding) {
|
|
28
|
-
if (!endcoding) return ''
|
|
29
|
-
var reg = /charset=(.*)/
|
|
30
|
-
var matchs = endcoding.match(reg)
|
|
31
|
-
if (matchs && matchs.length > 1) {
|
|
32
|
-
return matchs[1].replace(/\s*/g, '')
|
|
33
|
-
}
|
|
34
|
-
return ''
|
|
35
|
-
}
|
|
36
|
-
export function trackXhr(lifeCycle, configuration, tracer) {
|
|
37
|
-
var xhrProxy = startXhrProxy()
|
|
38
|
-
xhrProxy.beforeSend(function (context, xhr) {
|
|
39
|
-
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
40
|
-
tracer.traceXhr(context, xhr)
|
|
41
|
-
|
|
42
|
-
context.requestIndex = getNextRequestIndex()
|
|
43
|
-
|
|
44
|
-
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, {
|
|
45
|
-
requestIndex: context.requestIndex
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
xhrProxy.onRequestComplete(function (context) {
|
|
50
|
-
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
51
|
-
tracer.clearTracingIfCancelled(context)
|
|
52
|
-
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
|
|
53
|
-
duration: context.duration,
|
|
54
|
-
method: context.method,
|
|
55
|
-
requestIndex: context.requestIndex,
|
|
56
|
-
response: context.response,
|
|
57
|
-
traceId: context.traceId,
|
|
58
|
-
startClocks: context.startClocks,
|
|
59
|
-
spanId: context.spanId,
|
|
60
|
-
startTime: context.startTime,
|
|
61
|
-
status: context.status,
|
|
62
|
-
type: RequestType.XHR,
|
|
63
|
-
url: context.url
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
return xhrProxy
|
|
68
|
-
}
|
|
69
|
-
function getAllFetchResponseHeaders(headers) {
|
|
70
|
-
if (!headers || !(headers instanceof Headers)) return ''
|
|
71
|
-
var headerArry = []
|
|
72
|
-
var entries = headers.entries()
|
|
73
|
-
var next = entries.next()
|
|
74
|
-
while (next && !next.done) {
|
|
75
|
-
headerArry.push(next.value.join(':'))
|
|
76
|
-
next = entries.next()
|
|
77
|
-
}
|
|
78
|
-
return headerArry.join(/\r\n/)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function trackFetch(lifeCycle, configuration, tracer) {
|
|
82
|
-
var fetchProxy = startFetchProxy()
|
|
83
|
-
fetchProxy.beforeSend(function (context) {
|
|
84
|
-
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
85
|
-
tracer.traceFetch(context)
|
|
86
|
-
context.requestIndex = getNextRequestIndex()
|
|
87
|
-
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, {
|
|
88
|
-
requestIndex: context.requestIndex
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
fetchProxy.onRequestComplete(function (context) {
|
|
93
|
-
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
94
|
-
tracer.clearTracingIfCancelled(context)
|
|
95
|
-
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
|
|
96
|
-
duration: context.duration,
|
|
97
|
-
method: context.method,
|
|
98
|
-
requestIndex: context.requestIndex,
|
|
99
|
-
response: context.response,
|
|
100
|
-
responseType: context.responseType,
|
|
101
|
-
startClocks: context.startClocks,
|
|
102
|
-
spanId: context.spanId,
|
|
103
|
-
startTime: context.startTime,
|
|
104
|
-
status: context.status,
|
|
105
|
-
traceId: context.traceId,
|
|
106
|
-
type: RequestType.FETCH,
|
|
107
|
-
url: context.url
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
return fetchProxy
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function getNextRequestIndex() {
|
|
115
|
-
var result = nextRequestIndex
|
|
116
|
-
nextRequestIndex += 1
|
|
117
|
-
return result
|
|
118
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addEventListener,
|
|
3
|
-
elapsed,
|
|
4
|
-
UUID,
|
|
5
|
-
clocksNow,
|
|
6
|
-
preferredClock,
|
|
7
|
-
ActionType,
|
|
8
|
-
DOM_EVENT,
|
|
9
|
-
LifeCycleEventType
|
|
10
|
-
} from '@cloudcare/browser-core'
|
|
11
|
-
import { trackEventCounts } from '../../trackEventCounts'
|
|
12
|
-
import { waitIdlePageActivity } from '../../trackPageActivities'
|
|
13
|
-
import { getActionNameFromElement } from './getActionNameFromElement'
|
|
14
|
-
|
|
15
|
-
export function trackActions(lifeCycle) {
|
|
16
|
-
var action = startActionManagement(lifeCycle)
|
|
17
|
-
|
|
18
|
-
// New views trigger the discard of the current pending Action
|
|
19
|
-
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
20
|
-
action.discardCurrent()
|
|
21
|
-
})
|
|
22
|
-
var _addEventListener = addEventListener(
|
|
23
|
-
window,
|
|
24
|
-
DOM_EVENT.CLICK,
|
|
25
|
-
function (event) {
|
|
26
|
-
if (!(event.target instanceof Element)) {
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
var name = getActionNameFromElement(event.target)
|
|
30
|
-
if (!name) {
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
action.create(ActionType.CLICK, name)
|
|
34
|
-
},
|
|
35
|
-
{ capture: true }
|
|
36
|
-
)
|
|
37
|
-
var stopListener = _addEventListener.stop
|
|
38
|
-
return {
|
|
39
|
-
stop: function () {
|
|
40
|
-
action.discardCurrent()
|
|
41
|
-
stopListener()
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function startActionManagement(lifeCycle) {
|
|
47
|
-
var currentAction
|
|
48
|
-
var currentIdlePageActivitySubscription
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
create: function (type, name) {
|
|
52
|
-
if (currentAction) {
|
|
53
|
-
// Ignore any new action if another one is already occurring.
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
var pendingAutoAction = new PendingAutoAction(lifeCycle, type, name)
|
|
57
|
-
|
|
58
|
-
currentAction = pendingAutoAction
|
|
59
|
-
currentIdlePageActivitySubscription = waitIdlePageActivity(
|
|
60
|
-
lifeCycle,
|
|
61
|
-
function (params) {
|
|
62
|
-
if (params.hadActivity) {
|
|
63
|
-
pendingAutoAction.complete(params.endTime)
|
|
64
|
-
} else {
|
|
65
|
-
pendingAutoAction.discard()
|
|
66
|
-
}
|
|
67
|
-
currentAction = undefined
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
},
|
|
71
|
-
discardCurrent: function () {
|
|
72
|
-
if (currentAction) {
|
|
73
|
-
currentIdlePageActivitySubscription.stop()
|
|
74
|
-
currentAction.discard()
|
|
75
|
-
currentAction = undefined
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
var PendingAutoAction = function (lifeCycle, type, name) {
|
|
81
|
-
this.id = UUID()
|
|
82
|
-
this.startClocks = clocksNow()
|
|
83
|
-
this.name = name
|
|
84
|
-
this.type = type
|
|
85
|
-
this.lifeCycle = lifeCycle
|
|
86
|
-
this.eventCountsSubscription = trackEventCounts(lifeCycle)
|
|
87
|
-
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
|
|
88
|
-
id: this.id,
|
|
89
|
-
startClocks: this.startClocks
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
PendingAutoAction.prototype = {
|
|
93
|
-
complete: function (endTime) {
|
|
94
|
-
var eventCounts = this.eventCountsSubscription.eventCounts
|
|
95
|
-
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, {
|
|
96
|
-
counts: {
|
|
97
|
-
errorCount: eventCounts.errorCount,
|
|
98
|
-
longTaskCount: eventCounts.longTaskCount,
|
|
99
|
-
resourceCount: eventCounts.resourceCount
|
|
100
|
-
},
|
|
101
|
-
duration: elapsed(preferredClock(this.startClocks), endTime),
|
|
102
|
-
id: this.id,
|
|
103
|
-
name: this.name,
|
|
104
|
-
startClocks: this.startClocks,
|
|
105
|
-
type: this.type
|
|
106
|
-
})
|
|
107
|
-
this.eventCountsSubscription.stop()
|
|
108
|
-
},
|
|
109
|
-
discard: function () {
|
|
110
|
-
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_DISCARDED)
|
|
111
|
-
this.eventCountsSubscription.stop()
|
|
112
|
-
}
|
|
113
|
-
}
|
package/src/domain/rumSession.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
startSessionManagement,
|
|
3
|
-
performDraw,
|
|
4
|
-
LifeCycleEventType
|
|
5
|
-
} from '@cloudcare/browser-core'
|
|
6
|
-
export var RUM_SESSION_KEY = 'rum'
|
|
7
|
-
export var RumTrackingType = {
|
|
8
|
-
NOT_TRACKED: '0',
|
|
9
|
-
TRACKED_WITH_RESOURCES: '1',
|
|
10
|
-
TRACKED_WITHOUT_RESOURCES: '2',
|
|
11
|
-
TRACKED_WITH_SERVICE: '3' // 采样数据添加额外的tag,不舍弃,直接上报到服务端
|
|
12
|
-
}
|
|
13
|
-
export function startRumSession(configuration, lifeCycle) {
|
|
14
|
-
var session = startSessionManagement(
|
|
15
|
-
configuration.cookieOptions,
|
|
16
|
-
RUM_SESSION_KEY,
|
|
17
|
-
function (rawTrackingType) {
|
|
18
|
-
return computeSessionState(configuration, rawTrackingType)
|
|
19
|
-
}
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
session.renewObservable.subscribe(function () {
|
|
23
|
-
lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
getId: session.getId,
|
|
28
|
-
getAnonymousID: session.getAnonymousID,
|
|
29
|
-
getDebugSession: session.getDebugSession,
|
|
30
|
-
addDebugSession: session.addDebugSession,
|
|
31
|
-
clearDebugSession: session.clearDebugSession,
|
|
32
|
-
isTracked: function () {
|
|
33
|
-
return (
|
|
34
|
-
session.getId() !== undefined && isTracked(session.getTrackingType())
|
|
35
|
-
)
|
|
36
|
-
},
|
|
37
|
-
isTrackedWidthService: function() {
|
|
38
|
-
return session.getId() !== undefined && session.getTrackingType() === RumTrackingType.TRACKED_WITH_SERVICE
|
|
39
|
-
},
|
|
40
|
-
isTrackedWithResource: function () {
|
|
41
|
-
var trackingType = session.getTrackingType()
|
|
42
|
-
return (
|
|
43
|
-
session.getId() !== undefined &&
|
|
44
|
-
(trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITH_SERVICE)
|
|
45
|
-
)
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function computeSessionState(configuration, rawTrackingType) {
|
|
51
|
-
var trackingType
|
|
52
|
-
if (hasValidRumSession(rawTrackingType)) {
|
|
53
|
-
trackingType = rawTrackingType
|
|
54
|
-
} else if (!performDraw(configuration.sampleRate)) {
|
|
55
|
-
if (configuration.isServiceSampling) {
|
|
56
|
-
trackingType = RumTrackingType.TRACKED_WITH_SERVICE
|
|
57
|
-
} else {
|
|
58
|
-
trackingType = RumTrackingType.NOT_TRACKED
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
} else if (!performDraw(configuration.resourceSampleRate)) {
|
|
62
|
-
// trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
63
|
-
if (configuration.isServiceSampling) {
|
|
64
|
-
trackingType = RumTrackingType.TRACKED_WITH_SERVICE
|
|
65
|
-
} else {
|
|
66
|
-
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
trackingType = RumTrackingType.TRACKED_WITH_RESOURCES
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
trackingType: trackingType,
|
|
73
|
-
isTracked: isTracked(trackingType)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function hasValidRumSession(trackingType) {
|
|
78
|
-
return (
|
|
79
|
-
trackingType === RumTrackingType.NOT_TRACKED ||
|
|
80
|
-
trackingType === RumTrackingType.TRACKED_WITH_RESOURCES ||
|
|
81
|
-
trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES ||
|
|
82
|
-
trackingType === RumTrackingType.TRACKED_WITH_SERVICE
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function isTracked(rumSessionType) {
|
|
87
|
-
return (
|
|
88
|
-
rumSessionType === RumTrackingType.TRACKED_WITH_RESOURCES ||
|
|
89
|
-
rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES ||
|
|
90
|
-
rumSessionType === RumTrackingType.TRACKED_WITH_SERVICE
|
|
91
|
-
)
|
|
92
|
-
}
|