@cloudcare/rum-uniapp 2.1.6 → 2.1.9
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 -0
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.entry.js +3 -1
- package/cjs/core/configuration.js +8 -2
- package/cjs/core/dataMap.js +3 -0
- package/cjs/core/downloadProxy.js +51 -16
- package/cjs/core/errorCollection.js +5 -3
- package/cjs/core/xhrProxy.js +51 -16
- package/cjs/rumEventsCollection/assembly.js +2 -1
- package/cjs/rumEventsCollection/error/errorCollection.js +19 -2
- package/cjs/rumEventsCollection/requestCollection.js +2 -2
- package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +4 -2
- package/esm/core/configuration.js +8 -2
- package/esm/core/dataMap.js +3 -0
- package/esm/core/downloadProxy.js +49 -16
- package/esm/core/errorCollection.js +5 -3
- package/esm/core/xhrProxy.js +49 -16
- package/esm/rumEventsCollection/assembly.js +2 -1
- package/esm/rumEventsCollection/error/errorCollection.js +20 -3
- package/esm/rumEventsCollection/requestCollection.js +2 -2
- package/esm/rumEventsCollection/tracing/ddtraceTracer.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ datafluxRum.init({
|
|
|
42
42
|
| `applicationId` | String | 是 | | 从 dataflux 创建的应用 ID |
|
|
43
43
|
| `datakitOrigin` | String | 是 | | datakit 数据上报 Origin;`注意:需要在小程序管理后台加上request白名单` |
|
|
44
44
|
| `env` | String | 否 | | 小程序 应用当前环境, 如 prod:线上环境;gray:灰度环境;pre:预发布环境 common:日常环境;local:本地环境; |
|
|
45
|
+
| `service` | String | 否 | | 小程序应用 服务名称,可 用于 apm 关联 tag |
|
|
45
46
|
| `version` | String | 否 | | 小程序 应用的版本号 |
|
|
46
47
|
| `sampleRate` | Number | 否 | `100` | 指标数据收集百分比: `100`表示全收集,`0`表示不收集 |
|
|
47
48
|
| `traceType` $\color{#FF0000}{新增}$ | Enum | 否 | `ddtrace` | 与 APM 采集工具连接的请求header类型,目前兼容的类型包括:`ddtrace`、`zipkin`、`skywalking_v3`、`jaeger`、`zipkin_single_header`、`w3c_traceparent`。*注: opentelemetry 支持 `zipkin_single_header`,`w3c_traceparent`,`zipkin`三种类型* |
|
package/cjs/boot/buildEnv.js
CHANGED
package/cjs/boot/rum.entry.js
CHANGED
|
@@ -46,7 +46,9 @@ var makeRum = function makeRum(startRumImpl) {
|
|
|
46
46
|
isAlreadyInitialized = true;
|
|
47
47
|
},
|
|
48
48
|
initVue3: function initVue3(userConfiguration) {
|
|
49
|
-
this.init({},
|
|
49
|
+
this.init({}, (0, _utils.extend)({
|
|
50
|
+
isVue2: false
|
|
51
|
+
}, userConfiguration));
|
|
50
52
|
},
|
|
51
53
|
getInternalContext: function getInternalContext(startTime) {
|
|
52
54
|
return _getInternalContext(startTime);
|
|
@@ -37,8 +37,9 @@ var DEFAULT_CONFIGURATION = {
|
|
|
37
37
|
trackInteractions: false,
|
|
38
38
|
traceType: _enums.TraceType.DDTRACE,
|
|
39
39
|
traceId128Bit: false,
|
|
40
|
-
allowedTracingOrigins: []
|
|
41
|
-
|
|
40
|
+
allowedTracingOrigins: [],
|
|
41
|
+
// 新增
|
|
42
|
+
isVue2: true
|
|
42
43
|
};
|
|
43
44
|
exports.DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION;
|
|
44
45
|
|
|
@@ -56,6 +57,7 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
56
57
|
applicationId: userConfiguration.applicationId,
|
|
57
58
|
env: userConfiguration.env || '',
|
|
58
59
|
version: userConfiguration.version || '',
|
|
60
|
+
service: userConfiguration.service || '',
|
|
59
61
|
sdkVersion: buildEnv.sdkVersion,
|
|
60
62
|
sdkName: buildEnv.sdkName,
|
|
61
63
|
datakitUrl: getDatakitUrlUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
|
|
@@ -82,6 +84,10 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
82
84
|
transportConfiguration.sampleRate = userConfiguration.sampleRate;
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
if ('isVue2' in userConfiguration) {
|
|
88
|
+
transportConfiguration.isVue2 = userConfiguration.isVue2;
|
|
89
|
+
}
|
|
90
|
+
|
|
85
91
|
return (0, _utils.extend2Lev)(DEFAULT_CONFIGURATION, transportConfiguration);
|
|
86
92
|
}
|
|
87
93
|
|
package/cjs/core/dataMap.js
CHANGED
|
@@ -14,6 +14,7 @@ var commonTags = {
|
|
|
14
14
|
app_id: 'application.id',
|
|
15
15
|
env: '_dd.env',
|
|
16
16
|
version: '_dd.version',
|
|
17
|
+
service: '_dd.service',
|
|
17
18
|
userid: 'user.id',
|
|
18
19
|
user_email: 'user.email',
|
|
19
20
|
user_name: 'user.name',
|
|
@@ -88,6 +89,8 @@ var dataMap = {
|
|
|
88
89
|
error: {
|
|
89
90
|
type: _enums.RumEventType.ERROR,
|
|
90
91
|
tags: {
|
|
92
|
+
trace_id: '_dd.trace_id',
|
|
93
|
+
span_id: '_dd.span_id',
|
|
91
94
|
error_source: 'error.source',
|
|
92
95
|
error_type: 'error.type',
|
|
93
96
|
resource_url: 'error.resource.url',
|
|
@@ -12,14 +12,16 @@ var _utils = require("../helper/utils");
|
|
|
12
12
|
|
|
13
13
|
var _enums = require("../helper/enums");
|
|
14
14
|
|
|
15
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
16
|
+
|
|
15
17
|
var downloadProxySingleton;
|
|
16
18
|
var beforeSendCallbacks = [];
|
|
17
19
|
var onRequestCompleteCallbacks = [];
|
|
18
20
|
var originalDownloadRequest;
|
|
19
21
|
|
|
20
|
-
function startDownloadProxy() {
|
|
22
|
+
function startDownloadProxy(userConfiguration) {
|
|
21
23
|
if (!downloadProxySingleton) {
|
|
22
|
-
proxyDownload();
|
|
24
|
+
proxyDownload(userConfiguration);
|
|
23
25
|
downloadProxySingleton = {
|
|
24
26
|
beforeSend: function beforeSend(callback) {
|
|
25
27
|
beforeSendCallbacks.push(callback);
|
|
@@ -42,7 +44,7 @@ function resetDownloadProxy() {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
function proxyDownload() {
|
|
47
|
+
function proxyDownload(userConfiguration) {
|
|
46
48
|
originalDownloadRequest = _sdk.sdk.downloadFile;
|
|
47
49
|
|
|
48
50
|
_sdk.sdk.downloadFile = function () {
|
|
@@ -58,23 +60,27 @@ function proxyDownload() {
|
|
|
58
60
|
dataflux_xhr.startTime = (0, _utils.now)();
|
|
59
61
|
var originalSuccess = arguments[0].success;
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
if (typeof originalSuccess === 'function') {
|
|
64
|
+
arguments[0].success = function () {
|
|
65
|
+
reportXhr(arguments[0]);
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
if (originalSuccess) {
|
|
68
|
+
originalSuccess.apply(_this, arguments);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
68
72
|
|
|
69
73
|
var originalFail = arguments[0].fail;
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
if (typeof originalFail === 'function') {
|
|
76
|
+
arguments[0].fail = function () {
|
|
77
|
+
reportXhr(arguments[0]);
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
if (originalFail) {
|
|
80
|
+
originalFail.apply(_this, arguments);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
78
84
|
|
|
79
85
|
var hasBeenReported = false;
|
|
80
86
|
|
|
@@ -100,6 +106,35 @@ function proxyDownload() {
|
|
|
100
106
|
beforeSendCallbacks.forEach(function (callback) {
|
|
101
107
|
callback(dataflux_xhr);
|
|
102
108
|
});
|
|
103
|
-
|
|
109
|
+
var result = originalDownloadRequest.apply(this, arguments); // 判断结果是否为promise
|
|
110
|
+
|
|
111
|
+
var isPromise = function isPromise(obj) {
|
|
112
|
+
return !!obj && (_typeof(obj) === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (isPromise(result) && userConfiguration.isVue2) {
|
|
116
|
+
// vue2 版本,success, fail 都在then返回
|
|
117
|
+
return result.then(function (res) {
|
|
118
|
+
if (res[0]) {
|
|
119
|
+
reportXhr(res[0]);
|
|
120
|
+
} else {
|
|
121
|
+
reportXhr(res[1]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return res;
|
|
125
|
+
});
|
|
126
|
+
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
127
|
+
return new Promise(function (resolve, reject) {
|
|
128
|
+
result.then(function (res) {
|
|
129
|
+
reportXhr(res);
|
|
130
|
+
resolve(res);
|
|
131
|
+
})["catch"](function (err) {
|
|
132
|
+
reportXhr(err);
|
|
133
|
+
reject(err);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
104
139
|
};
|
|
105
140
|
}
|
|
@@ -120,10 +120,10 @@ function startAutomaticErrorCollection(configuration) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
function trackNetworkError(configuration, errorObservable) {
|
|
123
|
-
(0, _xhrProxy.startXhrProxy)().onRequestComplete(function (context) {
|
|
123
|
+
(0, _xhrProxy.startXhrProxy)(configuration).onRequestComplete(function (context) {
|
|
124
124
|
return handleCompleteRequest(context.type, context);
|
|
125
125
|
});
|
|
126
|
-
(0, _downloadProxy.startDownloadProxy)().onRequestComplete(function (context) {
|
|
126
|
+
(0, _downloadProxy.startDownloadProxy)(configuration).onRequestComplete(function (context) {
|
|
127
127
|
return handleCompleteRequest(context.type, context);
|
|
128
128
|
});
|
|
129
129
|
|
|
@@ -134,7 +134,9 @@ function trackNetworkError(configuration, errorObservable) {
|
|
|
134
134
|
resource: {
|
|
135
135
|
method: request.method,
|
|
136
136
|
statusCode: request.status,
|
|
137
|
-
url: request.url
|
|
137
|
+
url: request.url,
|
|
138
|
+
traceId: request.traceId,
|
|
139
|
+
spanId: request.spanId
|
|
138
140
|
},
|
|
139
141
|
type: _errorTools.ErrorSource.NETWORK,
|
|
140
142
|
source: _errorTools.ErrorSource.NETWORK,
|
package/cjs/core/xhrProxy.js
CHANGED
|
@@ -12,14 +12,16 @@ var _utils = require("../helper/utils");
|
|
|
12
12
|
|
|
13
13
|
var _enums = require("../helper/enums");
|
|
14
14
|
|
|
15
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
16
|
+
|
|
15
17
|
var xhrProxySingleton;
|
|
16
18
|
var beforeSendCallbacks = [];
|
|
17
19
|
var onRequestCompleteCallbacks = [];
|
|
18
20
|
var originalXhrRequest;
|
|
19
21
|
|
|
20
|
-
function startXhrProxy() {
|
|
22
|
+
function startXhrProxy(userConfiguration) {
|
|
21
23
|
if (!xhrProxySingleton) {
|
|
22
|
-
proxyXhr();
|
|
24
|
+
proxyXhr(userConfiguration);
|
|
23
25
|
xhrProxySingleton = {
|
|
24
26
|
beforeSend: function beforeSend(callback) {
|
|
25
27
|
beforeSendCallbacks.push(callback);
|
|
@@ -42,7 +44,7 @@ function resetXhrProxy() {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
function proxyXhr() {
|
|
47
|
+
function proxyXhr(userConfiguration) {
|
|
46
48
|
originalXhrRequest = _sdk.sdk.request;
|
|
47
49
|
|
|
48
50
|
_sdk.sdk.request = function () {
|
|
@@ -59,23 +61,27 @@ function proxyXhr() {
|
|
|
59
61
|
dataflux_xhr.startTime = (0, _utils.now)();
|
|
60
62
|
var originalSuccess = arguments[0].success;
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
if (typeof originalSuccess === 'function') {
|
|
65
|
+
arguments[0].success = function () {
|
|
66
|
+
reportXhr(arguments[0]);
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
if (originalSuccess) {
|
|
69
|
+
originalSuccess.apply(_this, arguments);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
69
73
|
|
|
70
74
|
var originalFail = arguments[0].fail;
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
if (typeof originalFail === 'function') {
|
|
77
|
+
arguments[0].fail = function () {
|
|
78
|
+
reportXhr(arguments[0]);
|
|
74
79
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
if (originalFail) {
|
|
81
|
+
originalFail.apply(_this, arguments);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
79
85
|
|
|
80
86
|
var hasBeenReported = false;
|
|
81
87
|
|
|
@@ -98,6 +104,35 @@ function proxyXhr() {
|
|
|
98
104
|
beforeSendCallbacks.forEach(function (callback) {
|
|
99
105
|
callback(dataflux_xhr);
|
|
100
106
|
});
|
|
101
|
-
|
|
107
|
+
var result = originalXhrRequest.call(this, dataflux_xhr.option); // 判断结果是否为promise
|
|
108
|
+
|
|
109
|
+
var isPromise = function isPromise(obj) {
|
|
110
|
+
return !!obj && (_typeof(obj) === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (isPromise(result) && userConfiguration.isVue2) {
|
|
114
|
+
// vue2 版本,success, fail 都在then返回
|
|
115
|
+
return result.then(function (res) {
|
|
116
|
+
if (res[0]) {
|
|
117
|
+
reportXhr(res[0]);
|
|
118
|
+
} else {
|
|
119
|
+
reportXhr(res[1]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return res;
|
|
123
|
+
});
|
|
124
|
+
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
125
|
+
return new Promise(function (resolve, reject) {
|
|
126
|
+
result.then(function (res) {
|
|
127
|
+
reportXhr(res);
|
|
128
|
+
resolve(res);
|
|
129
|
+
})["catch"](function (err) {
|
|
130
|
+
reportXhr(err);
|
|
131
|
+
reject(err);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
102
137
|
};
|
|
103
138
|
}
|
|
@@ -43,7 +43,8 @@ function startRumAssembly(applicationId, configuration, session, lifeCycle, pare
|
|
|
43
43
|
sdkName: configuration.sdkName,
|
|
44
44
|
sdkVersion: configuration.sdkVersion,
|
|
45
45
|
env: configuration.env,
|
|
46
|
-
version: configuration.version
|
|
46
|
+
version: configuration.version,
|
|
47
|
+
service: configuration.service
|
|
47
48
|
},
|
|
48
49
|
tags: configuration.tags,
|
|
49
50
|
application: {
|
|
@@ -58,8 +58,10 @@ function doStartErrorCollection(lifeCycle) {
|
|
|
58
58
|
|
|
59
59
|
function processError(error) {
|
|
60
60
|
var resource = error.resource;
|
|
61
|
+
var tracingInfo;
|
|
61
62
|
|
|
62
63
|
if (resource) {
|
|
64
|
+
tracingInfo = computeRequestTracingInfo(resource);
|
|
63
65
|
var urlObj = (0, _utils.urlParse)(error.resource.url).getParse();
|
|
64
66
|
resource = {
|
|
65
67
|
method: error.resource.method,
|
|
@@ -72,7 +74,7 @@ function processError(error) {
|
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
var rawRumEvent = {
|
|
77
|
+
var rawRumEvent = (0, _utils.extend2Lev)({
|
|
76
78
|
date: error.startTime,
|
|
77
79
|
error: {
|
|
78
80
|
message: error.message,
|
|
@@ -83,9 +85,24 @@ function processError(error) {
|
|
|
83
85
|
starttime: error.startTime
|
|
84
86
|
},
|
|
85
87
|
type: _enums.RumEventType.ERROR
|
|
86
|
-
};
|
|
88
|
+
}, tracingInfo);
|
|
87
89
|
return {
|
|
88
90
|
rawRumEvent: rawRumEvent,
|
|
89
91
|
startTime: error.startTime
|
|
90
92
|
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function computeRequestTracingInfo(request) {
|
|
96
|
+
var hasBeenTraced = request.traceId && request.spanId;
|
|
97
|
+
|
|
98
|
+
if (!hasBeenTraced) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
_dd: {
|
|
104
|
+
spanId: request.spanId,
|
|
105
|
+
traceId: request.traceId
|
|
106
|
+
}
|
|
107
|
+
};
|
|
91
108
|
}
|
|
@@ -47,7 +47,7 @@ function getHeaderString(header) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function trackXhr(lifeCycle, configuration, tracer) {
|
|
50
|
-
var xhrProxy = (0, _xhrProxy.startXhrProxy)();
|
|
50
|
+
var xhrProxy = (0, _xhrProxy.startXhrProxy)(configuration);
|
|
51
51
|
xhrProxy.beforeSend(function (context) {
|
|
52
52
|
if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
|
|
53
53
|
tracer.traceXhr(context);
|
|
@@ -79,7 +79,7 @@ function trackXhr(lifeCycle, configuration, tracer) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function trackDownload(lifeCycle, configuration) {
|
|
82
|
-
var dwonloadProxy = (0, _downloadProxy.startDownloadProxy)();
|
|
82
|
+
var dwonloadProxy = (0, _downloadProxy.startDownloadProxy)(configuration);
|
|
83
83
|
dwonloadProxy.beforeSend(function (context) {
|
|
84
84
|
if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
|
|
85
85
|
context.requestIndex = getNextRequestIndex();
|
|
@@ -41,7 +41,7 @@ DDtraceTracer.prototype = {
|
|
|
41
41
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
42
42
|
return {
|
|
43
43
|
'x-datadog-origin': 'rum',
|
|
44
|
-
|
|
44
|
+
'x-datadog-parent-id': this.getSpanId(),
|
|
45
45
|
'x-datadog-sampled': '1',
|
|
46
46
|
'x-datadog-sampling-priority': '1',
|
|
47
47
|
'x-datadog-trace-id': this.getTraceId()
|
package/esm/boot/buildEnv.js
CHANGED
package/esm/boot/rum.entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPercentage, extend2Lev, now, createContextManager, defineGlobal, getGlobalObject, isString, isObject } from '../helper/utils';
|
|
1
|
+
import { isPercentage, extend2Lev, extend, now, createContextManager, defineGlobal, getGlobalObject, isString, isObject } from '../helper/utils';
|
|
2
2
|
import { startRum } from './rum';
|
|
3
3
|
import { ActionType } from '../helper/enums';
|
|
4
4
|
export var makeRum = function makeRum(startRumImpl) {
|
|
@@ -34,7 +34,9 @@ export var makeRum = function makeRum(startRumImpl) {
|
|
|
34
34
|
isAlreadyInitialized = true;
|
|
35
35
|
},
|
|
36
36
|
initVue3: function initVue3(userConfiguration) {
|
|
37
|
-
this.init({},
|
|
37
|
+
this.init({}, extend({
|
|
38
|
+
isVue2: false
|
|
39
|
+
}, userConfiguration));
|
|
38
40
|
},
|
|
39
41
|
getInternalContext: function getInternalContext(startTime) {
|
|
40
42
|
return _getInternalContext(startTime);
|
|
@@ -26,8 +26,9 @@ export var DEFAULT_CONFIGURATION = {
|
|
|
26
26
|
trackInteractions: false,
|
|
27
27
|
traceType: TraceType.DDTRACE,
|
|
28
28
|
traceId128Bit: false,
|
|
29
|
-
allowedTracingOrigins: []
|
|
30
|
-
|
|
29
|
+
allowedTracingOrigins: [],
|
|
30
|
+
// 新增
|
|
31
|
+
isVue2: true
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
function trim(str) {
|
|
@@ -44,6 +45,7 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
44
45
|
applicationId: userConfiguration.applicationId,
|
|
45
46
|
env: userConfiguration.env || '',
|
|
46
47
|
version: userConfiguration.version || '',
|
|
48
|
+
service: userConfiguration.service || '',
|
|
47
49
|
sdkVersion: buildEnv.sdkVersion,
|
|
48
50
|
sdkName: buildEnv.sdkName,
|
|
49
51
|
datakitUrl: getDatakitUrlUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
|
|
@@ -70,6 +72,10 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
70
72
|
transportConfiguration.sampleRate = userConfiguration.sampleRate;
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
if ('isVue2' in userConfiguration) {
|
|
76
|
+
transportConfiguration.isVue2 = userConfiguration.isVue2;
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
|
|
74
80
|
}
|
|
75
81
|
|
package/esm/core/dataMap.js
CHANGED
|
@@ -6,6 +6,7 @@ export var commonTags = {
|
|
|
6
6
|
app_id: 'application.id',
|
|
7
7
|
env: '_dd.env',
|
|
8
8
|
version: '_dd.version',
|
|
9
|
+
service: '_dd.service',
|
|
9
10
|
userid: 'user.id',
|
|
10
11
|
user_email: 'user.email',
|
|
11
12
|
user_name: 'user.name',
|
|
@@ -79,6 +80,8 @@ export var dataMap = {
|
|
|
79
80
|
error: {
|
|
80
81
|
type: RumEventType.ERROR,
|
|
81
82
|
tags: {
|
|
83
|
+
trace_id: '_dd.trace_id',
|
|
84
|
+
span_id: '_dd.span_id',
|
|
82
85
|
error_source: 'error.source',
|
|
83
86
|
error_type: 'error.type',
|
|
84
87
|
resource_url: 'error.resource.url',
|
|
@@ -5,9 +5,9 @@ var downloadProxySingleton;
|
|
|
5
5
|
var beforeSendCallbacks = [];
|
|
6
6
|
var onRequestCompleteCallbacks = [];
|
|
7
7
|
var originalDownloadRequest;
|
|
8
|
-
export function startDownloadProxy() {
|
|
8
|
+
export function startDownloadProxy(userConfiguration) {
|
|
9
9
|
if (!downloadProxySingleton) {
|
|
10
|
-
proxyDownload();
|
|
10
|
+
proxyDownload(userConfiguration);
|
|
11
11
|
downloadProxySingleton = {
|
|
12
12
|
beforeSend: function beforeSend(callback) {
|
|
13
13
|
beforeSendCallbacks.push(callback);
|
|
@@ -29,7 +29,7 @@ export function resetDownloadProxy() {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function proxyDownload() {
|
|
32
|
+
function proxyDownload(userConfiguration) {
|
|
33
33
|
originalDownloadRequest = sdk.downloadFile;
|
|
34
34
|
|
|
35
35
|
sdk.downloadFile = function () {
|
|
@@ -45,23 +45,27 @@ function proxyDownload() {
|
|
|
45
45
|
dataflux_xhr.startTime = now();
|
|
46
46
|
var originalSuccess = arguments[0].success;
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
if (typeof originalSuccess === 'function') {
|
|
49
|
+
arguments[0].success = function () {
|
|
50
|
+
reportXhr(arguments[0]);
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
if (originalSuccess) {
|
|
53
|
+
originalSuccess.apply(_this, arguments);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
55
57
|
|
|
56
58
|
var originalFail = arguments[0].fail;
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
if (typeof originalFail === 'function') {
|
|
61
|
+
arguments[0].fail = function () {
|
|
62
|
+
reportXhr(arguments[0]);
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (originalFail) {
|
|
65
|
+
originalFail.apply(_this, arguments);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
65
69
|
|
|
66
70
|
var hasBeenReported = false;
|
|
67
71
|
|
|
@@ -87,6 +91,35 @@ function proxyDownload() {
|
|
|
87
91
|
beforeSendCallbacks.forEach(function (callback) {
|
|
88
92
|
callback(dataflux_xhr);
|
|
89
93
|
});
|
|
90
|
-
|
|
94
|
+
var result = originalDownloadRequest.apply(this, arguments); // 判断结果是否为promise
|
|
95
|
+
|
|
96
|
+
var isPromise = function isPromise(obj) {
|
|
97
|
+
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (isPromise(result) && userConfiguration.isVue2) {
|
|
101
|
+
// vue2 版本,success, fail 都在then返回
|
|
102
|
+
return result.then(function (res) {
|
|
103
|
+
if (res[0]) {
|
|
104
|
+
reportXhr(res[0]);
|
|
105
|
+
} else {
|
|
106
|
+
reportXhr(res[1]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return res;
|
|
110
|
+
});
|
|
111
|
+
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
112
|
+
return new Promise(function (resolve, reject) {
|
|
113
|
+
result.then(function (res) {
|
|
114
|
+
reportXhr(res);
|
|
115
|
+
resolve(res);
|
|
116
|
+
}).catch(function (err) {
|
|
117
|
+
reportXhr(err);
|
|
118
|
+
reject(err);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
91
124
|
};
|
|
92
125
|
}
|
|
@@ -91,10 +91,10 @@ export function startAutomaticErrorCollection(configuration) {
|
|
|
91
91
|
return errorObservable;
|
|
92
92
|
}
|
|
93
93
|
export function trackNetworkError(configuration, errorObservable) {
|
|
94
|
-
startXhrProxy().onRequestComplete(function (context) {
|
|
94
|
+
startXhrProxy(configuration).onRequestComplete(function (context) {
|
|
95
95
|
return handleCompleteRequest(context.type, context);
|
|
96
96
|
});
|
|
97
|
-
startDownloadProxy().onRequestComplete(function (context) {
|
|
97
|
+
startDownloadProxy(configuration).onRequestComplete(function (context) {
|
|
98
98
|
return handleCompleteRequest(context.type, context);
|
|
99
99
|
});
|
|
100
100
|
|
|
@@ -105,7 +105,9 @@ export function trackNetworkError(configuration, errorObservable) {
|
|
|
105
105
|
resource: {
|
|
106
106
|
method: request.method,
|
|
107
107
|
statusCode: request.status,
|
|
108
|
-
url: request.url
|
|
108
|
+
url: request.url,
|
|
109
|
+
traceId: request.traceId,
|
|
110
|
+
spanId: request.spanId
|
|
109
111
|
},
|
|
110
112
|
type: ErrorSource.NETWORK,
|
|
111
113
|
source: ErrorSource.NETWORK,
|
package/esm/core/xhrProxy.js
CHANGED
|
@@ -5,9 +5,9 @@ var xhrProxySingleton;
|
|
|
5
5
|
var beforeSendCallbacks = [];
|
|
6
6
|
var onRequestCompleteCallbacks = [];
|
|
7
7
|
var originalXhrRequest;
|
|
8
|
-
export function startXhrProxy() {
|
|
8
|
+
export function startXhrProxy(userConfiguration) {
|
|
9
9
|
if (!xhrProxySingleton) {
|
|
10
|
-
proxyXhr();
|
|
10
|
+
proxyXhr(userConfiguration);
|
|
11
11
|
xhrProxySingleton = {
|
|
12
12
|
beforeSend: function beforeSend(callback) {
|
|
13
13
|
beforeSendCallbacks.push(callback);
|
|
@@ -29,7 +29,7 @@ export function resetXhrProxy() {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function proxyXhr() {
|
|
32
|
+
function proxyXhr(userConfiguration) {
|
|
33
33
|
originalXhrRequest = sdk.request;
|
|
34
34
|
|
|
35
35
|
sdk.request = function () {
|
|
@@ -46,23 +46,27 @@ function proxyXhr() {
|
|
|
46
46
|
dataflux_xhr.startTime = now();
|
|
47
47
|
var originalSuccess = arguments[0].success;
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (typeof originalSuccess === 'function') {
|
|
50
|
+
arguments[0].success = function () {
|
|
51
|
+
reportXhr(arguments[0]);
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (originalSuccess) {
|
|
54
|
+
originalSuccess.apply(_this, arguments);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
56
58
|
|
|
57
59
|
var originalFail = arguments[0].fail;
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
if (typeof originalFail === 'function') {
|
|
62
|
+
arguments[0].fail = function () {
|
|
63
|
+
reportXhr(arguments[0]);
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
if (originalFail) {
|
|
66
|
+
originalFail.apply(_this, arguments);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
66
70
|
|
|
67
71
|
var hasBeenReported = false;
|
|
68
72
|
|
|
@@ -85,6 +89,35 @@ function proxyXhr() {
|
|
|
85
89
|
beforeSendCallbacks.forEach(function (callback) {
|
|
86
90
|
callback(dataflux_xhr);
|
|
87
91
|
});
|
|
88
|
-
|
|
92
|
+
var result = originalXhrRequest.call(this, dataflux_xhr.option); // 判断结果是否为promise
|
|
93
|
+
|
|
94
|
+
var isPromise = function isPromise(obj) {
|
|
95
|
+
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (isPromise(result) && userConfiguration.isVue2) {
|
|
99
|
+
// vue2 版本,success, fail 都在then返回
|
|
100
|
+
return result.then(function (res) {
|
|
101
|
+
if (res[0]) {
|
|
102
|
+
reportXhr(res[0]);
|
|
103
|
+
} else {
|
|
104
|
+
reportXhr(res[1]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return res;
|
|
108
|
+
});
|
|
109
|
+
} else if (isPromise(result) && !userConfiguration.isVue2) {
|
|
110
|
+
return new Promise(function (resolve, reject) {
|
|
111
|
+
result.then(function (res) {
|
|
112
|
+
reportXhr(res);
|
|
113
|
+
resolve(res);
|
|
114
|
+
}).catch(function (err) {
|
|
115
|
+
reportXhr(err);
|
|
116
|
+
reject(err);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
89
122
|
};
|
|
90
123
|
}
|
|
@@ -28,7 +28,8 @@ export function startRumAssembly(applicationId, configuration, session, lifeCycl
|
|
|
28
28
|
sdkName: configuration.sdkName,
|
|
29
29
|
sdkVersion: configuration.sdkVersion,
|
|
30
30
|
env: configuration.env,
|
|
31
|
-
version: configuration.version
|
|
31
|
+
version: configuration.version,
|
|
32
|
+
service: configuration.service
|
|
32
33
|
},
|
|
33
34
|
tags: configuration.tags,
|
|
34
35
|
application: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { startAutomaticErrorCollection } from '../../core/errorCollection';
|
|
2
2
|
import { RumEventType } from '../../helper/enums';
|
|
3
3
|
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
4
|
-
import { urlParse, replaceNumberCharByPath, getStatusGroup } from '../../helper/utils';
|
|
4
|
+
import { urlParse, replaceNumberCharByPath, getStatusGroup, extend2Lev } from '../../helper/utils';
|
|
5
5
|
export function startErrorCollection(lifeCycle, configuration) {
|
|
6
6
|
// return doStartErrorCollection(
|
|
7
7
|
// lifeCycle,
|
|
@@ -44,8 +44,10 @@ export function doStartErrorCollection(lifeCycle) {
|
|
|
44
44
|
|
|
45
45
|
function processError(error) {
|
|
46
46
|
var resource = error.resource;
|
|
47
|
+
var tracingInfo;
|
|
47
48
|
|
|
48
49
|
if (resource) {
|
|
50
|
+
tracingInfo = computeRequestTracingInfo(resource);
|
|
49
51
|
var urlObj = urlParse(error.resource.url).getParse();
|
|
50
52
|
resource = {
|
|
51
53
|
method: error.resource.method,
|
|
@@ -58,7 +60,7 @@ function processError(error) {
|
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
var rawRumEvent = {
|
|
63
|
+
var rawRumEvent = extend2Lev({
|
|
62
64
|
date: error.startTime,
|
|
63
65
|
error: {
|
|
64
66
|
message: error.message,
|
|
@@ -69,9 +71,24 @@ function processError(error) {
|
|
|
69
71
|
starttime: error.startTime
|
|
70
72
|
},
|
|
71
73
|
type: RumEventType.ERROR
|
|
72
|
-
};
|
|
74
|
+
}, tracingInfo);
|
|
73
75
|
return {
|
|
74
76
|
rawRumEvent: rawRumEvent,
|
|
75
77
|
startTime: error.startTime
|
|
76
78
|
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function computeRequestTracingInfo(request) {
|
|
82
|
+
var hasBeenTraced = request.traceId && request.spanId;
|
|
83
|
+
|
|
84
|
+
if (!hasBeenTraced) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
_dd: {
|
|
90
|
+
spanId: request.spanId,
|
|
91
|
+
traceId: request.traceId
|
|
92
|
+
}
|
|
93
|
+
};
|
|
77
94
|
}
|
|
@@ -31,7 +31,7 @@ function getHeaderString(header) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function trackXhr(lifeCycle, configuration, tracer) {
|
|
34
|
-
var xhrProxy = startXhrProxy();
|
|
34
|
+
var xhrProxy = startXhrProxy(configuration);
|
|
35
35
|
xhrProxy.beforeSend(function (context) {
|
|
36
36
|
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
37
37
|
tracer.traceXhr(context);
|
|
@@ -62,7 +62,7 @@ export function trackXhr(lifeCycle, configuration, tracer) {
|
|
|
62
62
|
return xhrProxy;
|
|
63
63
|
}
|
|
64
64
|
export function trackDownload(lifeCycle, configuration) {
|
|
65
|
-
var dwonloadProxy = startDownloadProxy();
|
|
65
|
+
var dwonloadProxy = startDownloadProxy(configuration);
|
|
66
66
|
dwonloadProxy.beforeSend(function (context) {
|
|
67
67
|
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
68
68
|
context.requestIndex = getNextRequestIndex();
|
|
@@ -33,7 +33,7 @@ DDtraceTracer.prototype = {
|
|
|
33
33
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
34
34
|
return {
|
|
35
35
|
'x-datadog-origin': 'rum',
|
|
36
|
-
|
|
36
|
+
'x-datadog-parent-id': this.getSpanId(),
|
|
37
37
|
'x-datadog-sampled': '1',
|
|
38
38
|
'x-datadog-sampling-priority': '1',
|
|
39
39
|
'x-datadog-trace-id': this.getTraceId()
|