@cloudcare/rum-uniapp 2.2.10 → 2.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/core/configuration.js +2 -2
- package/cjs/core/dataMap.js +2 -0
- package/cjs/core/downloadProxy.js +55 -41
- package/cjs/core/xhrProxy.js +58 -53
- package/cjs/rumEventsCollection/app/index.js +12 -3
- package/cjs/rumEventsCollection/error/errorCollection.js +1 -0
- package/cjs/rumEventsCollection/resource/resourceCollection.js +1 -3
- package/esm/boot/buildEnv.js +1 -1
- package/esm/core/configuration.js +3 -3
- package/esm/core/dataMap.js +2 -0
- package/esm/core/downloadProxy.js +55 -41
- package/esm/core/xhrProxy.js +58 -53
- package/esm/rumEventsCollection/app/index.js +13 -4
- package/esm/rumEventsCollection/error/errorCollection.js +2 -1
- package/esm/rumEventsCollection/resource/resourceCollection.js +1 -3
- package/package.json +1 -1
package/cjs/boot/buildEnv.js
CHANGED
|
@@ -87,10 +87,10 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
87
87
|
if ('isVue2' in userConfiguration) {
|
|
88
88
|
transportConfiguration.isVue2 = userConfiguration.isVue2;
|
|
89
89
|
}
|
|
90
|
-
if ('isIntakeUrl' in userConfiguration && (0, _utils.isFunction)(userConfiguration.isIntakeUrl)
|
|
90
|
+
if ('isIntakeUrl' in userConfiguration && (0, _utils.isFunction)(userConfiguration.isIntakeUrl)) {
|
|
91
91
|
transportConfiguration.isIntakeUrl = userConfiguration.isIntakeUrl;
|
|
92
92
|
}
|
|
93
|
-
return (0, _utils.extend2Lev)(DEFAULT_CONFIGURATION, transportConfiguration);
|
|
93
|
+
return (0, _utils.extend2Lev)({}, DEFAULT_CONFIGURATION, transportConfiguration);
|
|
94
94
|
}
|
|
95
95
|
function hasTraceType(traceType) {
|
|
96
96
|
if (traceType && (0, _utils.values)(_enums.TraceType).indexOf(traceType) > -1) return true;
|
package/cjs/core/dataMap.js
CHANGED
|
@@ -72,6 +72,7 @@ var dataMap = exports.dataMap = {
|
|
|
72
72
|
resource: {
|
|
73
73
|
type: _enums.RumEventType.RESOURCE,
|
|
74
74
|
tags: {
|
|
75
|
+
resource_id: 'resource.id',
|
|
75
76
|
trace_id: '_dd.trace_id',
|
|
76
77
|
span_id: '_dd.span_id',
|
|
77
78
|
resource_type: 'resource.type',
|
|
@@ -99,6 +100,7 @@ var dataMap = exports.dataMap = {
|
|
|
99
100
|
error: {
|
|
100
101
|
type: _enums.RumEventType.ERROR,
|
|
101
102
|
tags: {
|
|
103
|
+
error_id: 'error.id',
|
|
102
104
|
trace_id: '_dd.trace_id',
|
|
103
105
|
span_id: '_dd.span_id',
|
|
104
106
|
error_source: 'error.source',
|
|
@@ -39,37 +39,24 @@ function proxyDownload(userConfiguration) {
|
|
|
39
39
|
originalDownloadRequest = _sdk.sdk.downloadFile;
|
|
40
40
|
_sdk.sdk.downloadFile = function () {
|
|
41
41
|
var _this = this;
|
|
42
|
+
var requestOptions = arguments[0];
|
|
42
43
|
var dataflux_xhr = {
|
|
43
44
|
method: 'GET',
|
|
44
45
|
startTime: 0,
|
|
45
|
-
url:
|
|
46
|
+
url: requestOptions.url,
|
|
46
47
|
type: _enums.RequestType.DOWNLOAD,
|
|
47
48
|
responseType: 'file'
|
|
48
49
|
};
|
|
49
50
|
dataflux_xhr.startTime = (0, _utils.now)();
|
|
50
|
-
var originalSuccess =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
reportXhr(arguments[0]);
|
|
54
|
-
if (originalSuccess) {
|
|
55
|
-
originalSuccess.apply(_this, arguments);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
var originalFail = arguments[0].fail;
|
|
60
|
-
if (typeof originalFail === 'function') {
|
|
61
|
-
arguments[0].fail = function () {
|
|
62
|
-
reportXhr(arguments[0]);
|
|
63
|
-
if (originalFail) {
|
|
64
|
-
originalFail.apply(_this, arguments);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
51
|
+
var originalSuccess = requestOptions.success;
|
|
52
|
+
var originalFail = requestOptions.fail;
|
|
53
|
+
var originalComplete = requestOptions.complete;
|
|
68
54
|
var hasBeenReported = false;
|
|
69
55
|
var reportXhr = function reportXhr(res) {
|
|
70
56
|
if (hasBeenReported) {
|
|
71
57
|
return;
|
|
72
58
|
}
|
|
59
|
+
res = res || {};
|
|
73
60
|
hasBeenReported = true;
|
|
74
61
|
dataflux_xhr.duration = (0, _utils.now)() - dataflux_xhr.startTime;
|
|
75
62
|
dataflux_xhr.response = JSON.stringify({
|
|
@@ -80,39 +67,66 @@ function proxyDownload(userConfiguration) {
|
|
|
80
67
|
dataflux_xhr.profile = res.profile;
|
|
81
68
|
dataflux_xhr.status = res.statusCode || res.status || 0;
|
|
82
69
|
onRequestCompleteCallbacks.forEach(function (callback) {
|
|
83
|
-
|
|
70
|
+
try {
|
|
71
|
+
callback(dataflux_xhr);
|
|
72
|
+
} catch (e) {}
|
|
84
73
|
});
|
|
85
74
|
};
|
|
75
|
+
var safeReportXhr = function safeReportXhr(res) {
|
|
76
|
+
try {
|
|
77
|
+
reportXhr(res);
|
|
78
|
+
} catch (e) {}
|
|
79
|
+
};
|
|
80
|
+
// Only wrap callbacks supplied by the caller. Adding new callbacks can change
|
|
81
|
+
// uni-app request behavior, especially the Promise result shape in Vue2.
|
|
82
|
+
if (typeof originalSuccess === 'function') {
|
|
83
|
+
requestOptions.success = function () {
|
|
84
|
+
safeReportXhr(arguments[0]);
|
|
85
|
+
originalSuccess.apply(_this, arguments);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (typeof originalFail === 'function') {
|
|
89
|
+
requestOptions.fail = function () {
|
|
90
|
+
safeReportXhr(arguments[0]);
|
|
91
|
+
originalFail.apply(_this, arguments);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (typeof originalComplete === 'function') {
|
|
95
|
+
requestOptions.complete = function () {
|
|
96
|
+
safeReportXhr(arguments[0]);
|
|
97
|
+
originalComplete.apply(_this, arguments);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
86
100
|
beforeSendCallbacks.forEach(function (callback) {
|
|
87
|
-
|
|
101
|
+
try {
|
|
102
|
+
callback(dataflux_xhr);
|
|
103
|
+
} catch (e) {}
|
|
88
104
|
});
|
|
89
105
|
var result = originalDownloadRequest.apply(this, arguments);
|
|
90
106
|
// 判断结果是否为promise
|
|
91
107
|
var isPromise = function isPromise(obj) {
|
|
92
108
|
return !!obj && (_typeof(obj) === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
93
109
|
};
|
|
94
|
-
if (isPromise(result)
|
|
95
|
-
|
|
96
|
-
return result.then(function (res) {
|
|
97
|
-
if (res[0]) {
|
|
98
|
-
reportXhr(res[0]);
|
|
99
|
-
} else {
|
|
100
|
-
reportXhr(res[1]);
|
|
101
|
-
}
|
|
102
|
-
return res;
|
|
103
|
-
});
|
|
104
|
-
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
105
|
-
return new Promise(function (resolve, reject) {
|
|
110
|
+
if (isPromise(result)) {
|
|
111
|
+
try {
|
|
106
112
|
result.then(function (res) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
if (userConfiguration.isVue2) {
|
|
114
|
+
// vue2 版本,success, fail 都在then返回
|
|
115
|
+
if (res && res[0]) {
|
|
116
|
+
safeReportXhr(res[0]);
|
|
117
|
+
} else if (res && res[1]) {
|
|
118
|
+
safeReportXhr(res[1]);
|
|
119
|
+
} else {
|
|
120
|
+
safeReportXhr(res);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
safeReportXhr(res);
|
|
124
|
+
}
|
|
125
|
+
}, function (err) {
|
|
126
|
+
safeReportXhr(err);
|
|
112
127
|
});
|
|
113
|
-
})
|
|
114
|
-
} else {
|
|
115
|
-
return result;
|
|
128
|
+
} catch (e) {}
|
|
116
129
|
}
|
|
130
|
+
return result;
|
|
117
131
|
};
|
|
118
132
|
}
|
package/cjs/core/xhrProxy.js
CHANGED
|
@@ -39,47 +39,25 @@ function proxyXhr(userConfiguration) {
|
|
|
39
39
|
originalXhrRequest = _sdk.sdk.request;
|
|
40
40
|
_sdk.sdk.request = function () {
|
|
41
41
|
var _this = this;
|
|
42
|
+
var requestOptions = arguments[0];
|
|
42
43
|
var dataflux_xhr = {
|
|
43
|
-
method:
|
|
44
|
+
method: requestOptions.method || "GET",
|
|
44
45
|
startTime: 0,
|
|
45
|
-
url:
|
|
46
|
+
url: requestOptions.url,
|
|
46
47
|
type: _enums.RequestType.XHR,
|
|
47
|
-
responseType:
|
|
48
|
-
option:
|
|
48
|
+
responseType: requestOptions.responseType || "text",
|
|
49
|
+
option: requestOptions
|
|
49
50
|
};
|
|
50
51
|
dataflux_xhr.startTime = (0, _utils.now)();
|
|
51
|
-
var originalSuccess =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
reportXhr(arguments[0]);
|
|
55
|
-
if (typeof originalSuccess === "function") {
|
|
56
|
-
originalSuccess.apply(_this, arguments);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
var originalFail = arguments[0].fail;
|
|
61
|
-
if (originalFail) {
|
|
62
|
-
arguments[0].fail = function () {
|
|
63
|
-
reportXhr(arguments[0]);
|
|
64
|
-
if (typeof originalFail === "function") {
|
|
65
|
-
originalFail.apply(_this, arguments);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
var originalComplete = arguments[0].complete;
|
|
70
|
-
if (originalComplete) {
|
|
71
|
-
arguments[0].complete = function () {
|
|
72
|
-
reportXhr(arguments[0]);
|
|
73
|
-
if (typeof originalComplete === "function") {
|
|
74
|
-
originalComplete.apply(_this, arguments);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
52
|
+
var originalSuccess = requestOptions.success;
|
|
53
|
+
var originalFail = requestOptions.fail;
|
|
54
|
+
var originalComplete = requestOptions.complete;
|
|
78
55
|
var hasBeenReported = false;
|
|
79
56
|
var reportXhr = function reportXhr(res) {
|
|
80
57
|
if (hasBeenReported) {
|
|
81
58
|
return;
|
|
82
59
|
}
|
|
60
|
+
res = res || {};
|
|
83
61
|
hasBeenReported = true;
|
|
84
62
|
dataflux_xhr.duration = (0, _utils.now)() - dataflux_xhr.startTime;
|
|
85
63
|
dataflux_xhr.response = res.data && JSON.stringify(res.data) || {};
|
|
@@ -87,39 +65,66 @@ function proxyXhr(userConfiguration) {
|
|
|
87
65
|
dataflux_xhr.profile = res.profile;
|
|
88
66
|
dataflux_xhr.status = res.statusCode || res.status || 0;
|
|
89
67
|
onRequestCompleteCallbacks.forEach(function (callback) {
|
|
90
|
-
|
|
68
|
+
try {
|
|
69
|
+
callback(dataflux_xhr);
|
|
70
|
+
} catch (e) {}
|
|
91
71
|
});
|
|
92
72
|
};
|
|
73
|
+
var safeReportXhr = function safeReportXhr(res) {
|
|
74
|
+
try {
|
|
75
|
+
reportXhr(res);
|
|
76
|
+
} catch (e) {}
|
|
77
|
+
};
|
|
78
|
+
// Only wrap callbacks supplied by the caller. Adding new callbacks can change
|
|
79
|
+
// uni-app request behavior, especially the Promise result shape in Vue2.
|
|
80
|
+
if (typeof originalSuccess === "function") {
|
|
81
|
+
requestOptions.success = function () {
|
|
82
|
+
safeReportXhr(arguments[0]);
|
|
83
|
+
originalSuccess.apply(_this, arguments);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (typeof originalFail === "function") {
|
|
87
|
+
requestOptions.fail = function () {
|
|
88
|
+
safeReportXhr(arguments[0]);
|
|
89
|
+
originalFail.apply(_this, arguments);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (typeof originalComplete === "function") {
|
|
93
|
+
requestOptions.complete = function () {
|
|
94
|
+
safeReportXhr(arguments[0]);
|
|
95
|
+
originalComplete.apply(_this, arguments);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
93
98
|
beforeSendCallbacks.forEach(function (callback) {
|
|
94
|
-
|
|
99
|
+
try {
|
|
100
|
+
callback(dataflux_xhr);
|
|
101
|
+
} catch (e) {}
|
|
95
102
|
});
|
|
96
103
|
var result = originalXhrRequest.call(this, dataflux_xhr.option);
|
|
97
104
|
// 判断结果是否为promise
|
|
98
105
|
var isPromise = function isPromise(obj) {
|
|
99
106
|
return !!obj && (_typeof(obj) === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
100
107
|
};
|
|
101
|
-
if (isPromise(result)
|
|
102
|
-
|
|
103
|
-
return result.then(function (res) {
|
|
104
|
-
if (res[0]) {
|
|
105
|
-
reportXhr(res[0]);
|
|
106
|
-
} else {
|
|
107
|
-
reportXhr(res[1]);
|
|
108
|
-
}
|
|
109
|
-
return res;
|
|
110
|
-
});
|
|
111
|
-
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
112
|
-
return new Promise(function (resolve, reject) {
|
|
108
|
+
if (isPromise(result)) {
|
|
109
|
+
try {
|
|
113
110
|
result.then(function (res) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
if (userConfiguration.isVue2) {
|
|
112
|
+
// vue2 版本,success, fail 都在then返回
|
|
113
|
+
if (res && res[0]) {
|
|
114
|
+
safeReportXhr(res[0]);
|
|
115
|
+
} else if (res && res[1]) {
|
|
116
|
+
safeReportXhr(res[1]);
|
|
117
|
+
} else {
|
|
118
|
+
safeReportXhr(res);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
safeReportXhr(res);
|
|
122
|
+
}
|
|
123
|
+
}, function (err) {
|
|
124
|
+
safeReportXhr(err);
|
|
119
125
|
});
|
|
120
|
-
})
|
|
121
|
-
} else {
|
|
122
|
-
return result;
|
|
126
|
+
} catch (e) {}
|
|
123
127
|
}
|
|
128
|
+
return result;
|
|
124
129
|
};
|
|
125
130
|
}
|
|
@@ -59,7 +59,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
59
59
|
});
|
|
60
60
|
if (typeof launchEntity !== 'undefined') {
|
|
61
61
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.APP_UPDATE, {
|
|
62
|
-
startTime:
|
|
62
|
+
startTime: computeEntryStartTime(startTime, launchEntity),
|
|
63
63
|
name: '启动',
|
|
64
64
|
type: 'launch',
|
|
65
65
|
id: (0, _utils.UUID)(),
|
|
@@ -71,7 +71,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
71
71
|
});
|
|
72
72
|
if (typeof scriptentity !== 'undefined') {
|
|
73
73
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.APP_UPDATE, {
|
|
74
|
-
startTime:
|
|
74
|
+
startTime: computeEntryStartTime(startTime, scriptentity),
|
|
75
75
|
name: '脚本注入',
|
|
76
76
|
type: 'script_insert',
|
|
77
77
|
id: (0, _utils.UUID)(),
|
|
@@ -88,7 +88,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
88
88
|
codeDownloadDuration = launchEntity.duration - firstEntity.duration - scriptentity.duration;
|
|
89
89
|
// 资源下载耗时
|
|
90
90
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.APP_UPDATE, {
|
|
91
|
-
startTime:
|
|
91
|
+
startTime: computeEntryStartTime(startTime, launchEntity),
|
|
92
92
|
name: '小程序包下载',
|
|
93
93
|
type: 'package_download',
|
|
94
94
|
id: (0, _utils.UUID)(),
|
|
@@ -101,4 +101,13 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
101
101
|
return {
|
|
102
102
|
stop: subscribe.unsubscribe
|
|
103
103
|
};
|
|
104
|
+
}
|
|
105
|
+
function computeEntryStartTime(appStartTime, entry) {
|
|
106
|
+
if (!(0, _utils.isNumber)(appStartTime)) {
|
|
107
|
+
return (0, _utils.now)();
|
|
108
|
+
}
|
|
109
|
+
if (!entry || !(0, _utils.isNumber)(entry.startTime)) {
|
|
110
|
+
return appStartTime;
|
|
111
|
+
}
|
|
112
|
+
return appStartTime + entry.startTime;
|
|
104
113
|
}
|
|
@@ -24,6 +24,7 @@ function processRequest(request) {
|
|
|
24
24
|
var resourceEvent = (0, _utils.extend2Lev)({
|
|
25
25
|
date: startTime,
|
|
26
26
|
resource: {
|
|
27
|
+
id: (0, _utils.UUID)(),
|
|
27
28
|
type: type,
|
|
28
29
|
duration: (0, _utils.msToNs)(request.duration),
|
|
29
30
|
method: request.method,
|
|
@@ -51,9 +52,6 @@ function computeRequestTracingInfo(request) {
|
|
|
51
52
|
_dd: {
|
|
52
53
|
spanId: request.spanId,
|
|
53
54
|
traceId: request.traceId
|
|
54
|
-
},
|
|
55
|
-
resource: {
|
|
56
|
-
id: (0, _utils.UUID)()
|
|
57
55
|
}
|
|
58
56
|
};
|
|
59
57
|
}
|
package/esm/boot/buildEnv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extend2Lev, urlParse, values, isFunction
|
|
1
|
+
import { extend2Lev, urlParse, values, isFunction } from '../helper/utils';
|
|
2
2
|
import { ONE_KILO_BYTE, ONE_SECOND, TraceType } from '../helper/enums';
|
|
3
3
|
import { catchUserErrors } from '../helper/catchUserErrors';
|
|
4
4
|
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
@@ -79,10 +79,10 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
79
79
|
if ('isVue2' in userConfiguration) {
|
|
80
80
|
transportConfiguration.isVue2 = userConfiguration.isVue2;
|
|
81
81
|
}
|
|
82
|
-
if ('isIntakeUrl' in userConfiguration && isFunction(userConfiguration.isIntakeUrl)
|
|
82
|
+
if ('isIntakeUrl' in userConfiguration && isFunction(userConfiguration.isIntakeUrl)) {
|
|
83
83
|
transportConfiguration.isIntakeUrl = userConfiguration.isIntakeUrl;
|
|
84
84
|
}
|
|
85
|
-
return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
|
|
85
|
+
return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
|
|
86
86
|
}
|
|
87
87
|
function hasTraceType(traceType) {
|
|
88
88
|
if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
|
package/esm/core/dataMap.js
CHANGED
|
@@ -66,6 +66,7 @@ export var dataMap = {
|
|
|
66
66
|
resource: {
|
|
67
67
|
type: RumEventType.RESOURCE,
|
|
68
68
|
tags: {
|
|
69
|
+
resource_id: 'resource.id',
|
|
69
70
|
trace_id: '_dd.trace_id',
|
|
70
71
|
span_id: '_dd.span_id',
|
|
71
72
|
resource_type: 'resource.type',
|
|
@@ -93,6 +94,7 @@ export var dataMap = {
|
|
|
93
94
|
error: {
|
|
94
95
|
type: RumEventType.ERROR,
|
|
95
96
|
tags: {
|
|
97
|
+
error_id: 'error.id',
|
|
96
98
|
trace_id: '_dd.trace_id',
|
|
97
99
|
span_id: '_dd.span_id',
|
|
98
100
|
error_source: 'error.source',
|
|
@@ -31,37 +31,24 @@ function proxyDownload(userConfiguration) {
|
|
|
31
31
|
originalDownloadRequest = sdk.downloadFile;
|
|
32
32
|
sdk.downloadFile = function () {
|
|
33
33
|
var _this = this;
|
|
34
|
+
var requestOptions = arguments[0];
|
|
34
35
|
var dataflux_xhr = {
|
|
35
36
|
method: 'GET',
|
|
36
37
|
startTime: 0,
|
|
37
|
-
url:
|
|
38
|
+
url: requestOptions.url,
|
|
38
39
|
type: RequestType.DOWNLOAD,
|
|
39
40
|
responseType: 'file'
|
|
40
41
|
};
|
|
41
42
|
dataflux_xhr.startTime = now();
|
|
42
|
-
var originalSuccess =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
reportXhr(arguments[0]);
|
|
46
|
-
if (originalSuccess) {
|
|
47
|
-
originalSuccess.apply(_this, arguments);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
var originalFail = arguments[0].fail;
|
|
52
|
-
if (typeof originalFail === 'function') {
|
|
53
|
-
arguments[0].fail = function () {
|
|
54
|
-
reportXhr(arguments[0]);
|
|
55
|
-
if (originalFail) {
|
|
56
|
-
originalFail.apply(_this, arguments);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
43
|
+
var originalSuccess = requestOptions.success;
|
|
44
|
+
var originalFail = requestOptions.fail;
|
|
45
|
+
var originalComplete = requestOptions.complete;
|
|
60
46
|
var hasBeenReported = false;
|
|
61
47
|
var reportXhr = function reportXhr(res) {
|
|
62
48
|
if (hasBeenReported) {
|
|
63
49
|
return;
|
|
64
50
|
}
|
|
51
|
+
res = res || {};
|
|
65
52
|
hasBeenReported = true;
|
|
66
53
|
dataflux_xhr.duration = now() - dataflux_xhr.startTime;
|
|
67
54
|
dataflux_xhr.response = JSON.stringify({
|
|
@@ -72,39 +59,66 @@ function proxyDownload(userConfiguration) {
|
|
|
72
59
|
dataflux_xhr.profile = res.profile;
|
|
73
60
|
dataflux_xhr.status = res.statusCode || res.status || 0;
|
|
74
61
|
onRequestCompleteCallbacks.forEach(function (callback) {
|
|
75
|
-
|
|
62
|
+
try {
|
|
63
|
+
callback(dataflux_xhr);
|
|
64
|
+
} catch (e) {}
|
|
76
65
|
});
|
|
77
66
|
};
|
|
67
|
+
var safeReportXhr = function safeReportXhr(res) {
|
|
68
|
+
try {
|
|
69
|
+
reportXhr(res);
|
|
70
|
+
} catch (e) {}
|
|
71
|
+
};
|
|
72
|
+
// Only wrap callbacks supplied by the caller. Adding new callbacks can change
|
|
73
|
+
// uni-app request behavior, especially the Promise result shape in Vue2.
|
|
74
|
+
if (typeof originalSuccess === 'function') {
|
|
75
|
+
requestOptions.success = function () {
|
|
76
|
+
safeReportXhr(arguments[0]);
|
|
77
|
+
originalSuccess.apply(_this, arguments);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (typeof originalFail === 'function') {
|
|
81
|
+
requestOptions.fail = function () {
|
|
82
|
+
safeReportXhr(arguments[0]);
|
|
83
|
+
originalFail.apply(_this, arguments);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (typeof originalComplete === 'function') {
|
|
87
|
+
requestOptions.complete = function () {
|
|
88
|
+
safeReportXhr(arguments[0]);
|
|
89
|
+
originalComplete.apply(_this, arguments);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
78
92
|
beforeSendCallbacks.forEach(function (callback) {
|
|
79
|
-
|
|
93
|
+
try {
|
|
94
|
+
callback(dataflux_xhr);
|
|
95
|
+
} catch (e) {}
|
|
80
96
|
});
|
|
81
97
|
var result = originalDownloadRequest.apply(this, arguments);
|
|
82
98
|
// 判断结果是否为promise
|
|
83
99
|
var isPromise = function isPromise(obj) {
|
|
84
100
|
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
85
101
|
};
|
|
86
|
-
if (isPromise(result)
|
|
87
|
-
|
|
88
|
-
return result.then(function (res) {
|
|
89
|
-
if (res[0]) {
|
|
90
|
-
reportXhr(res[0]);
|
|
91
|
-
} else {
|
|
92
|
-
reportXhr(res[1]);
|
|
93
|
-
}
|
|
94
|
-
return res;
|
|
95
|
-
});
|
|
96
|
-
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
97
|
-
return new Promise(function (resolve, reject) {
|
|
102
|
+
if (isPromise(result)) {
|
|
103
|
+
try {
|
|
98
104
|
result.then(function (res) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
if (userConfiguration.isVue2) {
|
|
106
|
+
// vue2 版本,success, fail 都在then返回
|
|
107
|
+
if (res && res[0]) {
|
|
108
|
+
safeReportXhr(res[0]);
|
|
109
|
+
} else if (res && res[1]) {
|
|
110
|
+
safeReportXhr(res[1]);
|
|
111
|
+
} else {
|
|
112
|
+
safeReportXhr(res);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
safeReportXhr(res);
|
|
116
|
+
}
|
|
117
|
+
}, function (err) {
|
|
118
|
+
safeReportXhr(err);
|
|
104
119
|
});
|
|
105
|
-
})
|
|
106
|
-
} else {
|
|
107
|
-
return result;
|
|
120
|
+
} catch (e) {}
|
|
108
121
|
}
|
|
122
|
+
return result;
|
|
109
123
|
};
|
|
110
124
|
}
|
package/esm/core/xhrProxy.js
CHANGED
|
@@ -31,47 +31,25 @@ function proxyXhr(userConfiguration) {
|
|
|
31
31
|
originalXhrRequest = sdk.request;
|
|
32
32
|
sdk.request = function () {
|
|
33
33
|
var _this = this;
|
|
34
|
+
var requestOptions = arguments[0];
|
|
34
35
|
var dataflux_xhr = {
|
|
35
|
-
method:
|
|
36
|
+
method: requestOptions.method || "GET",
|
|
36
37
|
startTime: 0,
|
|
37
|
-
url:
|
|
38
|
+
url: requestOptions.url,
|
|
38
39
|
type: RequestType.XHR,
|
|
39
|
-
responseType:
|
|
40
|
-
option:
|
|
40
|
+
responseType: requestOptions.responseType || "text",
|
|
41
|
+
option: requestOptions
|
|
41
42
|
};
|
|
42
43
|
dataflux_xhr.startTime = now();
|
|
43
|
-
var originalSuccess =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
reportXhr(arguments[0]);
|
|
47
|
-
if (typeof originalSuccess === "function") {
|
|
48
|
-
originalSuccess.apply(_this, arguments);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
var originalFail = arguments[0].fail;
|
|
53
|
-
if (originalFail) {
|
|
54
|
-
arguments[0].fail = function () {
|
|
55
|
-
reportXhr(arguments[0]);
|
|
56
|
-
if (typeof originalFail === "function") {
|
|
57
|
-
originalFail.apply(_this, arguments);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
var originalComplete = arguments[0].complete;
|
|
62
|
-
if (originalComplete) {
|
|
63
|
-
arguments[0].complete = function () {
|
|
64
|
-
reportXhr(arguments[0]);
|
|
65
|
-
if (typeof originalComplete === "function") {
|
|
66
|
-
originalComplete.apply(_this, arguments);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
44
|
+
var originalSuccess = requestOptions.success;
|
|
45
|
+
var originalFail = requestOptions.fail;
|
|
46
|
+
var originalComplete = requestOptions.complete;
|
|
70
47
|
var hasBeenReported = false;
|
|
71
48
|
var reportXhr = function reportXhr(res) {
|
|
72
49
|
if (hasBeenReported) {
|
|
73
50
|
return;
|
|
74
51
|
}
|
|
52
|
+
res = res || {};
|
|
75
53
|
hasBeenReported = true;
|
|
76
54
|
dataflux_xhr.duration = now() - dataflux_xhr.startTime;
|
|
77
55
|
dataflux_xhr.response = res.data && JSON.stringify(res.data) || {};
|
|
@@ -79,39 +57,66 @@ function proxyXhr(userConfiguration) {
|
|
|
79
57
|
dataflux_xhr.profile = res.profile;
|
|
80
58
|
dataflux_xhr.status = res.statusCode || res.status || 0;
|
|
81
59
|
onRequestCompleteCallbacks.forEach(function (callback) {
|
|
82
|
-
|
|
60
|
+
try {
|
|
61
|
+
callback(dataflux_xhr);
|
|
62
|
+
} catch (e) {}
|
|
83
63
|
});
|
|
84
64
|
};
|
|
65
|
+
var safeReportXhr = function safeReportXhr(res) {
|
|
66
|
+
try {
|
|
67
|
+
reportXhr(res);
|
|
68
|
+
} catch (e) {}
|
|
69
|
+
};
|
|
70
|
+
// Only wrap callbacks supplied by the caller. Adding new callbacks can change
|
|
71
|
+
// uni-app request behavior, especially the Promise result shape in Vue2.
|
|
72
|
+
if (typeof originalSuccess === "function") {
|
|
73
|
+
requestOptions.success = function () {
|
|
74
|
+
safeReportXhr(arguments[0]);
|
|
75
|
+
originalSuccess.apply(_this, arguments);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (typeof originalFail === "function") {
|
|
79
|
+
requestOptions.fail = function () {
|
|
80
|
+
safeReportXhr(arguments[0]);
|
|
81
|
+
originalFail.apply(_this, arguments);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (typeof originalComplete === "function") {
|
|
85
|
+
requestOptions.complete = function () {
|
|
86
|
+
safeReportXhr(arguments[0]);
|
|
87
|
+
originalComplete.apply(_this, arguments);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
85
90
|
beforeSendCallbacks.forEach(function (callback) {
|
|
86
|
-
|
|
91
|
+
try {
|
|
92
|
+
callback(dataflux_xhr);
|
|
93
|
+
} catch (e) {}
|
|
87
94
|
});
|
|
88
95
|
var result = originalXhrRequest.call(this, dataflux_xhr.option);
|
|
89
96
|
// 判断结果是否为promise
|
|
90
97
|
var isPromise = function isPromise(obj) {
|
|
91
98
|
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
92
99
|
};
|
|
93
|
-
if (isPromise(result)
|
|
94
|
-
|
|
95
|
-
return result.then(function (res) {
|
|
96
|
-
if (res[0]) {
|
|
97
|
-
reportXhr(res[0]);
|
|
98
|
-
} else {
|
|
99
|
-
reportXhr(res[1]);
|
|
100
|
-
}
|
|
101
|
-
return res;
|
|
102
|
-
});
|
|
103
|
-
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
104
|
-
return new Promise(function (resolve, reject) {
|
|
100
|
+
if (isPromise(result)) {
|
|
101
|
+
try {
|
|
105
102
|
result.then(function (res) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
if (userConfiguration.isVue2) {
|
|
104
|
+
// vue2 版本,success, fail 都在then返回
|
|
105
|
+
if (res && res[0]) {
|
|
106
|
+
safeReportXhr(res[0]);
|
|
107
|
+
} else if (res && res[1]) {
|
|
108
|
+
safeReportXhr(res[1]);
|
|
109
|
+
} else {
|
|
110
|
+
safeReportXhr(res);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
safeReportXhr(res);
|
|
114
|
+
}
|
|
115
|
+
}, function (err) {
|
|
116
|
+
safeReportXhr(err);
|
|
111
117
|
});
|
|
112
|
-
})
|
|
113
|
-
} else {
|
|
114
|
-
return result;
|
|
118
|
+
} catch (e) {}
|
|
115
119
|
}
|
|
120
|
+
return result;
|
|
116
121
|
};
|
|
117
122
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { now, areInOrder, UUID } from '../../helper/utils';
|
|
1
|
+
import { now, areInOrder, UUID, isNumber } from '../../helper/utils';
|
|
2
2
|
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
3
3
|
|
|
4
4
|
// 劫持原小程序App方法
|
|
@@ -50,7 +50,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
50
50
|
var launchEntity = entitys.find(entity => entity.entryType === 'navigation' && entity.navigationType === 'appLaunch');
|
|
51
51
|
if (typeof launchEntity !== 'undefined') {
|
|
52
52
|
lifeCycle.notify(LifeCycleEventType.APP_UPDATE, {
|
|
53
|
-
startTime:
|
|
53
|
+
startTime: computeEntryStartTime(startTime, launchEntity),
|
|
54
54
|
name: '启动',
|
|
55
55
|
type: 'launch',
|
|
56
56
|
id: UUID(),
|
|
@@ -60,7 +60,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
60
60
|
var scriptentity = entitys.find(entity => entity.entryType === 'script' && entity.name === 'evaluateScript');
|
|
61
61
|
if (typeof scriptentity !== 'undefined') {
|
|
62
62
|
lifeCycle.notify(LifeCycleEventType.APP_UPDATE, {
|
|
63
|
-
startTime:
|
|
63
|
+
startTime: computeEntryStartTime(startTime, scriptentity),
|
|
64
64
|
name: '脚本注入',
|
|
65
65
|
type: 'script_insert',
|
|
66
66
|
id: UUID(),
|
|
@@ -75,7 +75,7 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
75
75
|
codeDownloadDuration = launchEntity.duration - firstEntity.duration - scriptentity.duration;
|
|
76
76
|
// 资源下载耗时
|
|
77
77
|
lifeCycle.notify(LifeCycleEventType.APP_UPDATE, {
|
|
78
|
-
startTime:
|
|
78
|
+
startTime: computeEntryStartTime(startTime, launchEntity),
|
|
79
79
|
name: '小程序包下载',
|
|
80
80
|
type: 'package_download',
|
|
81
81
|
id: UUID(),
|
|
@@ -88,4 +88,13 @@ function startPerformanceObservable(lifeCycle) {
|
|
|
88
88
|
return {
|
|
89
89
|
stop: subscribe.unsubscribe
|
|
90
90
|
};
|
|
91
|
+
}
|
|
92
|
+
function computeEntryStartTime(appStartTime, entry) {
|
|
93
|
+
if (!isNumber(appStartTime)) {
|
|
94
|
+
return now();
|
|
95
|
+
}
|
|
96
|
+
if (!entry || !isNumber(entry.startTime)) {
|
|
97
|
+
return appStartTime;
|
|
98
|
+
}
|
|
99
|
+
return appStartTime + entry.startTime;
|
|
91
100
|
}
|
|
@@ -2,7 +2,7 @@ import { startAutomaticErrorCollection } from '../../core/errorCollection';
|
|
|
2
2
|
import { RumEventType } from '../../helper/enums';
|
|
3
3
|
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
4
4
|
import { ErrorSource, formatUnknownError } from '../../core/errorTools';
|
|
5
|
-
import { urlParse, replaceNumberCharByPath, getStatusGroup, extend2Lev, extend } from '../../helper/utils';
|
|
5
|
+
import { urlParse, replaceNumberCharByPath, getStatusGroup, extend2Lev, extend, UUID } from '../../helper/utils';
|
|
6
6
|
import { computeStackTrace } from '../../helper/tracekit';
|
|
7
7
|
export function startErrorCollection(lifeCycle, configuration) {
|
|
8
8
|
startAutomaticErrorCollection(configuration).subscribe(function (error) {
|
|
@@ -53,6 +53,7 @@ function processError(error) {
|
|
|
53
53
|
var rawRumEvent = extend2Lev({
|
|
54
54
|
date: error.startTime,
|
|
55
55
|
error: {
|
|
56
|
+
id: UUID(),
|
|
56
57
|
message: error.message,
|
|
57
58
|
resource: resource,
|
|
58
59
|
source: error.source,
|
|
@@ -18,6 +18,7 @@ function processRequest(request) {
|
|
|
18
18
|
var resourceEvent = extend2Lev({
|
|
19
19
|
date: startTime,
|
|
20
20
|
resource: {
|
|
21
|
+
id: UUID(),
|
|
21
22
|
type: type,
|
|
22
23
|
duration: msToNs(request.duration),
|
|
23
24
|
method: request.method,
|
|
@@ -45,9 +46,6 @@ function computeRequestTracingInfo(request) {
|
|
|
45
46
|
_dd: {
|
|
46
47
|
spanId: request.spanId,
|
|
47
48
|
traceId: request.traceId
|
|
48
|
-
},
|
|
49
|
-
resource: {
|
|
50
|
-
id: UUID()
|
|
51
49
|
}
|
|
52
50
|
};
|
|
53
51
|
}
|