@cloudcare/rum-uniapp 2.1.18 → 2.1.22
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 +42 -34
- package/cjs/boot/buildEnv.js +3 -4
- package/cjs/boot/rum.entry.js +11 -36
- package/cjs/boot/rum.js +2 -25
- package/cjs/core/baseInfo.js +6 -25
- package/cjs/core/boundedBuffer.js +1 -7
- package/cjs/core/configuration.js +15 -27
- package/cjs/core/contextManager.js +5 -17
- package/cjs/core/dataMap.js +5 -10
- package/cjs/core/downloadProxy.js +4 -26
- package/cjs/core/errorCollection.js +5 -35
- package/cjs/core/errorFilter.js +0 -8
- package/cjs/core/errorTools.js +2 -10
- package/cjs/core/heavyCustomerDataWarning.js +3 -9
- package/cjs/core/lifeCycle.js +8 -18
- package/cjs/core/observable.js +7 -13
- package/cjs/core/sdk.js +11 -19
- package/cjs/core/sessionManagement.js +8 -17
- package/cjs/core/transport.js +6 -53
- package/cjs/core/user.js +2 -7
- package/cjs/core/xhrProxy.js +4 -26
- package/cjs/helper/byteUtils.js +6 -12
- package/cjs/helper/commonContext.js +2 -3
- package/cjs/helper/enums.js +17 -28
- package/cjs/helper/jsonStringify.js +5 -12
- package/cjs/helper/limitModification.js +3 -21
- package/cjs/helper/tracekit.js +32 -145
- package/cjs/helper/utils.js +92 -306
- package/cjs/index.js +0 -1
- package/cjs/main.js +10 -0
- package/cjs/rumEventsCollection/action/actionCollection.js +0 -9
- package/cjs/rumEventsCollection/action/trackActions.js +46 -39
- package/cjs/rumEventsCollection/app/appCollection.js +0 -6
- package/cjs/rumEventsCollection/app/index.js +14 -25
- package/cjs/rumEventsCollection/assembly.js +0 -14
- package/cjs/rumEventsCollection/error/errorCollection.js +1 -16
- package/cjs/rumEventsCollection/internalContext.js +0 -2
- package/cjs/rumEventsCollection/page/index.js +19 -49
- package/cjs/rumEventsCollection/page/viewCollection.js +0 -8
- package/cjs/rumEventsCollection/parentContexts.js +3 -20
- package/cjs/rumEventsCollection/performanceCollection.js +0 -4
- package/cjs/rumEventsCollection/requestCollection.js +1 -14
- package/cjs/rumEventsCollection/resource/resourceCollection.js +0 -11
- package/cjs/rumEventsCollection/resource/resourceUtils.js +50 -46
- package/cjs/rumEventsCollection/setDataCollection.js +0 -16
- package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +0 -6
- package/cjs/rumEventsCollection/tracing/jaegerTracer.js +3 -9
- package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +3 -10
- package/cjs/rumEventsCollection/tracing/tracer.js +1 -25
- package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +1 -6
- package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +3 -10
- package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +1 -6
- package/cjs/rumEventsCollection/trackEventCounts.js +0 -8
- package/cjs/rumEventsCollection/trackPageActiveites.js +10 -33
- package/cjs/rumEventsCollection/transport/batch.js +0 -9
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +8 -20
- package/esm/boot/rum.js +0 -4
- package/esm/core/baseInfo.js +0 -11
- package/esm/core/boundedBuffer.js +0 -3
- package/esm/core/configuration.js +13 -21
- package/esm/core/contextManager.js +3 -8
- package/esm/core/dataMap.js +2 -2
- package/esm/core/downloadProxy.js +2 -17
- package/esm/core/errorCollection.js +2 -15
- package/esm/core/errorFilter.js +0 -5
- package/esm/core/errorTools.js +0 -3
- package/esm/core/heavyCustomerDataWarning.js +3 -3
- package/esm/core/lifeCycle.js +0 -5
- package/esm/core/observable.js +0 -3
- package/esm/core/sdk.js +8 -12
- package/esm/core/sessionManagement.js +0 -3
- package/esm/core/transport.js +4 -38
- package/esm/core/user.js +2 -4
- package/esm/core/xhrProxy.js +2 -17
- package/esm/helper/byteUtils.js +4 -7
- package/esm/helper/commonContext.js +2 -2
- package/esm/helper/jsonStringify.js +4 -7
- package/esm/helper/limitModification.js +1 -11
- package/esm/helper/tracekit.js +29 -130
- package/esm/helper/utils.js +27 -125
- package/esm/main.js +4 -0
- package/esm/rumEventsCollection/action/actionCollection.js +0 -4
- package/esm/rumEventsCollection/action/trackActions.js +46 -31
- package/esm/rumEventsCollection/app/appCollection.js +0 -1
- package/esm/rumEventsCollection/app/index.js +12 -17
- package/esm/rumEventsCollection/assembly.js +0 -6
- package/esm/rumEventsCollection/error/errorCollection.js +0 -7
- package/esm/rumEventsCollection/internalContext.js +0 -1
- package/esm/rumEventsCollection/page/index.js +19 -43
- package/esm/rumEventsCollection/page/viewCollection.js +0 -3
- package/esm/rumEventsCollection/parentContexts.js +0 -10
- package/esm/rumEventsCollection/requestCollection.js +0 -4
- package/esm/rumEventsCollection/resource/resourceCollection.js +0 -5
- package/esm/rumEventsCollection/resource/resourceUtils.js +48 -39
- package/esm/rumEventsCollection/setDataCollection.js +0 -13
- package/esm/rumEventsCollection/tracing/ddtraceTracer.js +0 -4
- package/esm/rumEventsCollection/tracing/jaegerTracer.js +3 -7
- package/esm/rumEventsCollection/tracing/skywalkingTracer.js +5 -9
- package/esm/rumEventsCollection/tracing/tracer.js +0 -14
- package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +1 -4
- package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +3 -8
- package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +1 -4
- package/esm/rumEventsCollection/trackEventCounts.js +0 -4
- package/esm/rumEventsCollection/trackPageActiveites.js +9 -22
- package/esm/rumEventsCollection/transport/batch.js +0 -5
- package/package.json +7 -4
|
@@ -6,41 +6,67 @@ import { ActionType } from '../../helper/enums';
|
|
|
6
6
|
import { tracker } from '../../core/sdk';
|
|
7
7
|
var WHITE_METHOD = ['setup'];
|
|
8
8
|
export function trackActions(lifeCycle, Vue) {
|
|
9
|
-
var action = startActionManagement(lifeCycle);
|
|
9
|
+
var action = startActionManagement(lifeCycle);
|
|
10
10
|
|
|
11
|
+
// New views trigger the discard of the current pending Action
|
|
11
12
|
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
12
13
|
action.discardCurrent();
|
|
13
14
|
});
|
|
14
|
-
|
|
15
15
|
if (Vue && Vue.extend) {
|
|
16
16
|
var originVueExtend = Vue.extend;
|
|
17
|
-
|
|
18
17
|
Vue.extend = function (vueOptions) {
|
|
19
18
|
proxyInstance(vueOptions, action, lifeCycle);
|
|
20
19
|
return originVueExtend.call(this, vueOptions);
|
|
21
20
|
};
|
|
22
21
|
} else {
|
|
23
22
|
if (!tracker) return;
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
var hasComponent = false;
|
|
24
|
+
if (Page) {
|
|
25
|
+
hasComponent = true;
|
|
26
|
+
var originPage = Page;
|
|
27
|
+
Page = function Page(page) {
|
|
28
|
+
var methods = getMethods(page);
|
|
29
|
+
methods.forEach(methodName => {
|
|
30
|
+
clickProxy(page, methodName, function (_action) {
|
|
31
|
+
action.create(_action.type, _action.name);
|
|
32
|
+
}, lifeCycle);
|
|
33
|
+
});
|
|
34
|
+
return originPage(page);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (Component) {
|
|
38
|
+
hasComponent = true;
|
|
39
|
+
var originComponent = Component;
|
|
40
|
+
Component = function Component(component) {
|
|
41
|
+
var methods = getMethods(component.methods);
|
|
42
|
+
methods.forEach(methodName => {
|
|
43
|
+
clickProxy(component, methodName, function (_action) {
|
|
44
|
+
action.create(_action.type, _action.name);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return originComponent(component);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!hasComponent) {
|
|
51
|
+
var originCreatePage = tracker.createPage;
|
|
52
|
+
tracker.createPage = function (page) {
|
|
53
|
+
// methods 方法
|
|
54
|
+
proxyInstance(page, action, lifeCycle);
|
|
55
|
+
return originCreatePage.call(this, page);
|
|
56
|
+
};
|
|
57
|
+
var originCreateComponent = tracker.createComponent;
|
|
58
|
+
tracker.createComponent = function (component) {
|
|
59
|
+
proxyInstance(component, action, lifeCycle);
|
|
60
|
+
return originCreateComponent.call(this, component);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// var originVueExtend = Vue.extend
|
|
40
65
|
|
|
41
66
|
return {
|
|
42
67
|
stop: function stop() {
|
|
43
|
-
action.discardCurrent();
|
|
68
|
+
action.discardCurrent();
|
|
69
|
+
// stopListener()
|
|
44
70
|
}
|
|
45
71
|
};
|
|
46
72
|
}
|
|
@@ -55,7 +81,6 @@ function proxyInstance(options, action, lifeCycle) {
|
|
|
55
81
|
}, lifeCycle);
|
|
56
82
|
});
|
|
57
83
|
}
|
|
58
|
-
|
|
59
84
|
var originMethods = getMethods(options);
|
|
60
85
|
originMethods.forEach(methodName => {
|
|
61
86
|
clickProxy(options, methodName, function (_action) {
|
|
@@ -63,20 +88,16 @@ function proxyInstance(options, action, lifeCycle) {
|
|
|
63
88
|
}, lifeCycle);
|
|
64
89
|
});
|
|
65
90
|
}
|
|
66
|
-
|
|
67
91
|
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
68
92
|
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
69
93
|
var originMethod = origin[methodName];
|
|
70
|
-
|
|
71
94
|
origin[methodName] = function () {
|
|
72
95
|
var result = originMethod.apply(this, arguments);
|
|
73
96
|
var action = {};
|
|
74
|
-
|
|
75
97
|
if (isObject(arguments[0])) {
|
|
76
98
|
var currentTarget = arguments[0].currentTarget || {};
|
|
77
99
|
var dataset = currentTarget.dataset || {};
|
|
78
100
|
var actionType = arguments[0].type;
|
|
79
|
-
|
|
80
101
|
if (actionType && ActionType[actionType]) {
|
|
81
102
|
action.type = actionType;
|
|
82
103
|
action.name = dataset.name || dataset.content || dataset.type;
|
|
@@ -105,11 +126,9 @@ function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
|
105
126
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
|
-
|
|
109
129
|
return result;
|
|
110
130
|
};
|
|
111
131
|
}
|
|
112
|
-
|
|
113
132
|
function startActionManagement(lifeCycle) {
|
|
114
133
|
var currentAction;
|
|
115
134
|
var currentIdlePageActivitySubscription;
|
|
@@ -119,7 +138,6 @@ function startActionManagement(lifeCycle) {
|
|
|
119
138
|
// Ignore any new action if another one is already occurring.
|
|
120
139
|
return;
|
|
121
140
|
}
|
|
122
|
-
|
|
123
141
|
var pendingAutoAction = new PendingAutoAction(lifeCycle, type, name);
|
|
124
142
|
currentAction = pendingAutoAction;
|
|
125
143
|
currentIdlePageActivitySubscription = waitIdlePageActivity(lifeCycle, function (params) {
|
|
@@ -128,7 +146,6 @@ function startActionManagement(lifeCycle) {
|
|
|
128
146
|
} else {
|
|
129
147
|
pendingAutoAction.discard();
|
|
130
148
|
}
|
|
131
|
-
|
|
132
149
|
currentAction = undefined;
|
|
133
150
|
});
|
|
134
151
|
},
|
|
@@ -141,7 +158,6 @@ function startActionManagement(lifeCycle) {
|
|
|
141
158
|
}
|
|
142
159
|
};
|
|
143
160
|
}
|
|
144
|
-
|
|
145
161
|
var PendingAutoAction = function PendingAutoAction(lifeCycle, type, name) {
|
|
146
162
|
this.id = UUID();
|
|
147
163
|
this.startClocks = now();
|
|
@@ -154,7 +170,6 @@ var PendingAutoAction = function PendingAutoAction(lifeCycle, type, name) {
|
|
|
154
170
|
startClocks: this.startClocks
|
|
155
171
|
});
|
|
156
172
|
};
|
|
157
|
-
|
|
158
173
|
PendingAutoAction.prototype = {
|
|
159
174
|
complete: function complete(endTime) {
|
|
160
175
|
var eventCounts = this.eventCountsSubscription.eventCounts;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { now, areInOrder, UUID } from '../../helper/utils';
|
|
2
|
-
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
2
|
+
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
3
3
|
|
|
4
|
+
// 劫持原小程序App方法
|
|
4
5
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
5
6
|
export var startupTypes = {
|
|
6
7
|
COLD: 'cold',
|
|
@@ -10,12 +11,12 @@ export function rewriteApp(configuration, lifeCycle, Vue) {
|
|
|
10
11
|
var originApp = App;
|
|
11
12
|
var appInfo = {
|
|
12
13
|
isStartUp: false // 是否启动
|
|
13
|
-
|
|
14
14
|
};
|
|
15
|
-
var startTime;
|
|
16
15
|
|
|
16
|
+
var startTime;
|
|
17
17
|
App = function App(app) {
|
|
18
|
-
startTime = now()
|
|
18
|
+
startTime = now()
|
|
19
|
+
// 合并方法,插入记录脚本
|
|
19
20
|
;
|
|
20
21
|
['onLaunch', 'onShow', 'onHide'].forEach(methodName => {
|
|
21
22
|
var userDefinedMethod = app[methodName]; // 暂存用户定义的方法
|
|
@@ -28,28 +29,25 @@ export function rewriteApp(configuration, lifeCycle, Vue) {
|
|
|
28
29
|
} else if (methodName === 'onShow') {
|
|
29
30
|
if (appInfo.isStartUp && appInfo.isHide) {
|
|
30
31
|
// 判断是热启动
|
|
31
|
-
appInfo.startupType = startupTypes.HOT;
|
|
32
|
+
appInfo.startupType = startupTypes.HOT;
|
|
33
|
+
// appUpdate()
|
|
32
34
|
}
|
|
33
35
|
} else if (methodName === 'onHide') {
|
|
34
36
|
lifeCycle.notify(LifeCycleEventType.APP_HIDE);
|
|
35
37
|
appInfo.isHide = true;
|
|
36
38
|
}
|
|
37
|
-
|
|
38
39
|
return userDefinedMethod && userDefinedMethod.call(this, options);
|
|
39
40
|
};
|
|
40
41
|
});
|
|
41
42
|
return originApp(app);
|
|
42
43
|
};
|
|
43
|
-
|
|
44
44
|
startPerformanceObservable(lifeCycle);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
46
|
function startPerformanceObservable(lifeCycle) {
|
|
48
47
|
var subscribe = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, function (entitys) {
|
|
49
48
|
// 过滤掉其他页面监听,只保留首次启动
|
|
50
49
|
var codeDownloadDuration;
|
|
51
50
|
var launchEntity = entitys.find(entity => entity.entryType === 'navigation' && entity.navigationType === 'appLaunch');
|
|
52
|
-
|
|
53
51
|
if (typeof launchEntity !== 'undefined') {
|
|
54
52
|
lifeCycle.notify(LifeCycleEventType.APP_UPDATE, {
|
|
55
53
|
startTime: launchEntity.startTime,
|
|
@@ -59,9 +57,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
59
57
|
duration: launchEntity.duration
|
|
60
58
|
});
|
|
61
59
|
}
|
|
62
|
-
|
|
63
60
|
var scriptentity = entitys.find(entity => entity.entryType === 'script' && entity.name === 'evaluateScript');
|
|
64
|
-
|
|
65
61
|
if (typeof scriptentity !== 'undefined') {
|
|
66
62
|
lifeCycle.notify(LifeCycleEventType.APP_UPDATE, {
|
|
67
63
|
startTime: scriptentity.startTime,
|
|
@@ -71,25 +67,24 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
71
67
|
duration: scriptentity.duration
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
var firstEntity = entitys.find(entity => entity.entryType === 'render' && entity.name === 'firstRender');
|
|
76
|
-
|
|
77
71
|
if (firstEntity && scriptentity && launchEntity) {
|
|
78
72
|
if (!areInOrder(firstEntity.duration, launchEntity.duration) || !areInOrder(scriptentity.duration, launchEntity.duration)) {
|
|
79
73
|
return;
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
codeDownloadDuration = launchEntity.duration - firstEntity.duration - scriptentity.duration;
|
|
76
|
+
// 资源下载耗时
|
|
84
77
|
lifeCycle.notify(LifeCycleEventType.APP_UPDATE, {
|
|
85
78
|
startTime: launchEntity.startTime,
|
|
86
79
|
name: '小程序包下载',
|
|
87
80
|
type: 'package_download',
|
|
88
81
|
id: UUID(),
|
|
89
82
|
duration: codeDownloadDuration
|
|
90
|
-
});
|
|
83
|
+
});
|
|
84
|
+
// 资源下载时间暂时定为:首次启动时间-脚本加载时间-初次渲染时间
|
|
91
85
|
}
|
|
92
86
|
});
|
|
87
|
+
|
|
93
88
|
return {
|
|
94
89
|
stop: subscribe.unsubscribe
|
|
95
90
|
};
|
|
@@ -24,7 +24,6 @@ export function startRumAssembly(applicationId, configuration, session, lifeCycl
|
|
|
24
24
|
launch: baseInfo.getLaunchOptions()
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
|
|
28
27
|
if (session.isTracked() && (viewContext || rawRumEvent.type === RumEventType.APP)) {
|
|
29
28
|
var actionContext = parentContexts.findAction(startTime);
|
|
30
29
|
var commonContext = savedCommonContext || getCommonContext();
|
|
@@ -54,11 +53,9 @@ export function startRumAssembly(applicationId, configuration, session, lifeCycl
|
|
|
54
53
|
var rumEvent = extend2Lev(rumContext, deviceContext, appContext, viewContext, actionContext, rawRumEvent);
|
|
55
54
|
var serverRumEvent = withSnakeCaseKeys(rumEvent);
|
|
56
55
|
var context = extend2Lev({}, commonContext.context, customerContext);
|
|
57
|
-
|
|
58
56
|
if (!isEmptyObject(context)) {
|
|
59
57
|
serverRumEvent.tags = context;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
59
|
if (!isEmptyObject(commonContext.user)) {
|
|
63
60
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
64
61
|
serverRumEvent.user = extend2Lev({
|
|
@@ -66,18 +63,15 @@ export function startRumAssembly(applicationId, configuration, session, lifeCycl
|
|
|
66
63
|
is_signin: 'T'
|
|
67
64
|
}, commonContext.user);
|
|
68
65
|
}
|
|
69
|
-
|
|
70
66
|
if (shouldSend(serverRumEvent, errorFilter)) {
|
|
71
67
|
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
});
|
|
75
71
|
}
|
|
76
|
-
|
|
77
72
|
function shouldSend(event, errorFilter) {
|
|
78
73
|
if (event.type === RumEventType.ERROR) {
|
|
79
74
|
return !errorFilter.isLimitReached();
|
|
80
75
|
}
|
|
81
|
-
|
|
82
76
|
return true;
|
|
83
77
|
}
|
|
@@ -26,7 +26,6 @@ export function doStartErrorCollection(lifeCycle) {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
function computeRawError(error, startTime, context) {
|
|
31
30
|
var stackTrace = error instanceof Error ? computeStackTrace(error) : undefined;
|
|
32
31
|
return extend({
|
|
@@ -35,11 +34,9 @@ function computeRawError(error, startTime, context) {
|
|
|
35
34
|
context
|
|
36
35
|
}, formatUnknownError(stackTrace, error, 'Provided'));
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
function processError(error) {
|
|
40
38
|
var resource = error.resource;
|
|
41
39
|
var tracingInfo;
|
|
42
|
-
|
|
43
40
|
if (resource) {
|
|
44
41
|
tracingInfo = computeRequestTracingInfo(resource);
|
|
45
42
|
var urlObj = urlParse(error.resource.url).getParse();
|
|
@@ -53,7 +50,6 @@ function processError(error) {
|
|
|
53
50
|
urlPathGroup: replaceNumberCharByPath(urlObj.Path)
|
|
54
51
|
};
|
|
55
52
|
}
|
|
56
|
-
|
|
57
53
|
var rawRumEvent = extend2Lev({
|
|
58
54
|
date: error.startTime,
|
|
59
55
|
error: {
|
|
@@ -72,14 +68,11 @@ function processError(error) {
|
|
|
72
68
|
startTime: error.startTime
|
|
73
69
|
};
|
|
74
70
|
}
|
|
75
|
-
|
|
76
71
|
function computeRequestTracingInfo(request) {
|
|
77
72
|
var hasBeenTraced = request.traceId && request.spanId;
|
|
78
|
-
|
|
79
73
|
if (!hasBeenTraced) {
|
|
80
74
|
return undefined;
|
|
81
75
|
}
|
|
82
|
-
|
|
83
76
|
return {
|
|
84
77
|
_dd: {
|
|
85
78
|
spanId: request.spanId,
|
|
@@ -6,7 +6,6 @@ export function startInternalContext(applicationId, session, parentContexts) {
|
|
|
6
6
|
return {
|
|
7
7
|
get: function get(startTime) {
|
|
8
8
|
var viewContext = parentContexts.findView(startTime);
|
|
9
|
-
|
|
10
9
|
if (session.isTracked() && viewContext) {
|
|
11
10
|
var actionContext = parentContexts.findAction(startTime);
|
|
12
11
|
return {
|
|
@@ -1,70 +1,66 @@
|
|
|
1
1
|
import { now, throttle, UUID, isNumber, getActivePage } from '../../helper/utils';
|
|
2
2
|
import { trackEventCounts } from '../trackEventCounts';
|
|
3
|
-
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
3
|
+
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
4
4
|
|
|
5
|
+
// 劫持原小程序App方法
|
|
5
6
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
6
|
-
|
|
7
7
|
function proxyPage(pageOptions, lifeCycle) {
|
|
8
8
|
// 合并方法,插入记录脚本
|
|
9
9
|
var currentView,
|
|
10
|
-
|
|
10
|
+
startTime = now();
|
|
11
11
|
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(methodName => {
|
|
12
12
|
var userDefinedMethod = pageOptions[methodName];
|
|
13
|
-
|
|
14
13
|
pageOptions[methodName] = function () {
|
|
15
|
-
var mpType = this.mpType || this.$vm.mpType;
|
|
16
|
-
|
|
14
|
+
var mpType = this.mpType || this.$vm && this.$vm.mpType;
|
|
17
15
|
if (mpType !== 'page') {
|
|
18
16
|
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
}
|
|
18
|
+
// 只处理page类型
|
|
22
19
|
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
23
20
|
if (typeof currentView === 'undefined') {
|
|
24
21
|
var activePage = getActivePage();
|
|
25
22
|
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
currentView && currentView.setLoadEventEnd(methodName);
|
|
30
|
-
|
|
31
26
|
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
32
27
|
currentView.triggerUpdate();
|
|
33
|
-
|
|
34
28
|
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
35
29
|
currentView.end();
|
|
36
30
|
currentView = undefined;
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
41
34
|
};
|
|
42
35
|
});
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
export function rewritePage(configuration, lifeCycle, Vue) {
|
|
46
38
|
if (Vue && Vue.extend) {
|
|
47
39
|
var originVueExtend = Vue.extend;
|
|
48
|
-
|
|
49
40
|
Vue.extend = function (vueOptions) {
|
|
50
41
|
proxyPage(vueOptions, lifeCycle);
|
|
51
42
|
return originVueExtend.call(this, vueOptions);
|
|
52
43
|
};
|
|
53
44
|
} else {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
if (Page) {
|
|
46
|
+
var originPage = Page;
|
|
47
|
+
Page = function Page(pageOptions) {
|
|
48
|
+
proxyPage(pageOptions, lifeCycle);
|
|
49
|
+
return originPage.call(this, pageOptions);
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
var originComponent = Component;
|
|
53
|
+
Component = function Component(pageOptions) {
|
|
54
|
+
proxyPage(pageOptions.methods, lifeCycle);
|
|
55
|
+
return originComponent.call(this, pageOptions);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
|
-
|
|
63
60
|
function newView(lifeCycle, route, startTime) {
|
|
64
61
|
if (typeof startTime === 'undefined' || Number(startTime) === 0) {
|
|
65
62
|
startTime = now();
|
|
66
63
|
}
|
|
67
|
-
|
|
68
64
|
var id = UUID();
|
|
69
65
|
var isActive = true;
|
|
70
66
|
var eventCounts = {
|
|
@@ -92,21 +88,16 @@ function newView(lifeCycle, route, startTime) {
|
|
|
92
88
|
});
|
|
93
89
|
var scheduleViewUpdate = scheduleViewThrottled.throttled;
|
|
94
90
|
var cancelScheduleViewUpdate = scheduleViewThrottled.cancel;
|
|
95
|
-
|
|
96
91
|
var _trackEventCounts = trackEventCounts(lifeCycle, function (newEventCounts) {
|
|
97
92
|
eventCounts = newEventCounts;
|
|
98
93
|
scheduleViewUpdate();
|
|
99
94
|
});
|
|
100
|
-
|
|
101
95
|
var stopEventCountsTracking = _trackEventCounts.stop;
|
|
102
|
-
|
|
103
96
|
var _trackFptTime = trackFptTime(lifeCycle, function (duration) {
|
|
104
97
|
fpt = duration;
|
|
105
98
|
scheduleViewUpdate();
|
|
106
99
|
});
|
|
107
|
-
|
|
108
100
|
var stopFptTracking = _trackFptTime.stop;
|
|
109
|
-
|
|
110
101
|
var _trackSetDataTime = trackSetDataTime(lifeCycle, function (duration) {
|
|
111
102
|
if (isNumber(duration)) {
|
|
112
103
|
setdataDuration += duration;
|
|
@@ -114,25 +105,20 @@ function newView(lifeCycle, route, startTime) {
|
|
|
114
105
|
scheduleViewUpdate();
|
|
115
106
|
}
|
|
116
107
|
});
|
|
117
|
-
|
|
118
108
|
var stopSetDataTracking = _trackSetDataTime.stop;
|
|
119
|
-
|
|
120
109
|
var _trackLoadingTime = trackLoadingTime(lifeCycle, function (duration) {
|
|
121
110
|
if (isNumber(duration)) {
|
|
122
111
|
loadingDuration = duration;
|
|
123
112
|
scheduleViewUpdate();
|
|
124
113
|
}
|
|
125
114
|
});
|
|
126
|
-
|
|
127
115
|
var stopLoadingTimeTracking = _trackLoadingTime.stop;
|
|
128
|
-
|
|
129
116
|
var setLoadEventEnd = function setLoadEventEnd(type) {
|
|
130
117
|
if (type === 'onLoad') {
|
|
131
118
|
loadingTime = now();
|
|
132
119
|
loadingDuration = loadingTime - startTime;
|
|
133
120
|
} else if (type === 'onShow') {
|
|
134
121
|
showTime = now();
|
|
135
|
-
|
|
136
122
|
if (typeof onload2onshowTime === 'undefined' && typeof loadingTime !== 'undefined') {
|
|
137
123
|
onload2onshowTime = showTime - loadingTime;
|
|
138
124
|
}
|
|
@@ -140,7 +126,6 @@ function newView(lifeCycle, route, startTime) {
|
|
|
140
126
|
if (typeof onshow2onready === 'undefined' && typeof showTime !== 'undefined') {
|
|
141
127
|
onshow2onready = now() - showTime;
|
|
142
128
|
}
|
|
143
|
-
|
|
144
129
|
if (typeof fmp === 'undefined') {
|
|
145
130
|
fmp = now() - startTime; // 从开发者角度看,小程序首屏渲染完成的标志是首页 Page.onReady 事件触发。
|
|
146
131
|
}
|
|
@@ -148,13 +133,10 @@ function newView(lifeCycle, route, startTime) {
|
|
|
148
133
|
if (typeof showTime !== 'undefined') {
|
|
149
134
|
stayTime = now() - showTime;
|
|
150
135
|
}
|
|
151
|
-
|
|
152
136
|
isActive = false;
|
|
153
137
|
}
|
|
154
|
-
|
|
155
138
|
triggerViewUpdate();
|
|
156
139
|
};
|
|
157
|
-
|
|
158
140
|
function triggerViewUpdate() {
|
|
159
141
|
documentVersion += 1;
|
|
160
142
|
lifeCycle.notify(LifeCycleEventType.VIEW_UPDATED, {
|
|
@@ -175,7 +157,6 @@ function newView(lifeCycle, route, startTime) {
|
|
|
175
157
|
isActive: isActive
|
|
176
158
|
});
|
|
177
159
|
}
|
|
178
|
-
|
|
179
160
|
return {
|
|
180
161
|
scheduleUpdate: scheduleViewUpdate,
|
|
181
162
|
setLoadEventEnd,
|
|
@@ -195,11 +176,9 @@ function newView(lifeCycle, route, startTime) {
|
|
|
195
176
|
}
|
|
196
177
|
};
|
|
197
178
|
}
|
|
198
|
-
|
|
199
179
|
function trackFptTime(lifeCycle, callback) {
|
|
200
180
|
var subscribe = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, function (entitys) {
|
|
201
181
|
var firstRenderEntity = entitys.find(entity => entity.entryType === 'render' && entity.name === 'firstRender');
|
|
202
|
-
|
|
203
182
|
if (typeof firstRenderEntity !== 'undefined') {
|
|
204
183
|
callback(firstRenderEntity.duration);
|
|
205
184
|
}
|
|
@@ -208,11 +187,9 @@ function trackFptTime(lifeCycle, callback) {
|
|
|
208
187
|
stop: subscribe.unsubscribe
|
|
209
188
|
};
|
|
210
189
|
}
|
|
211
|
-
|
|
212
190
|
function trackLoadingTime(lifeCycle, callback) {
|
|
213
191
|
var subscribe = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, function (entitys) {
|
|
214
192
|
var navigationEnity = entitys.find(entity => entity.entryType === 'navigation');
|
|
215
|
-
|
|
216
193
|
if (typeof navigationEnity !== 'undefined') {
|
|
217
194
|
callback(navigationEnity.duration);
|
|
218
195
|
}
|
|
@@ -221,7 +198,6 @@ function trackLoadingTime(lifeCycle, callback) {
|
|
|
221
198
|
stop: subscribe.unsubscribe
|
|
222
199
|
};
|
|
223
200
|
}
|
|
224
|
-
|
|
225
201
|
function trackSetDataTime(lifeCycle, callback) {
|
|
226
202
|
var subscribe = lifeCycle.subscribe(LifeCycleEventType.PAGE_SET_DATA_UPDATE, function (data) {
|
|
227
203
|
if (!data) return;
|
|
@@ -8,15 +8,12 @@ export function startViewCollection(lifeCycle, configuration, Vue) {
|
|
|
8
8
|
});
|
|
9
9
|
return rewritePage(configuration, lifeCycle, Vue);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
function processViewUpdate(view) {
|
|
13
12
|
var apdexLevel;
|
|
14
|
-
|
|
15
13
|
if (view.fmp) {
|
|
16
14
|
apdexLevel = parseInt(Number(view.fmp) / 1000);
|
|
17
15
|
apdexLevel = apdexLevel > 9 ? 9 : apdexLevel;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
var viewEvent = {
|
|
21
18
|
_dd: {
|
|
22
19
|
documentVersion: view.documentVersion
|
|
@@ -39,7 +39,6 @@ export function startParentContexts(lifeCycle) {
|
|
|
39
39
|
startTime: currentAction.startClocks
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
|
|
43
42
|
currentAction = undefined;
|
|
44
43
|
});
|
|
45
44
|
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_DISCARDED, function () {
|
|
@@ -54,15 +53,12 @@ export function startParentContexts(lifeCycle) {
|
|
|
54
53
|
var clearOldContextsInterval = setInterval(function () {
|
|
55
54
|
clearOldContexts(previousViews, VIEW_CONTEXT_TIME_OUT_DELAY);
|
|
56
55
|
}, CLEAR_OLD_CONTEXTS_INTERVAL);
|
|
57
|
-
|
|
58
56
|
function clearOldContexts(previousContexts, timeOutDelay) {
|
|
59
57
|
var oldTimeThreshold = now() - timeOutDelay;
|
|
60
|
-
|
|
61
58
|
while (previousContexts.length > 0 && previousContexts[previousContexts.length - 1].startTime < oldTimeThreshold) {
|
|
62
59
|
previousContexts.pop();
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
|
|
66
62
|
function buildCurrentActionContext() {
|
|
67
63
|
return {
|
|
68
64
|
userAction: {
|
|
@@ -70,7 +66,6 @@ export function startParentContexts(lifeCycle) {
|
|
|
70
66
|
}
|
|
71
67
|
};
|
|
72
68
|
}
|
|
73
|
-
|
|
74
69
|
function buildCurrentViewContext() {
|
|
75
70
|
return {
|
|
76
71
|
page: {
|
|
@@ -80,22 +75,18 @@ export function startParentContexts(lifeCycle) {
|
|
|
80
75
|
}
|
|
81
76
|
};
|
|
82
77
|
}
|
|
83
|
-
|
|
84
78
|
function findContext(buildContext, previousContexts, currentContext, startTime) {
|
|
85
79
|
if (startTime === undefined) {
|
|
86
80
|
return currentContext ? buildContext() : undefined;
|
|
87
81
|
}
|
|
88
|
-
|
|
89
82
|
if (currentContext && startTime >= currentContext.startTime) {
|
|
90
83
|
return buildContext();
|
|
91
84
|
}
|
|
92
|
-
|
|
93
85
|
var flag = undefined;
|
|
94
86
|
each(previousContexts, function (previousContext) {
|
|
95
87
|
if (startTime > previousContext.endTime) {
|
|
96
88
|
return false;
|
|
97
89
|
}
|
|
98
|
-
|
|
99
90
|
if (startTime >= previousContext.startTime) {
|
|
100
91
|
flag = previousContext.context;
|
|
101
92
|
return false;
|
|
@@ -103,7 +94,6 @@ export function startParentContexts(lifeCycle) {
|
|
|
103
94
|
});
|
|
104
95
|
return flag;
|
|
105
96
|
}
|
|
106
|
-
|
|
107
97
|
var parentContexts = {
|
|
108
98
|
findView: function findView(startTime) {
|
|
109
99
|
return findContext(buildCurrentViewContext, previousViews, currentView, startTime);
|
|
@@ -10,7 +10,6 @@ export function startRequestCollection(lifeCycle, configuration) {
|
|
|
10
10
|
trackXhr(lifeCycle, configuration, tracer);
|
|
11
11
|
trackDownload(lifeCycle, configuration);
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
function parseHeader(header) {
|
|
15
14
|
// 大小写兼容
|
|
16
15
|
if (!isObject(header)) return header;
|
|
@@ -20,7 +19,6 @@ function parseHeader(header) {
|
|
|
20
19
|
});
|
|
21
20
|
return res;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
function getHeaderString(header) {
|
|
25
23
|
if (!isObject(header)) return header;
|
|
26
24
|
var headerStr = '';
|
|
@@ -29,7 +27,6 @@ function getHeaderString(header) {
|
|
|
29
27
|
});
|
|
30
28
|
return headerStr;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
30
|
export function trackXhr(lifeCycle, configuration, tracer) {
|
|
34
31
|
var xhrProxy = startXhrProxy(configuration);
|
|
35
32
|
xhrProxy.beforeSend(function (context) {
|
|
@@ -88,7 +85,6 @@ export function trackDownload(lifeCycle, configuration) {
|
|
|
88
85
|
});
|
|
89
86
|
return dwonloadProxy;
|
|
90
87
|
}
|
|
91
|
-
|
|
92
88
|
function getNextRequestIndex() {
|
|
93
89
|
var result = nextRequestIndex;
|
|
94
90
|
nextRequestIndex += 1;
|
|
@@ -8,7 +8,6 @@ export function startResourceCollection(lifeCycle, configuration) {
|
|
|
8
8
|
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processRequest(request));
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
function processRequest(request) {
|
|
13
12
|
var type = request.type;
|
|
14
13
|
var timing = request.performance;
|
|
@@ -37,14 +36,11 @@ function processRequest(request) {
|
|
|
37
36
|
rawRumEvent: resourceEvent
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
function computeRequestTracingInfo(request) {
|
|
42
40
|
var hasBeenTraced = request.traceId && request.spanId;
|
|
43
|
-
|
|
44
41
|
if (!hasBeenTraced) {
|
|
45
42
|
return undefined;
|
|
46
43
|
}
|
|
47
|
-
|
|
48
44
|
return {
|
|
49
45
|
_dd: {
|
|
50
46
|
spanId: request.spanId,
|
|
@@ -55,7 +51,6 @@ function computeRequestTracingInfo(request) {
|
|
|
55
51
|
}
|
|
56
52
|
};
|
|
57
53
|
}
|
|
58
|
-
|
|
59
54
|
function computePerformanceEntryMetrics(timing) {
|
|
60
55
|
return {
|
|
61
56
|
resource: extend2Lev({}, {
|