@cloudcare/browser-core 2.0.9 → 2.0.11

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.
@@ -9,27 +9,30 @@ exports.isIntakeRequest = isIntakeRequest;
9
9
  var _tools = require("../helper/tools");
10
10
 
11
11
  var TRIM_REGIX = /^\s+|\s+$/g;
12
+ var typeMap = {
13
+ rum: '/rum',
14
+ log: '/logging',
15
+ sessionReplay: '/rum/replay'
16
+ };
17
+
18
+ function getEndPointUrl(url, type) {
19
+ // type: rum, log,replay
20
+ var subUrl = typeMap[type];
21
+ if (!subUrl) return '';
22
+
23
+ if (url.indexOf('/') === 0) {
24
+ // 绝对路径这种 /xxx
25
+ url = location.origin + trim(url);
26
+ }
12
27
 
13
- function getDatakitUrl(url) {
14
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum';
15
- return trim(url) + '/v1/write/rum';
28
+ if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write' + subUrl;
29
+ return trim(url) + '/v1/write' + subUrl;
16
30
  }
17
31
 
18
32
  function trim(str) {
19
33
  return str.replace(TRIM_REGIX, '');
20
34
  }
21
35
 
22
- function getLogsEndPoint(url) {
23
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/logging';
24
- return trim(url) + '/v1/write/logging';
25
- }
26
-
27
- function getSessionReplayEndPoint(url) {
28
- // return 'http://localhost:3002/write_data'
29
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum/replay';
30
- return trim(url) + '/v1/write/rum/replay';
31
- }
32
-
33
36
  function computeTransportConfiguration(initConfiguration) {
34
37
  var isIntakeUrl = function isIntakeUrl(url) {
35
38
  return false;
@@ -48,9 +51,9 @@ function computeTransportConfiguration(initConfiguration) {
48
51
  }
49
52
 
50
53
  return {
51
- datakitUrl: getDatakitUrl(initConfiguration.datakitUrl || initConfiguration.datakitOrigin),
52
- logsEndpoint: getLogsEndPoint(initConfiguration.datakitOrigin),
53
- sessionReplayEndPoint: getSessionReplayEndPoint(initConfiguration.datakitOrigin),
54
+ datakitUrl: getEndPointUrl(initConfiguration.datakitUrl || initConfiguration.datakitOrigin, 'rum'),
55
+ logsEndpoint: getEndPointUrl(initConfiguration.datakitOrigin, 'log'),
56
+ sessionReplayEndPoint: getEndPointUrl(initConfiguration.datakitOrigin, 'sessionReplay'),
54
57
  isIntakeUrl: isIntakeUrl,
55
58
  isServerError: isServerError
56
59
  };
@@ -62,6 +65,10 @@ function isIntakeRequest(url, configuration) {
62
65
 
63
66
  if (configuration.logsEndpoint) {
64
67
  notTakeRequest.push(configuration.logsEndpoint);
68
+ }
69
+
70
+ if (configuration.sessionReplayEndPoint) {
71
+ notTakeRequest.push(configuration.sessionReplayEndPoint);
65
72
  } // datakit 地址,log 地址,以及客户自定义过滤方法定义url
66
73
 
67
74
 
package/cjs/dataMap.js CHANGED
@@ -53,10 +53,10 @@ var dataMap = {
53
53
  type: _enums.RumEventType.VIEW,
54
54
  tags: {
55
55
  view_loading_type: 'view.loading_type',
56
- view_apdex_level: 'view.apdex_level',
57
- is_active: 'view.is_active'
56
+ view_apdex_level: 'view.apdex_level'
58
57
  },
59
58
  fields: {
59
+ is_active: 'view.is_active',
60
60
  session_replay_stats: '_dd.replay_stats',
61
61
  session_is_active: 'session.is_active',
62
62
  view_error_count: 'view.error.count',
@@ -73,7 +73,6 @@ var dataMap = {
73
73
  dom_complete: 'view.dom_complete',
74
74
  load_event: 'view.load_event',
75
75
  first_input_time: 'view.first_input_time',
76
- first_meaningful_paint: 'view.largest_contentful_paint',
77
76
  first_paint_time: 'view.fpt',
78
77
  resource_load_time: 'view.resource_load_time',
79
78
  time_to_interactive: 'view.tti',
@@ -57,21 +57,14 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
57
57
  var fields = (0, _tools.extend)({}, _dataMap.commonFields, value.fields);
58
58
  (0, _tools.each)(fields, function (_value, _key) {
59
59
  if ((0, _tools.isArray)(_value) && _value.length === 2) {
60
- var type = _value[0],
61
- value_path = _value[1];
60
+ var value_path = _value[1];
62
61
 
63
62
  var _valueData = (0, _tools.findByPath)(message, value_path);
64
63
 
65
64
  filterFileds.push(_key);
66
65
 
67
- if (_valueData || (0, _tools.isNumber)(_valueData)) {
66
+ if (_valueData !== undefined && _valueData !== null) {
68
67
  rowData.fields[_key] = _valueData; // 这里不需要转译
69
- // _valueData =
70
- // type === 'string'
71
- // ? '"' +
72
- // _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
73
- // '"'
74
- // : escapeRowData(_valueData)
75
68
 
76
69
  fieldsStr.push((0, _rowData.escapeRowData)(_key) + '=' + (0, _rowData.escapeRowField)(_valueData));
77
70
  }
@@ -80,7 +73,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
80
73
 
81
74
  filterFileds.push(_key);
82
75
 
83
- if (_valueData || (0, _tools.isNumber)(_valueData)) {
76
+ if (_valueData !== undefined && _valueData !== null) {
84
77
  rowData.fields[_key] = _valueData; // 这里不需要转译
85
78
 
86
79
  fieldsStr.push((0, _rowData.escapeRowData)(_key) + '=' + (0, _rowData.escapeRowField)(_valueData));
@@ -96,7 +89,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
96
89
  if (filterFileds.indexOf(_key) > -1) return;
97
90
  filterFileds.push(_key);
98
91
 
99
- if (_value || (0, _tools.isNumber)(_value)) {
92
+ if (_value !== undefined && _value !== null) {
100
93
  _tagKeys.push(_key);
101
94
 
102
95
  rowData.fields[_key] = _value; // 这里不需要转译
@@ -114,7 +107,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
114
107
  if (message.type === _enums.RumEventType.LOGGER) {
115
108
  // 这里处理日志类型数据自定义字段
116
109
  (0, _tools.each)(message, function (value, key) {
117
- if (filterFileds.indexOf(key) === -1 && ((0, _tools.isNumber)(value) || value)) {
110
+ if (filterFileds.indexOf(key) === -1 && value !== undefined && value !== null) {
118
111
  rowData.fields[key] = value; // 这里不需要转译
119
112
 
120
113
  fieldsStr.push((0, _rowData.escapeRowData)(key) + '=' + (0, _rowData.escapeRowField)(value));
@@ -1,24 +1,27 @@
1
1
  import { isFunction, isBoolean, some } from '../helper/tools';
2
2
  var TRIM_REGIX = /^\s+|\s+$/g;
3
+ var typeMap = {
4
+ rum: '/rum',
5
+ log: '/logging',
6
+ sessionReplay: '/rum/replay'
7
+ };
3
8
 
4
- function getDatakitUrl(url) {
5
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum';
6
- return trim(url) + '/v1/write/rum';
7
- }
9
+ function getEndPointUrl(url, type) {
10
+ // type: rum, log,replay
11
+ var subUrl = typeMap[type];
12
+ if (!subUrl) return '';
8
13
 
9
- function trim(str) {
10
- return str.replace(TRIM_REGIX, '');
11
- }
14
+ if (url.indexOf('/') === 0) {
15
+ // 绝对路径这种 /xxx
16
+ url = location.origin + trim(url);
17
+ }
12
18
 
13
- function getLogsEndPoint(url) {
14
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/logging';
15
- return trim(url) + '/v1/write/logging';
19
+ if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write' + subUrl;
20
+ return trim(url) + '/v1/write' + subUrl;
16
21
  }
17
22
 
18
- function getSessionReplayEndPoint(url) {
19
- // return 'http://localhost:3002/write_data'
20
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum/replay';
21
- return trim(url) + '/v1/write/rum/replay';
23
+ function trim(str) {
24
+ return str.replace(TRIM_REGIX, '');
22
25
  }
23
26
 
24
27
  export function computeTransportConfiguration(initConfiguration) {
@@ -39,9 +42,9 @@ export function computeTransportConfiguration(initConfiguration) {
39
42
  }
40
43
 
41
44
  return {
42
- datakitUrl: getDatakitUrl(initConfiguration.datakitUrl || initConfiguration.datakitOrigin),
43
- logsEndpoint: getLogsEndPoint(initConfiguration.datakitOrigin),
44
- sessionReplayEndPoint: getSessionReplayEndPoint(initConfiguration.datakitOrigin),
45
+ datakitUrl: getEndPointUrl(initConfiguration.datakitUrl || initConfiguration.datakitOrigin, 'rum'),
46
+ logsEndpoint: getEndPointUrl(initConfiguration.datakitOrigin, 'log'),
47
+ sessionReplayEndPoint: getEndPointUrl(initConfiguration.datakitOrigin, 'sessionReplay'),
45
48
  isIntakeUrl: isIntakeUrl,
46
49
  isServerError: isServerError
47
50
  };
@@ -52,6 +55,10 @@ export function isIntakeRequest(url, configuration) {
52
55
 
53
56
  if (configuration.logsEndpoint) {
54
57
  notTakeRequest.push(configuration.logsEndpoint);
58
+ }
59
+
60
+ if (configuration.sessionReplayEndPoint) {
61
+ notTakeRequest.push(configuration.sessionReplayEndPoint);
55
62
  } // datakit 地址,log 地址,以及客户自定义过滤方法定义url
56
63
 
57
64
 
package/esm/dataMap.js CHANGED
@@ -43,10 +43,10 @@ export var dataMap = {
43
43
  type: RumEventType.VIEW,
44
44
  tags: {
45
45
  view_loading_type: 'view.loading_type',
46
- view_apdex_level: 'view.apdex_level',
47
- is_active: 'view.is_active'
46
+ view_apdex_level: 'view.apdex_level'
48
47
  },
49
48
  fields: {
49
+ is_active: 'view.is_active',
50
50
  session_replay_stats: '_dd.replay_stats',
51
51
  session_is_active: 'session.is_active',
52
52
  view_error_count: 'view.error.count',
@@ -63,7 +63,6 @@ export var dataMap = {
63
63
  dom_complete: 'view.dom_complete',
64
64
  load_event: 'view.load_event',
65
65
  first_input_time: 'view.first_input_time',
66
- first_meaningful_paint: 'view.largest_contentful_paint',
67
66
  first_paint_time: 'view.fpt',
68
67
  resource_load_time: 'view.resource_load_time',
69
68
  time_to_interactive: 'view.tti',
@@ -42,21 +42,14 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
42
42
  var fields = extend({}, commonFields, value.fields);
43
43
  each(fields, function (_value, _key) {
44
44
  if (isArray(_value) && _value.length === 2) {
45
- var type = _value[0],
46
- value_path = _value[1];
45
+ var value_path = _value[1];
47
46
 
48
47
  var _valueData = findByPath(message, value_path);
49
48
 
50
49
  filterFileds.push(_key);
51
50
 
52
- if (_valueData || isNumber(_valueData)) {
51
+ if (_valueData !== undefined && _valueData !== null) {
53
52
  rowData.fields[_key] = _valueData; // 这里不需要转译
54
- // _valueData =
55
- // type === 'string'
56
- // ? '"' +
57
- // _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
58
- // '"'
59
- // : escapeRowData(_valueData)
60
53
 
61
54
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
62
55
  }
@@ -65,7 +58,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
65
58
 
66
59
  filterFileds.push(_key);
67
60
 
68
- if (_valueData || isNumber(_valueData)) {
61
+ if (_valueData !== undefined && _valueData !== null) {
69
62
  rowData.fields[_key] = _valueData; // 这里不需要转译
70
63
 
71
64
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
@@ -81,7 +74,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
81
74
  if (filterFileds.indexOf(_key) > -1) return;
82
75
  filterFileds.push(_key);
83
76
 
84
- if (_value || isNumber(_value)) {
77
+ if (_value !== undefined && _value !== null) {
85
78
  _tagKeys.push(_key);
86
79
 
87
80
  rowData.fields[_key] = _value; // 这里不需要转译
@@ -99,7 +92,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
99
92
  if (message.type === RumEventType.LOGGER) {
100
93
  // 这里处理日志类型数据自定义字段
101
94
  each(message, function (value, key) {
102
- if (filterFileds.indexOf(key) === -1 && (isNumber(value) || value)) {
95
+ if (filterFileds.indexOf(key) === -1 && value !== undefined && value !== null) {
103
96
  rowData.fields[key] = value; // 这里不需要转译
104
97
 
105
98
  fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "scripts": {
@@ -20,5 +20,5 @@
20
20
  "author": "dataflux",
21
21
  "license": "MIT",
22
22
  "description": "DataFlux RUM Web 端数据指标监控",
23
- "gitHead": "ad44c611b98f97c4a115d281f0a91a4c7f260081"
23
+ "gitHead": "3419a0f49ffef058ceff8e94bc8f01274575988a"
24
24
  }
@@ -1,23 +1,27 @@
1
1
  import { isFunction, isBoolean, some } from '../helper/tools'
2
2
  var TRIM_REGIX = /^\s+|\s+$/g
3
- function getDatakitUrl(url) {
4
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum'
5
- return trim(url) + '/v1/write/rum'
3
+ var typeMap = {
4
+ rum: '/rum',
5
+ log: '/logging',
6
+ sessionReplay: '/rum/replay'
6
7
  }
7
- function trim(str) {
8
- return str.replace(TRIM_REGIX, '')
9
- }
10
- function getLogsEndPoint(url) {
8
+ function getEndPointUrl(url, type) {
9
+ // type: rum, log,replay
10
+ var subUrl = typeMap[type]
11
+ if (!subUrl) return ''
12
+ if (url.indexOf('/') === 0) {
13
+ // 绝对路径这种 /xxx
14
+ url = location.origin + trim(url)
15
+ }
11
16
  if (url.lastIndexOf('/') === url.length - 1)
12
- return trim(url) + 'v1/write/logging'
13
- return trim(url) + '/v1/write/logging'
17
+ return trim(url) + 'v1/write' + subUrl
18
+ return trim(url) + '/v1/write' + subUrl
14
19
  }
15
- function getSessionReplayEndPoint(url) {
16
- // return 'http://localhost:3002/write_data'
17
- if (url.lastIndexOf('/') === url.length - 1)
18
- return trim(url) + 'v1/write/rum/replay'
19
- return trim(url) + '/v1/write/rum/replay'
20
+
21
+ function trim(str) {
22
+ return str.replace(TRIM_REGIX, '')
20
23
  }
24
+
21
25
  export function computeTransportConfiguration(initConfiguration) {
22
26
  var isIntakeUrl = function (url) {
23
27
  return false
@@ -40,12 +44,14 @@ export function computeTransportConfiguration(initConfiguration) {
40
44
  isServerError = initConfiguration.isServerError
41
45
  }
42
46
  return {
43
- datakitUrl: getDatakitUrl(
44
- initConfiguration.datakitUrl || initConfiguration.datakitOrigin
47
+ datakitUrl: getEndPointUrl(
48
+ initConfiguration.datakitUrl || initConfiguration.datakitOrigin,
49
+ 'rum'
45
50
  ),
46
- logsEndpoint: getLogsEndPoint(initConfiguration.datakitOrigin),
47
- sessionReplayEndPoint: getSessionReplayEndPoint(
48
- initConfiguration.datakitOrigin
51
+ logsEndpoint: getEndPointUrl(initConfiguration.datakitOrigin, 'log'),
52
+ sessionReplayEndPoint: getEndPointUrl(
53
+ initConfiguration.datakitOrigin,
54
+ 'sessionReplay'
49
55
  ),
50
56
  isIntakeUrl: isIntakeUrl,
51
57
  isServerError: isServerError
@@ -57,6 +63,9 @@ export function isIntakeRequest(url, configuration) {
57
63
  if (configuration.logsEndpoint) {
58
64
  notTakeRequest.push(configuration.logsEndpoint)
59
65
  }
66
+ if (configuration.sessionReplayEndPoint) {
67
+ notTakeRequest.push(configuration.sessionReplayEndPoint)
68
+ }
60
69
  // datakit 地址,log 地址,以及客户自定义过滤方法定义url
61
70
  return (
62
71
  some(notTakeRequest, function (takeUrl) {
package/src/dataMap.js CHANGED
@@ -42,10 +42,10 @@ export var dataMap = {
42
42
  type: RumEventType.VIEW,
43
43
  tags: {
44
44
  view_loading_type: 'view.loading_type',
45
- view_apdex_level: 'view.apdex_level',
46
- is_active: 'view.is_active'
45
+ view_apdex_level: 'view.apdex_level'
47
46
  },
48
47
  fields: {
48
+ is_active: 'view.is_active',
49
49
  session_replay_stats: '_dd.replay_stats',
50
50
  session_is_active: 'session.is_active',
51
51
  view_error_count: 'view.error.count',
@@ -62,7 +62,6 @@ export var dataMap = {
62
62
  dom_complete: 'view.dom_complete',
63
63
  load_event: 'view.load_event',
64
64
  first_input_time: 'view.first_input_time',
65
- first_meaningful_paint: 'view.largest_contentful_paint',
66
65
  first_paint_time: 'view.fpt',
67
66
  resource_load_time: 'view.resource_load_time',
68
67
  time_to_interactive: 'view.tti',
@@ -55,18 +55,11 @@ export var processedMessageByDataMap = function (message) {
55
55
  var fields = extend({}, commonFields, value.fields)
56
56
  each(fields, function (_value, _key) {
57
57
  if (isArray(_value) && _value.length === 2) {
58
- var type = _value[0],
59
- value_path = _value[1]
58
+ var value_path = _value[1]
60
59
  var _valueData = findByPath(message, value_path)
61
60
  filterFileds.push(_key)
62
- if (_valueData || isNumber(_valueData)) {
61
+ if (_valueData !== undefined && _valueData !== null) {
63
62
  rowData.fields[_key] = _valueData // 这里不需要转译
64
- // _valueData =
65
- // type === 'string'
66
- // ? '"' +
67
- // _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
68
- // '"'
69
- // : escapeRowData(_valueData)
70
63
  fieldsStr.push(
71
64
  escapeRowData(_key) + '=' + escapeRowField(_valueData)
72
65
  )
@@ -74,7 +67,7 @@ export var processedMessageByDataMap = function (message) {
74
67
  } else if (isString(_value)) {
75
68
  var _valueData = findByPath(message, _value)
76
69
  filterFileds.push(_key)
77
- if (_valueData || isNumber(_valueData)) {
70
+ if (_valueData !== undefined && _valueData !== null) {
78
71
  rowData.fields[_key] = _valueData // 这里不需要转译
79
72
  fieldsStr.push(
80
73
  escapeRowData(_key) + '=' + escapeRowField(_valueData)
@@ -93,7 +86,7 @@ export var processedMessageByDataMap = function (message) {
93
86
  // 如果和之前tag重名,则舍弃
94
87
  if (filterFileds.indexOf(_key) > -1) return
95
88
  filterFileds.push(_key)
96
- if (_value || isNumber(_value)) {
89
+ if (_value !== undefined && _value !== null) {
97
90
  _tagKeys.push(_key)
98
91
  rowData.fields[_key] = _value // 这里不需要转译
99
92
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value))
@@ -109,7 +102,11 @@ export var processedMessageByDataMap = function (message) {
109
102
  if (message.type === RumEventType.LOGGER) {
110
103
  // 这里处理日志类型数据自定义字段
111
104
  each(message, function (value, key) {
112
- if (filterFileds.indexOf(key) === -1 && (isNumber(value) || value)) {
105
+ if (
106
+ filterFileds.indexOf(key) === -1 &&
107
+ value !== undefined &&
108
+ value !== null
109
+ ) {
113
110
  rowData.fields[key] = value // 这里不需要转译
114
111
  fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value))
115
112
  }