@cloudcare/rum-uniapp 1.0.3 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.entry.js +56 -1
- package/cjs/boot/rum.js +2 -2
- package/cjs/core/boundedBuffer.js +28 -0
- package/cjs/core/configuration.js +22 -1
- package/cjs/core/dataMap.js +5 -1
- package/cjs/core/transport.js +123 -69
- package/cjs/core/xhrProxy.js +3 -2
- package/cjs/helper/enums.js +11 -2
- package/cjs/helper/utils.js +163 -6
- package/cjs/rumEventsCollection/assembly.js +19 -2
- package/cjs/rumEventsCollection/page/index.js +1 -11
- package/cjs/rumEventsCollection/requestCollection.js +9 -2
- package/cjs/rumEventsCollection/resource/resourceCollection.js +20 -1
- package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +50 -0
- package/cjs/rumEventsCollection/tracing/jaegerTracer.js +58 -0
- package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +75 -0
- package/cjs/rumEventsCollection/tracing/tracer.js +108 -0
- package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +51 -0
- package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +58 -0
- package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +51 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +55 -2
- package/esm/boot/rum.js +2 -2
- package/esm/core/boundedBuffer.js +20 -0
- package/esm/core/configuration.js +24 -3
- package/esm/core/dataMap.js +5 -1
- package/esm/core/transport.js +120 -70
- package/esm/core/xhrProxy.js +3 -2
- package/esm/helper/enums.js +8 -0
- package/esm/helper/utils.js +145 -5
- package/esm/rumEventsCollection/assembly.js +20 -3
- package/esm/rumEventsCollection/page/index.js +1 -11
- package/esm/rumEventsCollection/requestCollection.js +8 -2
- package/esm/rumEventsCollection/resource/resourceCollection.js +21 -2
- package/esm/rumEventsCollection/tracing/ddtraceTracer.js +42 -0
- package/esm/rumEventsCollection/tracing/jaegerTracer.js +50 -0
- package/esm/rumEventsCollection/tracing/skywalkingTracer.js +66 -0
- package/esm/rumEventsCollection/tracing/tracer.js +90 -0
- package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +43 -0
- package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +50 -0
- package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +43 -0
- package/package.json +1 -1
package/esm/boot/rum.js
CHANGED
|
@@ -13,12 +13,12 @@ import { startPagePerformanceObservable } from '../rumEventsCollection/performan
|
|
|
13
13
|
import { startSetDataColloction } from '../rumEventsCollection/setDataCollection';
|
|
14
14
|
import { startActionCollection } from '../rumEventsCollection/action/actionCollection';
|
|
15
15
|
import { sdk } from '../core/sdk';
|
|
16
|
-
export var startRum = function startRum(Vue, userConfiguration) {
|
|
16
|
+
export var startRum = function startRum(Vue, userConfiguration, getCommonContext) {
|
|
17
17
|
var configuration = commonInit(userConfiguration, buildEnv);
|
|
18
18
|
var lifeCycle = new LifeCycle();
|
|
19
19
|
var parentContexts = startParentContexts(lifeCycle);
|
|
20
20
|
var batch = startRumBatch(configuration, lifeCycle);
|
|
21
|
-
startRumAssembly(userConfiguration.applicationId, configuration, lifeCycle, parentContexts);
|
|
21
|
+
startRumAssembly(userConfiguration.applicationId, configuration, lifeCycle, parentContexts, getCommonContext);
|
|
22
22
|
startAppCollection(lifeCycle, configuration);
|
|
23
23
|
startResourceCollection(lifeCycle, configuration);
|
|
24
24
|
startViewCollection(lifeCycle, configuration, Vue);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var _BoundedBuffer = function _BoundedBuffer() {
|
|
2
|
+
this.buffer = [];
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
_BoundedBuffer.prototype = {
|
|
6
|
+
add: function add(item) {
|
|
7
|
+
var length = this.buffer.push(item);
|
|
8
|
+
|
|
9
|
+
if (length > this.limit) {
|
|
10
|
+
this.buffer.splice(0, 1);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
drain: function drain(fn) {
|
|
14
|
+
this.buffer.forEach(function (item) {
|
|
15
|
+
fn(item);
|
|
16
|
+
});
|
|
17
|
+
this.buffer.length = 0;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export var BoundedBuffer = _BoundedBuffer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { extend2Lev, urlParse } from '../helper/utils';
|
|
2
|
-
import { ONE_KILO_BYTE, ONE_SECOND } from '../helper/enums';
|
|
1
|
+
import { extend2Lev, urlParse, values } from '../helper/utils';
|
|
2
|
+
import { ONE_KILO_BYTE, ONE_SECOND, TraceType } from '../helper/enums';
|
|
3
3
|
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
4
4
|
export var DEFAULT_CONFIGURATION = {
|
|
5
5
|
sampleRate: 100,
|
|
@@ -23,7 +23,11 @@ export var DEFAULT_CONFIGURATION = {
|
|
|
23
23
|
* arbitrary value, byte precision not needed
|
|
24
24
|
*/
|
|
25
25
|
requestErrorResponseLengthLimit: 32 * ONE_KILO_BYTE,
|
|
26
|
-
trackInteractions: false
|
|
26
|
+
trackInteractions: false,
|
|
27
|
+
traceType: TraceType.DDTRACE,
|
|
28
|
+
traceId128Bit: false,
|
|
29
|
+
allowedTracingOrigins: [] // 新增
|
|
30
|
+
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
function trim(str) {
|
|
@@ -50,9 +54,26 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
50
54
|
transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
|
|
51
55
|
}
|
|
52
56
|
|
|
57
|
+
if ('allowedTracingOrigins' in userConfiguration) {
|
|
58
|
+
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ('traceId128Bit' in userConfiguration) {
|
|
62
|
+
transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
|
|
66
|
+
transportConfiguration.traceType = userConfiguration.traceType;
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
|
|
54
70
|
}
|
|
55
71
|
|
|
72
|
+
function hasTraceType(traceType) {
|
|
73
|
+
if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
56
77
|
var haveSameOrigin = function haveSameOrigin(url1, url2) {
|
|
57
78
|
var parseUrl1 = urlParse(url1).getParse();
|
|
58
79
|
var parseUrl2 = urlParse(url2).getParse();
|
package/esm/core/dataMap.js
CHANGED
|
@@ -6,7 +6,9 @@ export var commonTags = {
|
|
|
6
6
|
app_id: 'application.id',
|
|
7
7
|
env: '_dd.env',
|
|
8
8
|
version: '_dd.version',
|
|
9
|
-
userid: 'user.
|
|
9
|
+
userid: 'user.id',
|
|
10
|
+
user_email: 'user.email',
|
|
11
|
+
user_name: 'user.name',
|
|
10
12
|
session_id: 'session.id',
|
|
11
13
|
session_type: 'session.type',
|
|
12
14
|
is_signin: 'user.is_signin',
|
|
@@ -50,6 +52,8 @@ export var dataMap = {
|
|
|
50
52
|
resource: {
|
|
51
53
|
type: RumEventType.RESOURCE,
|
|
52
54
|
tags: {
|
|
55
|
+
trace_id: '_dd.trace_id',
|
|
56
|
+
span_id: '_dd.span_id',
|
|
53
57
|
resource_type: 'resource.type',
|
|
54
58
|
resource_status: 'resource.status',
|
|
55
59
|
resource_status_group: 'resource.status_group',
|
package/esm/core/transport.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { findByPath, escapeRowData, isNumber, each, isString, values, extend } from '../helper/utils';
|
|
1
|
+
import { findByPath, escapeRowData, isNumber, each, isString, values, extend, isObject, isEmptyObject, isArray, isBoolean, toServerDuration } from '../helper/utils';
|
|
2
2
|
import { sdk } from '../core/sdk';
|
|
3
3
|
import { LifeCycleEventType } from '../core/lifeCycle';
|
|
4
|
-
import { commonTags, dataMap } from './dataMap';
|
|
4
|
+
import { commonTags, dataMap } from './dataMap';
|
|
5
|
+
import { RumEventType } from '../helper/enums'; // https://en.wikipedia.org/wiki/UTF-8
|
|
5
6
|
|
|
6
7
|
var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
|
|
8
|
+
var CUSTOM_KEYS = 'custom_keys';
|
|
7
9
|
|
|
8
10
|
function addBatchPrecision(url) {
|
|
9
11
|
if (!url) return url;
|
|
@@ -29,6 +31,121 @@ httpRequest.prototype = {
|
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
33
|
export var HttpRequest = httpRequest;
|
|
34
|
+
export var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
35
|
+
if (!message || !message.type) return {
|
|
36
|
+
rowStr: '',
|
|
37
|
+
rowData: undefined
|
|
38
|
+
};
|
|
39
|
+
var rowData = {
|
|
40
|
+
tags: {},
|
|
41
|
+
fields: {}
|
|
42
|
+
};
|
|
43
|
+
var hasFileds = false;
|
|
44
|
+
var rowStr = '';
|
|
45
|
+
each(dataMap, function (value, key) {
|
|
46
|
+
if (value.type === message.type) {
|
|
47
|
+
if (value.alias_key) {
|
|
48
|
+
rowStr += value.alias_key + ',';
|
|
49
|
+
} else {
|
|
50
|
+
rowStr += key + ',';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
rowData.measurement = key;
|
|
54
|
+
var tagsStr = [];
|
|
55
|
+
var tags = extend({}, commonTags, value.tags);
|
|
56
|
+
var filterFileds = ['date', 'type']; // 已经在datamap中定义过的fields和tags
|
|
57
|
+
|
|
58
|
+
each(tags, function (value_path, _key) {
|
|
59
|
+
var _value = findByPath(message, value_path);
|
|
60
|
+
|
|
61
|
+
filterFileds.push(_key);
|
|
62
|
+
|
|
63
|
+
if (_value || isNumber(_value)) {
|
|
64
|
+
rowData.tags[_key] = _value;
|
|
65
|
+
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
|
|
70
|
+
// 自定义tag
|
|
71
|
+
var _tagKeys = [];
|
|
72
|
+
each(message.tags, function (_value, _key) {
|
|
73
|
+
// 如果和之前tag重名,则舍弃
|
|
74
|
+
if (filterFileds.indexOf(_key) > -1) return;
|
|
75
|
+
filterFileds.push(_key);
|
|
76
|
+
|
|
77
|
+
if (_value || isNumber(_value)) {
|
|
78
|
+
_tagKeys.push(_key);
|
|
79
|
+
|
|
80
|
+
rowData.tags[_key] = _value;
|
|
81
|
+
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (_tagKeys.length) {
|
|
86
|
+
rowData.tags[CUSTOM_KEYS] = _tagKeys;
|
|
87
|
+
tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var fieldsStr = [];
|
|
92
|
+
each(value.fields, function (_value, _key) {
|
|
93
|
+
if (isArray(_value) && _value.length === 2) {
|
|
94
|
+
var type = _value[0],
|
|
95
|
+
value_path = _value[1];
|
|
96
|
+
|
|
97
|
+
var _valueData = findByPath(message, value_path);
|
|
98
|
+
|
|
99
|
+
filterFileds.push(_key);
|
|
100
|
+
|
|
101
|
+
if (_valueData || isNumber(_valueData)) {
|
|
102
|
+
rowData.fields[_key] = _valueData; // 这里不需要转译
|
|
103
|
+
|
|
104
|
+
_valueData = type === 'string' ? '"' + _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"' : escapeRowData(_valueData);
|
|
105
|
+
fieldsStr.push(escapeRowData(_key) + '=' + _valueData);
|
|
106
|
+
}
|
|
107
|
+
} else if (isString(_value)) {
|
|
108
|
+
var _valueData = findByPath(message, _value);
|
|
109
|
+
|
|
110
|
+
filterFileds.push(_key);
|
|
111
|
+
|
|
112
|
+
if (_valueData || isNumber(_valueData)) {
|
|
113
|
+
rowData.fields[_key] = _valueData; // 这里不需要转译
|
|
114
|
+
|
|
115
|
+
_valueData = escapeRowData(_valueData);
|
|
116
|
+
fieldsStr.push(escapeRowData(_key) + '=' + _valueData);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (message.type === RumEventType.LOGGER) {
|
|
122
|
+
// 这里处理日志类型数据自定义字段
|
|
123
|
+
each(message, function (value, key) {
|
|
124
|
+
if (filterFileds.indexOf(key) === -1 && (isNumber(value) || isString(value) || isBoolean(value))) {
|
|
125
|
+
tagsStr.push(escapeRowData(key) + '=' + escapeRowData(value));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (tagsStr.length) {
|
|
131
|
+
rowStr += tagsStr.join(',');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (fieldsStr.length) {
|
|
135
|
+
rowStr += ' ';
|
|
136
|
+
rowStr += fieldsStr.join(',');
|
|
137
|
+
hasFileds = true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
rowStr = rowStr + ' ' + message.date;
|
|
141
|
+
rowData.time = toServerDuration(message.date); // 这里不需要转译
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
rowStr: hasFileds ? rowStr : '',
|
|
146
|
+
rowData: hasFileds ? rowData : undefined
|
|
147
|
+
};
|
|
148
|
+
};
|
|
32
149
|
|
|
33
150
|
function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, lifeCycle) {
|
|
34
151
|
this.request = request;
|
|
@@ -63,74 +180,7 @@ batch.prototype = {
|
|
|
63
180
|
}
|
|
64
181
|
},
|
|
65
182
|
processSendData: function processSendData(message) {
|
|
66
|
-
|
|
67
|
-
if (!message || !message.type) return '';
|
|
68
|
-
var rowStr = '';
|
|
69
|
-
var hasFileds = false;
|
|
70
|
-
each(dataMap, function (value, key) {
|
|
71
|
-
if (value.type === message.type) {
|
|
72
|
-
// 做一下别名处理
|
|
73
|
-
if (value.alias_key) {
|
|
74
|
-
rowStr += value.alias_key + ',';
|
|
75
|
-
} else {
|
|
76
|
-
rowStr += key + ',';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var tagsStr = [];
|
|
80
|
-
var tags = extend({}, commonTags, value.tags);
|
|
81
|
-
each(tags, function (value_path, _key) {
|
|
82
|
-
var _value = findByPath(message, value_path);
|
|
83
|
-
|
|
84
|
-
if (_value || isNumber(_value)) {
|
|
85
|
-
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (message.tags.length) {
|
|
90
|
-
// 自定义tag
|
|
91
|
-
each(message.tags, function (_value, _key) {
|
|
92
|
-
if (_value || isNumber(_value)) {
|
|
93
|
-
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
var fieldsStr = [];
|
|
99
|
-
each(value.fields, function (_value, _key) {
|
|
100
|
-
if (Array.isArray(_value) && _value.length === 2) {
|
|
101
|
-
var type = _value[0],
|
|
102
|
-
value_path = _value[1];
|
|
103
|
-
|
|
104
|
-
var _valueData = findByPath(message, value_path);
|
|
105
|
-
|
|
106
|
-
if (_valueData || isNumber(_valueData)) {
|
|
107
|
-
_valueData = type === 'string' ? '"' + String(_valueData).replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"' : escapeRowData(_valueData);
|
|
108
|
-
fieldsStr.push(escapeRowData(_key) + '=' + _valueData);
|
|
109
|
-
}
|
|
110
|
-
} else if (isString(_value)) {
|
|
111
|
-
var _valueData = findByPath(message, _value);
|
|
112
|
-
|
|
113
|
-
if (_valueData || isNumber(_valueData)) {
|
|
114
|
-
_valueData = escapeRowData(_valueData);
|
|
115
|
-
fieldsStr.push(escapeRowData(_key) + '=' + _valueData);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if (tagsStr.length) {
|
|
121
|
-
rowStr += tagsStr.join(',');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (fieldsStr.length) {
|
|
125
|
-
rowStr += ' ';
|
|
126
|
-
rowStr += fieldsStr.join(',');
|
|
127
|
-
hasFileds = true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
rowStr = rowStr + ' ' + message.date;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
return hasFileds ? rowStr : '';
|
|
183
|
+
return processedMessageByDataMap(message).rowStr;
|
|
134
184
|
},
|
|
135
185
|
sizeInBytes: function sizeInBytes(candidate) {
|
|
136
186
|
// Accurate byte size computations can degrade performances when there is a lot of events to process
|
package/esm/core/xhrProxy.js
CHANGED
|
@@ -40,7 +40,8 @@ function proxyXhr() {
|
|
|
40
40
|
startTime: 0,
|
|
41
41
|
url: arguments[0].url,
|
|
42
42
|
type: RequestType.XHR,
|
|
43
|
-
responseType: arguments[0].responseType || 'text'
|
|
43
|
+
responseType: arguments[0].responseType || 'text',
|
|
44
|
+
option: arguments[0]
|
|
44
45
|
};
|
|
45
46
|
dataflux_xhr.startTime = now();
|
|
46
47
|
var originalSuccess = arguments[0].success;
|
|
@@ -84,6 +85,6 @@ function proxyXhr() {
|
|
|
84
85
|
beforeSendCallbacks.forEach(function (callback) {
|
|
85
86
|
callback(dataflux_xhr);
|
|
86
87
|
});
|
|
87
|
-
return originalXhrRequest.
|
|
88
|
+
return originalXhrRequest.call(this, dataflux_xhr.option);
|
|
88
89
|
};
|
|
89
90
|
}
|
package/esm/helper/enums.js
CHANGED
|
@@ -33,4 +33,12 @@ export var MpHook = {
|
|
|
33
33
|
onResize: 1,
|
|
34
34
|
onHide: 1,
|
|
35
35
|
onUnload: 1
|
|
36
|
+
};
|
|
37
|
+
export var TraceType = {
|
|
38
|
+
DDTRACE: 'ddtrace',
|
|
39
|
+
ZIPKIN_MULTI_HEADER: 'zipkin',
|
|
40
|
+
ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
|
|
41
|
+
W3C_TRACEPARENT: 'w3c_traceparent',
|
|
42
|
+
SKYWALKING_V3: 'skywalking_v3',
|
|
43
|
+
JAEGER: 'jaeger'
|
|
36
44
|
};
|
package/esm/helper/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ var hasOwnProperty = ObjProto.hasOwnProperty;
|
|
|
6
6
|
var slice = ArrayProto.slice;
|
|
7
7
|
var toString = ObjProto.toString;
|
|
8
8
|
var nativeForEach = ArrayProto.forEach;
|
|
9
|
+
var nativeIsArray = Array.isArray;
|
|
9
10
|
var breaker = false;
|
|
10
11
|
export var isArguments = function isArguments(obj) {
|
|
11
12
|
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
|
@@ -46,6 +47,13 @@ export var values = function values(obj) {
|
|
|
46
47
|
export function round(num, decimals) {
|
|
47
48
|
return +num.toFixed(decimals);
|
|
48
49
|
}
|
|
50
|
+
export function toServerDuration(duration) {
|
|
51
|
+
if (!isNumber(duration)) {
|
|
52
|
+
return duration;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return round(duration * 1e6, 0);
|
|
56
|
+
}
|
|
49
57
|
export function msToNs(duration) {
|
|
50
58
|
if (typeof duration !== 'number') {
|
|
51
59
|
return duration;
|
|
@@ -68,6 +76,9 @@ export var isBoolean = function isBoolean(obj) {
|
|
|
68
76
|
export var isNumber = function isNumber(obj) {
|
|
69
77
|
return toString.call(obj) === '[object Number]' && /[\d\.]+/.test(String(obj));
|
|
70
78
|
};
|
|
79
|
+
export var isArray = nativeIsArray || function (obj) {
|
|
80
|
+
return toString.call(obj) === '[object Array]';
|
|
81
|
+
};
|
|
71
82
|
export var toArray = function toArray(iterable) {
|
|
72
83
|
if (!iterable) return [];
|
|
73
84
|
|
|
@@ -149,6 +160,92 @@ export function jsonStringify(value, replacer, space) {
|
|
|
149
160
|
|
|
150
161
|
return result;
|
|
151
162
|
}
|
|
163
|
+
export var utf8Encode = function utf8Encode(string) {
|
|
164
|
+
string = (string + '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
165
|
+
var utftext = '',
|
|
166
|
+
start,
|
|
167
|
+
end;
|
|
168
|
+
var stringl = 0,
|
|
169
|
+
n;
|
|
170
|
+
start = end = 0;
|
|
171
|
+
stringl = string.length;
|
|
172
|
+
|
|
173
|
+
for (n = 0; n < stringl; n++) {
|
|
174
|
+
var c1 = string.charCodeAt(n);
|
|
175
|
+
var enc = null;
|
|
176
|
+
|
|
177
|
+
if (c1 < 128) {
|
|
178
|
+
end++;
|
|
179
|
+
} else if (c1 > 127 && c1 < 2048) {
|
|
180
|
+
enc = String.fromCharCode(c1 >> 6 | 192, c1 & 63 | 128);
|
|
181
|
+
} else {
|
|
182
|
+
enc = String.fromCharCode(c1 >> 12 | 224, c1 >> 6 & 63 | 128, c1 & 63 | 128);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (enc !== null) {
|
|
186
|
+
if (end > start) {
|
|
187
|
+
utftext += string.substring(start, end);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
utftext += enc;
|
|
191
|
+
start = end = n + 1;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (end > start) {
|
|
196
|
+
utftext += string.substring(start, string.length);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return utftext;
|
|
200
|
+
};
|
|
201
|
+
export var base64Encode = function base64Encode(data) {
|
|
202
|
+
data = String(data);
|
|
203
|
+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
204
|
+
var o1,
|
|
205
|
+
o2,
|
|
206
|
+
o3,
|
|
207
|
+
h1,
|
|
208
|
+
h2,
|
|
209
|
+
h3,
|
|
210
|
+
h4,
|
|
211
|
+
bits,
|
|
212
|
+
i = 0,
|
|
213
|
+
ac = 0,
|
|
214
|
+
enc = '',
|
|
215
|
+
tmp_arr = [];
|
|
216
|
+
|
|
217
|
+
if (!data) {
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
data = utf8Encode(data);
|
|
222
|
+
|
|
223
|
+
do {
|
|
224
|
+
o1 = data.charCodeAt(i++);
|
|
225
|
+
o2 = data.charCodeAt(i++);
|
|
226
|
+
o3 = data.charCodeAt(i++);
|
|
227
|
+
bits = o1 << 16 | o2 << 8 | o3;
|
|
228
|
+
h1 = bits >> 18 & 0x3f;
|
|
229
|
+
h2 = bits >> 12 & 0x3f;
|
|
230
|
+
h3 = bits >> 6 & 0x3f;
|
|
231
|
+
h4 = bits & 0x3f;
|
|
232
|
+
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
|
|
233
|
+
} while (i < data.length);
|
|
234
|
+
|
|
235
|
+
enc = tmp_arr.join('');
|
|
236
|
+
|
|
237
|
+
switch (data.length % 3) {
|
|
238
|
+
case 1:
|
|
239
|
+
enc = enc.slice(0, -2) + '==';
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case 2:
|
|
243
|
+
enc = enc.slice(0, -1) + '=';
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return enc;
|
|
248
|
+
};
|
|
152
249
|
|
|
153
250
|
function hasToJSON(value) {
|
|
154
251
|
return typeof value === 'object' && value !== null && value.hasOwnProperty('toJSON');
|
|
@@ -376,7 +473,12 @@ export function toSnakeCase(word) {
|
|
|
376
473
|
}).replace(/-/g, '_');
|
|
377
474
|
}
|
|
378
475
|
export function escapeRowData(str) {
|
|
379
|
-
if (
|
|
476
|
+
if (typeof str === 'object' && str) {
|
|
477
|
+
str = jsonStringify(str);
|
|
478
|
+
} else if (!isString(str)) {
|
|
479
|
+
return str;
|
|
480
|
+
}
|
|
481
|
+
|
|
380
482
|
var reg = /[\s=,"]/g;
|
|
381
483
|
return String(str).replace(reg, function (word) {
|
|
382
484
|
return '\\' + word;
|
|
@@ -446,8 +548,8 @@ export var urlParse = function urlParse(para) {
|
|
|
446
548
|
|
|
447
549
|
URLParser.prototype.getUrl = function () {
|
|
448
550
|
var url = '';
|
|
449
|
-
url += this._values.Origin;
|
|
450
|
-
|
|
551
|
+
url += this._values.Origin; // url += this._values.Port ? ':' + this._values.Port : ''
|
|
552
|
+
|
|
451
553
|
url += this._values.Path;
|
|
452
554
|
url += this._values.QueryString ? '?' + this._values.QueryString : '';
|
|
453
555
|
return url;
|
|
@@ -468,8 +570,9 @@ export var urlParse = function urlParse(para) {
|
|
|
468
570
|
}
|
|
469
571
|
}
|
|
470
572
|
|
|
573
|
+
this._values['Path'] = this._values['Path'] || '/';
|
|
471
574
|
this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '');
|
|
472
|
-
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'];
|
|
575
|
+
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'] + (this._values.Port ? ':' + this._values.Port : '');
|
|
473
576
|
};
|
|
474
577
|
|
|
475
578
|
return new URLParser(para);
|
|
@@ -525,4 +628,41 @@ export var deepMixObject = function deepMixObject(targetObj) {
|
|
|
525
628
|
}
|
|
526
629
|
|
|
527
630
|
return targetObj;
|
|
528
|
-
};
|
|
631
|
+
};
|
|
632
|
+
export function getOrigin(url) {
|
|
633
|
+
return urlParse(url).getParse().Origin;
|
|
634
|
+
}
|
|
635
|
+
export function createContextManager() {
|
|
636
|
+
var context = {};
|
|
637
|
+
return {
|
|
638
|
+
get: function get() {
|
|
639
|
+
return context;
|
|
640
|
+
},
|
|
641
|
+
add: function add(key, value) {
|
|
642
|
+
if (isString(key)) {
|
|
643
|
+
context[key] = value;
|
|
644
|
+
} else {
|
|
645
|
+
console.error('key 需要传递字符串类型');
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
remove: function remove(key) {
|
|
649
|
+
delete context[key];
|
|
650
|
+
},
|
|
651
|
+
set: function set(newContext) {
|
|
652
|
+
if (isObject(newContext)) {
|
|
653
|
+
context = newContext;
|
|
654
|
+
} else {
|
|
655
|
+
console.error('content 需要传递对象类型数据');
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
export function getActivePage() {
|
|
661
|
+
var curPages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
|
|
662
|
+
|
|
663
|
+
if (curPages.length) {
|
|
664
|
+
return curPages[curPages.length - 1];
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
return {};
|
|
668
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extend2Lev, withSnakeCaseKeys, performDraw } from '../helper/utils';
|
|
1
|
+
import { extend2Lev, withSnakeCaseKeys, performDraw, isEmptyObject } from '../helper/utils';
|
|
2
2
|
import { LifeCycleEventType } from '../core/lifeCycle';
|
|
3
3
|
import { RumEventType } from '../helper/enums';
|
|
4
4
|
import baseInfo from '../core/baseInfo';
|
|
@@ -11,17 +11,20 @@ var SessionType = {
|
|
|
11
11
|
SYNTHETICS: 'synthetics',
|
|
12
12
|
USER: 'user'
|
|
13
13
|
};
|
|
14
|
-
export function startRumAssembly(applicationId, configuration, lifeCycle, parentContexts) {
|
|
14
|
+
export function startRumAssembly(applicationId, configuration, lifeCycle, parentContexts, getCommonContext) {
|
|
15
15
|
lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (data) {
|
|
16
16
|
var startTime = data.startTime;
|
|
17
17
|
var rawRumEvent = data.rawRumEvent;
|
|
18
18
|
var viewContext = parentContexts.findView(startTime);
|
|
19
|
+
var savedCommonContext = data.savedGlobalContext;
|
|
20
|
+
var customerContext = data.customerContext;
|
|
19
21
|
var deviceContext = {
|
|
20
22
|
device: baseInfo.deviceInfo
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
if (isTracked(configuration) && (viewContext || rawRumEvent.type === RumEventType.APP)) {
|
|
24
26
|
var actionContext = parentContexts.findAction(startTime);
|
|
27
|
+
var commonContext = savedCommonContext || getCommonContext();
|
|
25
28
|
var rumContext = {
|
|
26
29
|
_dd: {
|
|
27
30
|
sdkName: configuration.sdkName,
|
|
@@ -40,12 +43,26 @@ export function startRumAssembly(applicationId, configuration, lifeCycle, parent
|
|
|
40
43
|
type: SessionType.USER
|
|
41
44
|
},
|
|
42
45
|
user: {
|
|
43
|
-
|
|
46
|
+
id: configuration.user_id || baseInfo.getClientID(),
|
|
44
47
|
is_signin: configuration.user_id ? 'T' : 'F'
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
50
|
var rumEvent = extend2Lev(rumContext, deviceContext, viewContext, actionContext, rawRumEvent);
|
|
48
51
|
var serverRumEvent = withSnakeCaseKeys(rumEvent);
|
|
52
|
+
var context = extend2Lev(commonContext.context, customerContext);
|
|
53
|
+
|
|
54
|
+
if (!isEmptyObject(context)) {
|
|
55
|
+
serverRumEvent.tags = context;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!isEmptyObject(commonContext.user)) {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
60
|
+
serverRumEvent.user = extend2Lev({
|
|
61
|
+
id: baseInfo.getClientID(),
|
|
62
|
+
is_signin: 'T'
|
|
63
|
+
}, commonContext.user);
|
|
64
|
+
}
|
|
65
|
+
|
|
49
66
|
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
|
|
50
67
|
}
|
|
51
68
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extend, now, throttle, UUID, isNumber } from '../../helper/utils';
|
|
1
|
+
import { extend, now, throttle, UUID, isNumber, getActivePage } from '../../helper/utils';
|
|
2
2
|
import { trackEventCounts } from '../trackEventCounts';
|
|
3
3
|
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
4
4
|
import { sdk } from '../../core/sdk'; // 劫持原小程序App方法
|
|
@@ -213,14 +213,4 @@ function trackSetDataTime(lifeCycle, callback) {
|
|
|
213
213
|
return {
|
|
214
214
|
stop: subscribe.unsubscribe
|
|
215
215
|
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function getActivePage() {
|
|
219
|
-
var curPages = getCurrentPages();
|
|
220
|
-
|
|
221
|
-
if (curPages.length) {
|
|
222
|
-
return curPages[curPages.length - 1];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return {};
|
|
226
216
|
}
|
|
@@ -3,9 +3,11 @@ import { startDownloadProxy } from '../core/downloadProxy';
|
|
|
3
3
|
import { LifeCycleEventType } from '../core/lifeCycle';
|
|
4
4
|
import { isObject } from '../helper/utils';
|
|
5
5
|
import { isAllowedRequestUrl } from '../rumEventsCollection/resource/resourceUtils';
|
|
6
|
+
import { startTracer } from '../rumEventsCollection/tracing/tracer';
|
|
6
7
|
var nextRequestIndex = 1;
|
|
7
8
|
export function startRequestCollection(lifeCycle, configuration) {
|
|
8
|
-
|
|
9
|
+
var tracer = startTracer(configuration);
|
|
10
|
+
trackXhr(lifeCycle, configuration, tracer);
|
|
9
11
|
trackDownload(lifeCycle, configuration);
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -28,10 +30,11 @@ function getHeaderString(header) {
|
|
|
28
30
|
return headerStr;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
export function trackXhr(lifeCycle, configuration) {
|
|
33
|
+
export function trackXhr(lifeCycle, configuration, tracer) {
|
|
32
34
|
var xhrProxy = startXhrProxy();
|
|
33
35
|
xhrProxy.beforeSend(function (context) {
|
|
34
36
|
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
37
|
+
tracer.traceXhr(context);
|
|
35
38
|
context.requestIndex = getNextRequestIndex();
|
|
36
39
|
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, {
|
|
37
40
|
requestIndex: context.requestIndex
|
|
@@ -40,6 +43,7 @@ export function trackXhr(lifeCycle, configuration) {
|
|
|
40
43
|
});
|
|
41
44
|
xhrProxy.onRequestComplete(function (context) {
|
|
42
45
|
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
46
|
+
tracer.clearTracingIfCancelled(context);
|
|
43
47
|
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
|
|
44
48
|
duration: context.duration,
|
|
45
49
|
method: context.method,
|
|
@@ -48,6 +52,8 @@ export function trackXhr(lifeCycle, configuration) {
|
|
|
48
52
|
response: context.response,
|
|
49
53
|
startTime: context.startTime,
|
|
50
54
|
status: context.status,
|
|
55
|
+
traceId: context.traceId,
|
|
56
|
+
spanId: context.spanId,
|
|
51
57
|
type: context.type,
|
|
52
58
|
url: context.url
|
|
53
59
|
});
|