@arms/rum-core 0.0.23 → 0.0.25-beta.13
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/lib/model/reporter.js +1 -1
- package/lib/model/shell.d.ts +11 -3
- package/lib/model/shell.js +34 -3
- package/lib/types/client.d.ts +12 -1
- package/lib/types/rum-event.d.ts +43 -11
- package/lib/utils/base.d.ts +29 -3
- package/lib/utils/base.js +99 -16
- package/lib/utils/number.d.ts +8 -0
- package/lib/utils/number.js +29 -0
- package/lib/utils/polyfills.js +3 -3
- package/lib/utils/trace.d.ts +0 -2
- package/lib/utils/trace.js +0 -25
- package/package.json +1 -1
package/lib/model/reporter.js
CHANGED
|
@@ -6,7 +6,7 @@ var _rumEvent = require("../types/rum-event");
|
|
|
6
6
|
var _exception = require("../utils/exception");
|
|
7
7
|
var _is = require("../utils/is");
|
|
8
8
|
var FLUSH_TIME = 3000;
|
|
9
|
-
var MAX_EVENT_COUNT =
|
|
9
|
+
var MAX_EVENT_COUNT = 20;
|
|
10
10
|
var Reporter = exports["default"] = /*#__PURE__*/function () {
|
|
11
11
|
function Reporter() {
|
|
12
12
|
this.name = 'reporter';
|
package/lib/model/shell.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IClient, IConfiguration } from "../types/client";
|
|
2
|
-
import { RumEvent } from "../types/rum-event";
|
|
2
|
+
import { RumCustomEvent, RumEvent, RumExceptionEvent, RumResourceEvent } from "../types/rum-event";
|
|
3
3
|
import { IShell } from "../types/shell";
|
|
4
4
|
export default abstract class Shell implements IShell {
|
|
5
5
|
client: IClient;
|
|
@@ -19,7 +19,15 @@ export default abstract class Shell implements IShell {
|
|
|
19
19
|
abstract setConfig<T extends keyof IConfiguration>(key: T, value: IConfiguration[T]): void;
|
|
20
20
|
abstract setConfig(value: IConfiguration): void;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* 自定义事件上报
|
|
23
23
|
*/
|
|
24
|
-
sendCustom(payload:
|
|
24
|
+
sendCustom(payload: RumCustomEvent): void;
|
|
25
|
+
/**
|
|
26
|
+
* 自定义异常上报
|
|
27
|
+
*/
|
|
28
|
+
sendException(payload: RumExceptionEvent): void;
|
|
29
|
+
/**
|
|
30
|
+
* 自定义资源上报
|
|
31
|
+
*/
|
|
32
|
+
sendResource(payload: RumResourceEvent): void;
|
|
25
33
|
}
|
package/lib/model/shell.js
CHANGED
|
@@ -5,11 +5,12 @@ exports.__esModule = true;
|
|
|
5
5
|
exports["default"] = void 0;
|
|
6
6
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
7
|
var _rumEvent = require("../types/rum-event");
|
|
8
|
-
var
|
|
8
|
+
var _client = _interopRequireDefault(require("../model/client"));
|
|
9
|
+
var _is = require("../utils/is");
|
|
9
10
|
var Shell = exports["default"] = /*#__PURE__*/function () {
|
|
10
11
|
function Shell(config) {
|
|
11
12
|
this.client = void 0;
|
|
12
|
-
this.client = new
|
|
13
|
+
this.client = new _client["default"]();
|
|
13
14
|
if (config && this.init) {
|
|
14
15
|
this.init(config);
|
|
15
16
|
}
|
|
@@ -38,7 +39,7 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
|
|
|
38
39
|
* set config
|
|
39
40
|
*/;
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
+
* 自定义事件上报
|
|
42
43
|
*/
|
|
43
44
|
_proto.sendCustom = function sendCustom(payload) {
|
|
44
45
|
if (!payload.name || !payload.type) {
|
|
@@ -49,5 +50,35 @@ var Shell = exports["default"] = /*#__PURE__*/function () {
|
|
|
49
50
|
});
|
|
50
51
|
this.sendEvent(data);
|
|
51
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* 自定义异常上报
|
|
55
|
+
*/
|
|
56
|
+
_proto.sendException = function sendException(payload) {
|
|
57
|
+
if (!payload.name || !payload.message) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
var data = (0, _extends2["default"])({
|
|
61
|
+
times: 1
|
|
62
|
+
}, payload, {
|
|
63
|
+
event_type: _rumEvent.RumEventType.EXCEPTION,
|
|
64
|
+
type: 'custom',
|
|
65
|
+
source: 'custom'
|
|
66
|
+
});
|
|
67
|
+
this.sendEvent(data);
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* 自定义资源上报
|
|
71
|
+
*/
|
|
72
|
+
_proto.sendResource = function sendResource(payload) {
|
|
73
|
+
if (!payload.name || !payload.type || !(0, _is.isNumber)(payload.duration)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
var data = (0, _extends2["default"])({
|
|
77
|
+
times: 1
|
|
78
|
+
}, payload, {
|
|
79
|
+
event_type: _rumEvent.RumEventType.RESOURCE
|
|
80
|
+
});
|
|
81
|
+
this.sendEvent(data);
|
|
82
|
+
};
|
|
52
83
|
return Shell;
|
|
53
84
|
}();
|
package/lib/types/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ICollector } from './collector';
|
|
|
2
2
|
import { IProcessor } from './processor';
|
|
3
3
|
import { IReporter } from './reporter';
|
|
4
4
|
import { RumEvent, RumEventBundle, IViewData } from './rum-event';
|
|
5
|
+
import { MatchOption } from "../utils/match";
|
|
5
6
|
export declare enum EventType {
|
|
6
7
|
/**
|
|
7
8
|
* 收集数据
|
|
@@ -97,6 +98,16 @@ export interface IConfiguration {
|
|
|
97
98
|
/**
|
|
98
99
|
* 各个 collector config
|
|
99
100
|
*/
|
|
100
|
-
collectors?:
|
|
101
|
+
collectors?: {
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 事件过滤器配置
|
|
106
|
+
*/
|
|
107
|
+
filters?: {
|
|
108
|
+
view?: MatchOption | MatchOption[];
|
|
109
|
+
resource?: MatchOption | MatchOption[];
|
|
110
|
+
exception?: MatchOption | MatchOption[];
|
|
111
|
+
};
|
|
101
112
|
[key: string]: any;
|
|
102
113
|
}
|
package/lib/types/rum-event.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface RumBaseEvent {
|
|
|
21
21
|
timestamp?: number;
|
|
22
22
|
times?: number;
|
|
23
23
|
view?: IViewData;
|
|
24
|
+
snapshots?: string;
|
|
24
25
|
[key: string]: BaseObjectValue;
|
|
25
26
|
}
|
|
26
27
|
export interface RumViewEvent extends RumBaseEvent {
|
|
@@ -29,7 +30,9 @@ export interface RumViewEvent extends RumBaseEvent {
|
|
|
29
30
|
largest_contentful_paint?: number;
|
|
30
31
|
first_input_delay?: number;
|
|
31
32
|
cumulative_layout_shift?: number;
|
|
33
|
+
first_input_time?: number;
|
|
32
34
|
loading_time?: number;
|
|
35
|
+
first_paint?: number;
|
|
33
36
|
first_contentful_paint?: number;
|
|
34
37
|
dom_interactive?: number;
|
|
35
38
|
dom_content_loaded?: number;
|
|
@@ -41,14 +44,13 @@ export interface RumViewEvent extends RumBaseEvent {
|
|
|
41
44
|
}
|
|
42
45
|
export interface RumResourceEvent extends RumBaseEvent {
|
|
43
46
|
name?: string;
|
|
44
|
-
type
|
|
47
|
+
type?: string;
|
|
45
48
|
method?: string;
|
|
46
|
-
status_code?: number;
|
|
49
|
+
status_code?: number | string;
|
|
47
50
|
message?: string;
|
|
48
|
-
success
|
|
49
|
-
provider_type?: string;
|
|
51
|
+
success?: -1 | 0 | 1;
|
|
50
52
|
trace_id?: string;
|
|
51
|
-
duration
|
|
53
|
+
duration?: number;
|
|
52
54
|
size?: number;
|
|
53
55
|
connect_duration?: number;
|
|
54
56
|
ssl_duration?: number;
|
|
@@ -56,12 +58,13 @@ export interface RumResourceEvent extends RumBaseEvent {
|
|
|
56
58
|
redirect_duration?: number;
|
|
57
59
|
first_byte_duration?: number;
|
|
58
60
|
download_duration?: number;
|
|
59
|
-
url
|
|
61
|
+
url?: string;
|
|
60
62
|
timing_data?: string;
|
|
63
|
+
tracing_data?: string;
|
|
61
64
|
}
|
|
62
65
|
export interface RumExceptionEvent extends RumBaseEvent {
|
|
63
66
|
source?: string;
|
|
64
|
-
type?: 'crash' | '
|
|
67
|
+
type?: 'crash' | 'custom' | 'error' | 'blank';
|
|
65
68
|
name?: string;
|
|
66
69
|
message?: string;
|
|
67
70
|
file?: string;
|
|
@@ -83,7 +86,6 @@ export interface RumActionEvent extends RumBaseEvent {
|
|
|
83
86
|
name?: string;
|
|
84
87
|
target_name?: string;
|
|
85
88
|
duration?: number;
|
|
86
|
-
snapshots?: string;
|
|
87
89
|
}
|
|
88
90
|
export interface RumCustomEvent extends RumBaseEvent {
|
|
89
91
|
type: string;
|
|
@@ -99,9 +101,12 @@ export declare enum AppType {
|
|
|
99
101
|
export interface RumEventBundle {
|
|
100
102
|
app: {
|
|
101
103
|
id: string;
|
|
102
|
-
env?: string;
|
|
103
|
-
version?: string;
|
|
104
104
|
type: AppType;
|
|
105
|
+
name?: string;
|
|
106
|
+
version?: string;
|
|
107
|
+
channel?: string;
|
|
108
|
+
env?: string;
|
|
109
|
+
package?: string;
|
|
105
110
|
};
|
|
106
111
|
user: {
|
|
107
112
|
id: string;
|
|
@@ -115,8 +120,35 @@ export interface RumEventBundle {
|
|
|
115
120
|
id: string;
|
|
116
121
|
name: string;
|
|
117
122
|
};
|
|
123
|
+
device?: {
|
|
124
|
+
id?: string;
|
|
125
|
+
type?: string;
|
|
126
|
+
brand?: string;
|
|
127
|
+
model?: string;
|
|
128
|
+
name?: string;
|
|
129
|
+
};
|
|
130
|
+
os?: {
|
|
131
|
+
type?: string;
|
|
132
|
+
version?: string;
|
|
133
|
+
container?: string;
|
|
134
|
+
container_version?: string;
|
|
135
|
+
};
|
|
136
|
+
geo?: {
|
|
137
|
+
country?: string;
|
|
138
|
+
country_id?: string;
|
|
139
|
+
province?: string;
|
|
140
|
+
province_id?: string;
|
|
141
|
+
city?: string;
|
|
142
|
+
city_id?: string;
|
|
143
|
+
};
|
|
144
|
+
isp?: {
|
|
145
|
+
id?: string;
|
|
146
|
+
name?: string;
|
|
147
|
+
};
|
|
118
148
|
net?: {
|
|
119
|
-
model
|
|
149
|
+
model?: string;
|
|
150
|
+
name?: string;
|
|
120
151
|
};
|
|
121
152
|
events: Array<RumEvent>;
|
|
153
|
+
_v: string;
|
|
122
154
|
}
|
package/lib/utils/base.d.ts
CHANGED
|
@@ -8,8 +8,34 @@ export declare function interceptFunction(target: any, name: string, callback: F
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function generateGUID(): string;
|
|
10
10
|
/**
|
|
11
|
-
* @description:
|
|
12
|
-
* @param len {String}
|
|
11
|
+
* @description: 随机生成 traceId 或 sessionId
|
|
13
12
|
* @return {String}
|
|
14
13
|
*/
|
|
15
|
-
export declare function
|
|
14
|
+
export declare function generateTraceId(): string;
|
|
15
|
+
/**
|
|
16
|
+
* @description: 随机生成 spanId
|
|
17
|
+
* @param len {number}
|
|
18
|
+
* @param radix {number}
|
|
19
|
+
* @return {String}
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateSpanId(len?: number, radix?: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* @description: 随机生成 eventId
|
|
24
|
+
* @param sessionId {string} sessionId
|
|
25
|
+
* @param sampled {boolean} 是否命中采样
|
|
26
|
+
* @param samplingType {string} 采样类型
|
|
27
|
+
* @return {String}
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateEventId(sessionId: string, sampled?: boolean, samplingType?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* @desc 函数防抖
|
|
32
|
+
* @param func 回调函数
|
|
33
|
+
* @param wait 延迟执行毫秒数
|
|
34
|
+
*/
|
|
35
|
+
export declare function debounce(func: Function, wait: number): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* @desc 函数延迟执行
|
|
38
|
+
* @param func 回调函数
|
|
39
|
+
* @param wait 延迟执行毫秒数
|
|
40
|
+
*/
|
|
41
|
+
export declare function delay(func: Function, wait: number, ...args: any[]): number;
|
package/lib/utils/base.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
+
exports.debounce = debounce;
|
|
5
|
+
exports.delay = delay;
|
|
6
|
+
exports.generateEventId = generateEventId;
|
|
4
7
|
exports.generateGUID = generateGUID;
|
|
5
|
-
exports.
|
|
8
|
+
exports.generateSpanId = generateSpanId;
|
|
9
|
+
exports.generateTraceId = generateTraceId;
|
|
6
10
|
exports.interceptFunction = interceptFunction;
|
|
11
|
+
var _is = require("./is");
|
|
7
12
|
/**
|
|
8
13
|
* 劫持函数
|
|
9
14
|
*/
|
|
@@ -29,8 +34,18 @@ function generateGUID() {
|
|
|
29
34
|
try {
|
|
30
35
|
if (crypto && crypto.randomUUID) {
|
|
31
36
|
guid = crypto.randomUUID();
|
|
37
|
+
} else if (crypto && crypto.getRandomValues) {
|
|
38
|
+
var buf = new Uint8Array(16);
|
|
39
|
+
crypto.getRandomValues(buf);
|
|
40
|
+
buf[6] = buf[6] & 0x0f | 0x40; // version 4 UUID
|
|
41
|
+
buf[8] = buf[8] & 0x3f | 0x80; // variant 10xxxxxx
|
|
42
|
+
guid = buf.reduce(function (str, _byte) {
|
|
43
|
+
return str + _byte.toString(16).padStart(2, '0');
|
|
44
|
+
}, '').replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '\$1-\$2-\$3-\$4-\$5');
|
|
32
45
|
}
|
|
33
|
-
} catch (e) {
|
|
46
|
+
} catch (e) {
|
|
47
|
+
//
|
|
48
|
+
}
|
|
34
49
|
if (!guid) {
|
|
35
50
|
guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
36
51
|
var r = Math.random() * 16 | 0,
|
|
@@ -42,24 +57,92 @@ function generateGUID() {
|
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
/**
|
|
45
|
-
* @description:
|
|
46
|
-
* @
|
|
60
|
+
* @description: 随机生成 traceId 或 sessionId
|
|
61
|
+
* @return {String}
|
|
62
|
+
*/
|
|
63
|
+
function generateTraceId() {
|
|
64
|
+
var traceId = generateGUID().replace(/-/g, '');
|
|
65
|
+
// 适配OpenTracing 实现(long long转成16进制最高位不能为0)
|
|
66
|
+
if (traceId[0] === '0') {
|
|
67
|
+
traceId = '1' + traceId.substring(1);
|
|
68
|
+
}
|
|
69
|
+
if (traceId[16] === '0') {
|
|
70
|
+
traceId = traceId.substring(0, 16) + '1' + traceId.substring(17);
|
|
71
|
+
}
|
|
72
|
+
return traceId;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @description: 随机生成 spanId
|
|
77
|
+
* @param len {number}
|
|
78
|
+
* @param radix {number}
|
|
47
79
|
* @return {String}
|
|
48
80
|
*/
|
|
49
|
-
function
|
|
81
|
+
function generateSpanId(len, radix) {
|
|
50
82
|
if (len === void 0) {
|
|
51
|
-
len =
|
|
83
|
+
len = 16;
|
|
84
|
+
}
|
|
85
|
+
if (radix === void 0) {
|
|
86
|
+
radix = 16;
|
|
87
|
+
}
|
|
88
|
+
var result = '';
|
|
89
|
+
for (var i = 0; i < len; i++) {
|
|
90
|
+
result += Math.floor(Math.random() * radix).toString(radix);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @description: 随机生成 eventId
|
|
97
|
+
* @param sessionId {string} sessionId
|
|
98
|
+
* @param sampled {boolean} 是否命中采样
|
|
99
|
+
* @param samplingType {string} 采样类型
|
|
100
|
+
* @return {String}
|
|
101
|
+
*/
|
|
102
|
+
function generateEventId(sessionId, sampled, samplingType) {
|
|
103
|
+
if (sampled === void 0) {
|
|
104
|
+
sampled = true;
|
|
105
|
+
}
|
|
106
|
+
if (samplingType === void 0) {
|
|
107
|
+
samplingType = '0';
|
|
108
|
+
}
|
|
109
|
+
var spanId = generateSpanId();
|
|
110
|
+
return "00-" + sessionId + "-" + spanId + "-" + samplingType + (sampled ? '1' : '0');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @desc 函数防抖
|
|
115
|
+
* @param func 回调函数
|
|
116
|
+
* @param wait 延迟执行毫秒数
|
|
117
|
+
*/
|
|
118
|
+
function debounce(func, wait) {
|
|
119
|
+
var timer;
|
|
120
|
+
if (!(0, _is.isFunction)(func)) {
|
|
121
|
+
return;
|
|
52
122
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
123
|
+
return function () {
|
|
124
|
+
var context = this;
|
|
125
|
+
var args = arguments;
|
|
126
|
+
if (timer) {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
}
|
|
129
|
+
timer = setTimeout(function () {
|
|
130
|
+
func.apply(context, args);
|
|
131
|
+
}, wait);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @desc 函数延迟执行
|
|
137
|
+
* @param func 回调函数
|
|
138
|
+
* @param wait 延迟执行毫秒数
|
|
139
|
+
*/
|
|
140
|
+
function delay(func, wait) {
|
|
141
|
+
if (!(0, _is.isFunction)(func)) {
|
|
142
|
+
return;
|
|
60
143
|
}
|
|
61
|
-
for (var
|
|
62
|
-
|
|
144
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
145
|
+
args[_key2 - 2] = arguments[_key2];
|
|
63
146
|
}
|
|
64
|
-
return
|
|
147
|
+
return setTimeout.apply(void 0, [func, +wait || 0].concat(args));
|
|
65
148
|
}
|
package/lib/utils/number.d.ts
CHANGED
|
@@ -4,3 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function performDraw(threshold: number): boolean;
|
|
6
6
|
export declare function round(num: number, decimals: 0 | 1 | 2 | 3 | 4): number;
|
|
7
|
+
/**
|
|
8
|
+
* 保留指定位数的小数
|
|
9
|
+
* @param num 原数据
|
|
10
|
+
* @param decimal 小数位数
|
|
11
|
+
* @param min 限制最小值,否则返回undefined
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatNumber(num: number, decimal?: number, min?: number): number;
|
package/lib/utils/number.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
+
exports.formatNumber = formatNumber;
|
|
4
5
|
exports.performDraw = performDraw;
|
|
5
6
|
exports.round = round;
|
|
6
7
|
/**
|
|
@@ -12,4 +13,32 @@ function performDraw(threshold) {
|
|
|
12
13
|
}
|
|
13
14
|
function round(num, decimals) {
|
|
14
15
|
return +num.toFixed(decimals);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 保留指定位数的小数
|
|
20
|
+
* @param num 原数据
|
|
21
|
+
* @param decimal 小数位数
|
|
22
|
+
* @param min 限制最小值,否则返回undefined
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function formatNumber(num, decimal, min) {
|
|
26
|
+
if (decimal === void 0) {
|
|
27
|
+
decimal = 3;
|
|
28
|
+
}
|
|
29
|
+
if (min === void 0) {
|
|
30
|
+
min = 0;
|
|
31
|
+
}
|
|
32
|
+
if (!num) {
|
|
33
|
+
return num;
|
|
34
|
+
}
|
|
35
|
+
var str = num.toString();
|
|
36
|
+
var index = str.indexOf('.');
|
|
37
|
+
if (index !== -1) {
|
|
38
|
+
str = str.substring(0, decimal + index + 1);
|
|
39
|
+
} else {
|
|
40
|
+
str = str.substring(0);
|
|
41
|
+
}
|
|
42
|
+
var result = parseFloat(str);
|
|
43
|
+
return result >= min ? result : undefined;
|
|
15
44
|
}
|
package/lib/utils/polyfills.js
CHANGED
|
@@ -7,9 +7,9 @@ exports.find = find;
|
|
|
7
7
|
exports.startsWith = startsWith;
|
|
8
8
|
function find(array, predicate) {
|
|
9
9
|
for (var i = 0; i < array.length; i += 1) {
|
|
10
|
-
var
|
|
11
|
-
if (predicate(
|
|
12
|
-
return
|
|
10
|
+
var item = array[i];
|
|
11
|
+
if (predicate(item, i)) {
|
|
12
|
+
return item;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
return undefined;
|
package/lib/utils/trace.d.ts
CHANGED
package/lib/utils/trace.js
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.generateSpanId = generateSpanId;
|
|
5
|
-
exports.generateTraceId = generateTraceId;
|
|
6
4
|
exports.isTraceOption = isTraceOption;
|
|
7
5
|
exports.makeTracingHeaders = makeTracingHeaders;
|
|
8
6
|
exports.parseTracingOptions = parseTracingOptions;
|
|
9
7
|
var _match = require("./match");
|
|
10
8
|
var _is = require("./is");
|
|
11
|
-
var _base = require("./base");
|
|
12
9
|
var _jsBase = require("js-base64");
|
|
13
10
|
function isTraceOption(option) {
|
|
14
11
|
return option && (0, _match.isMatchOption)(option.match) && (0, _is.isArray)(option.propagatorTypes);
|
|
15
12
|
}
|
|
16
|
-
function generateTraceId() {
|
|
17
|
-
var traceId = (0, _base.generateGUID)().replace(/-/g, '');
|
|
18
|
-
// 适配OpenTracing 实现(long long转成16进制最高位不能为0)
|
|
19
|
-
if (traceId[0] === '0') {
|
|
20
|
-
traceId = '1' + traceId.substring(1);
|
|
21
|
-
}
|
|
22
|
-
if (traceId[16] === '0') {
|
|
23
|
-
traceId = traceId.substring(0, 16) + '1' + traceId.substring(17);
|
|
24
|
-
}
|
|
25
|
-
return traceId;
|
|
26
|
-
}
|
|
27
|
-
function generateSpanId() {
|
|
28
|
-
var list = Array(16);
|
|
29
|
-
for (var i = 0; i < 16; i++) {
|
|
30
|
-
list[i] = Math.floor(Math.random() * 16) + 48;
|
|
31
|
-
// valid hex characters in the range 48-57 and 97-102
|
|
32
|
-
if (list[i] >= 58) {
|
|
33
|
-
list[i] += 39;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return String.fromCharCode.apply(null, list);
|
|
37
|
-
}
|
|
38
13
|
function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, subOption) {
|
|
39
14
|
if (subOption === void 0) {
|
|
40
15
|
subOption = {};
|