@cloudcare/rum-uniapp 2.1.7 → 2.1.10

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 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`三种类型* |
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildEnv = void 0;
7
7
  var buildEnv = {
8
- sdkVersion: '2.1.7',
8
+ sdkVersion: '2.1.10',
9
9
  sdkName: 'df_uniapp_rum_sdk'
10
10
  };
11
11
  exports.buildEnv = buildEnv;
@@ -57,6 +57,7 @@ function commonInit(userConfiguration, buildEnv) {
57
57
  applicationId: userConfiguration.applicationId,
58
58
  env: userConfiguration.env || '',
59
59
  version: userConfiguration.version || '',
60
+ service: userConfiguration.service || '',
60
61
  sdkVersion: buildEnv.sdkVersion,
61
62
  sdkName: buildEnv.sdkName,
62
63
  datakitUrl: getDatakitUrlUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
@@ -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',
@@ -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,
@@ -68,7 +68,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
68
68
  rowData.measurement = key;
69
69
  var tagsStr = [];
70
70
  var tags = (0, _utils.extend)({}, _dataMap.commonTags, value.tags);
71
- var filterFileds = ['date', 'type']; // 已经在datamap中定义过的fields和tags
71
+ var filterFileds = ['date', 'type', CUSTOM_KEYS]; // 已经在datamap中定义过的fields和tags
72
72
 
73
73
  (0, _utils.each)(tags, function (value_path, _key) {
74
74
  var _value = (0, _utils.findByPath)(message, value_path);
@@ -76,13 +76,13 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
76
76
  filterFileds.push(_key);
77
77
 
78
78
  if (_value || (0, _utils.isNumber)(_value)) {
79
- rowData.tags[_key] = _value;
79
+ rowData.tags[_key] = (0, _utils.escapeJsonValue)(_value);
80
80
  tagsStr.push((0, _utils.escapeRowData)(_key) + '=' + (0, _utils.escapeRowData)(_value));
81
81
  }
82
82
  });
83
83
 
84
84
  if (message.tags && (0, _utils.isObject)(message.tags) && !(0, _utils.isEmptyObject)(message.tags)) {
85
- // 自定义tag
85
+ // 自定义tag, 存储成field
86
86
  var _tagKeys = [];
87
87
  (0, _utils.each)(message.tags, function (_value, _key) {
88
88
  // 如果和之前tag重名,则舍弃
@@ -92,14 +92,15 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
92
92
  if (_value || (0, _utils.isNumber)(_value)) {
93
93
  _tagKeys.push(_key);
94
94
 
95
- rowData.tags[_key] = _value;
96
- tagsStr.push((0, _utils.escapeRowData)(_key) + '=' + (0, _utils.escapeRowData)(_value));
95
+ rowData.fields[_key] = _value; // 这里不需要转译
96
+
97
+ fieldsStr.push((0, _utils.escapeRowData)(_key) + '=' + (0, _utils.escapeRowField)(_value));
97
98
  }
98
99
  });
99
100
 
100
101
  if (_tagKeys.length) {
101
- rowData.tags[CUSTOM_KEYS] = _tagKeys;
102
- tagsStr.push((0, _utils.escapeRowData)(CUSTOM_KEYS) + '=' + (0, _utils.escapeRowData)(_tagKeys));
102
+ rowData.fields[CUSTOM_KEYS] = (0, _utils.escapeRowField)(_tagKeys);
103
+ fieldsStr.push((0, _utils.escapeRowData)(CUSTOM_KEYS) + '=' + (0, _utils.escapeRowField)(_tagKeys));
103
104
  }
104
105
  }
105
106
 
@@ -116,8 +117,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
116
117
  if (_valueData || (0, _utils.isNumber)(_valueData)) {
117
118
  rowData.fields[_key] = _valueData; // 这里不需要转译
118
119
 
119
- _valueData = type === 'string' ? '"' + _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"' : (0, _utils.escapeRowData)(_valueData);
120
- fieldsStr.push((0, _utils.escapeRowData)(_key) + '=' + _valueData);
120
+ fieldsStr.push((0, _utils.escapeRowData)(_key) + '=' + (0, _utils.escapeRowField)(_valueData));
121
121
  }
122
122
  } else if ((0, _utils.isString)(_value)) {
123
123
  var _valueData = (0, _utils.findByPath)(message, _value);
@@ -127,8 +127,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
127
127
  if (_valueData || (0, _utils.isNumber)(_valueData)) {
128
128
  rowData.fields[_key] = _valueData; // 这里不需要转译
129
129
 
130
- _valueData = (0, _utils.escapeRowData)(_valueData);
131
- fieldsStr.push((0, _utils.escapeRowData)(_key) + '=' + _valueData);
130
+ fieldsStr.push((0, _utils.escapeRowData)(_key) + '=' + (0, _utils.escapeRowField)(_valueData));
132
131
  }
133
132
  }
134
133
  });
@@ -20,6 +20,9 @@ exports.withSnakeCaseKeys = withSnakeCaseKeys;
20
20
  exports.deepSnakeCase = deepSnakeCase;
21
21
  exports.toSnakeCase = toSnakeCase;
22
22
  exports.escapeRowData = escapeRowData;
23
+ exports.escapeJsonValue = escapeJsonValue;
24
+ exports.escapeFieldValueStr = escapeFieldValueStr;
25
+ exports.escapeRowField = escapeRowField;
23
26
  exports.getOrigin = getOrigin;
24
27
  exports.createContextManager = createContextManager;
25
28
  exports.getActivePage = getActivePage;
@@ -641,6 +644,28 @@ function escapeRowData(str) {
641
644
  });
642
645
  }
643
646
 
647
+ function escapeJsonValue(value) {
648
+ if (isString(value)) {
649
+ return value;
650
+ } else {
651
+ return jsonStringify(value);
652
+ }
653
+ }
654
+
655
+ function escapeFieldValueStr(str) {
656
+ return '"' + str.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"';
657
+ }
658
+
659
+ function escapeRowField(value) {
660
+ if (_typeof(value) === 'object' && value) {
661
+ return escapeFieldValueStr(jsonStringify(value));
662
+ } else if (isString(value)) {
663
+ return escapeFieldValueStr(value);
664
+ } else {
665
+ return value;
666
+ }
667
+ }
668
+
644
669
  var urlParse = function urlParse(para) {
645
670
  var URLParser = function URLParser(a) {
646
671
  this._fields = {
@@ -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
  }
@@ -41,7 +41,7 @@ DDtraceTracer.prototype = {
41
41
  makeTracingHeaders: function makeTracingHeaders() {
42
42
  return {
43
43
  'x-datadog-origin': 'rum',
44
- // 'x-datadog-parent-id': spanId.toDecimalString(),
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()
@@ -1,4 +1,4 @@
1
1
  export var buildEnv = {
2
- sdkVersion: '2.1.7',
2
+ sdkVersion: '2.1.10',
3
3
  sdkName: 'df_uniapp_rum_sdk'
4
4
  };
@@ -45,6 +45,7 @@ export function commonInit(userConfiguration, buildEnv) {
45
45
  applicationId: userConfiguration.applicationId,
46
46
  env: userConfiguration.env || '',
47
47
  version: userConfiguration.version || '',
48
+ service: userConfiguration.service || '',
48
49
  sdkVersion: buildEnv.sdkVersion,
49
50
  sdkName: buildEnv.sdkName,
50
51
  datakitUrl: getDatakitUrlUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
@@ -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',
@@ -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,
@@ -1,4 +1,4 @@
1
- import { findByPath, escapeRowData, isNumber, each, isString, values, extend, isObject, isEmptyObject, isArray, isBoolean, toServerDuration } from '../helper/utils';
1
+ import { findByPath, escapeRowData, isNumber, each, isString, values, extend, isObject, isEmptyObject, isArray, escapeRowField, escapeJsonValue, toServerDuration } from '../helper/utils';
2
2
  import { sdk } from '../core/sdk';
3
3
  import { LifeCycleEventType } from '../core/lifeCycle';
4
4
  import { commonTags, dataMap } from './dataMap';
@@ -53,7 +53,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
53
53
  rowData.measurement = key;
54
54
  var tagsStr = [];
55
55
  var tags = extend({}, commonTags, value.tags);
56
- var filterFileds = ['date', 'type']; // 已经在datamap中定义过的fields和tags
56
+ var filterFileds = ['date', 'type', CUSTOM_KEYS]; // 已经在datamap中定义过的fields和tags
57
57
 
58
58
  each(tags, function (value_path, _key) {
59
59
  var _value = findByPath(message, value_path);
@@ -61,13 +61,13 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
61
61
  filterFileds.push(_key);
62
62
 
63
63
  if (_value || isNumber(_value)) {
64
- rowData.tags[_key] = _value;
64
+ rowData.tags[_key] = escapeJsonValue(_value);
65
65
  tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
66
66
  }
67
67
  });
68
68
 
69
69
  if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
70
- // 自定义tag
70
+ // 自定义tag, 存储成field
71
71
  var _tagKeys = [];
72
72
  each(message.tags, function (_value, _key) {
73
73
  // 如果和之前tag重名,则舍弃
@@ -77,14 +77,15 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
77
77
  if (_value || isNumber(_value)) {
78
78
  _tagKeys.push(_key);
79
79
 
80
- rowData.tags[_key] = _value;
81
- tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
80
+ rowData.fields[_key] = _value; // 这里不需要转译
81
+
82
+ fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value));
82
83
  }
83
84
  });
84
85
 
85
86
  if (_tagKeys.length) {
86
- rowData.tags[CUSTOM_KEYS] = _tagKeys;
87
- tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys));
87
+ rowData.fields[CUSTOM_KEYS] = escapeRowField(_tagKeys);
88
+ fieldsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowField(_tagKeys));
88
89
  }
89
90
  }
90
91
 
@@ -101,8 +102,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
101
102
  if (_valueData || isNumber(_valueData)) {
102
103
  rowData.fields[_key] = _valueData; // 这里不需要转译
103
104
 
104
- _valueData = type === 'string' ? '"' + _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"' : escapeRowData(_valueData);
105
- fieldsStr.push(escapeRowData(_key) + '=' + _valueData);
105
+ fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
106
106
  }
107
107
  } else if (isString(_value)) {
108
108
  var _valueData = findByPath(message, _value);
@@ -112,8 +112,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
112
112
  if (_valueData || isNumber(_valueData)) {
113
113
  rowData.fields[_key] = _valueData; // 这里不需要转译
114
114
 
115
- _valueData = escapeRowData(_valueData);
116
- fieldsStr.push(escapeRowData(_key) + '=' + _valueData);
115
+ fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
117
116
  }
118
117
  }
119
118
  });
@@ -511,6 +511,25 @@ export function escapeRowData(str) {
511
511
  return '\\' + word;
512
512
  });
513
513
  }
514
+ export function escapeJsonValue(value) {
515
+ if (isString(value)) {
516
+ return value;
517
+ } else {
518
+ return jsonStringify(value);
519
+ }
520
+ }
521
+ export function escapeFieldValueStr(str) {
522
+ return '"' + str.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"';
523
+ }
524
+ export function escapeRowField(value) {
525
+ if (typeof value === 'object' && value) {
526
+ return escapeFieldValueStr(jsonStringify(value));
527
+ } else if (isString(value)) {
528
+ return escapeFieldValueStr(value);
529
+ } else {
530
+ return value;
531
+ }
532
+ }
514
533
  export var urlParse = function urlParse(para) {
515
534
  var URLParser = function URLParser(a) {
516
535
  this._fields = {
@@ -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
  }
@@ -33,7 +33,7 @@ DDtraceTracer.prototype = {
33
33
  makeTracingHeaders: function makeTracingHeaders() {
34
34
  return {
35
35
  'x-datadog-origin': 'rum',
36
- // 'x-datadog-parent-id': spanId.toDecimalString(),
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()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/rum-uniapp",
3
- "version": "2.1.7",
3
+ "version": "2.1.10",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "miniprogram": "cjs",