@arms/rum-core 0.0.25-beta.14 → 0.0.25-beta.15
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/es/index.d.ts +17 -0
- package/es/index.js +17 -0
- package/es/model/client.d.ts +20 -0
- package/es/model/client.js +73 -0
- package/es/model/context.d.ts +18 -0
- package/es/model/context.js +38 -0
- package/es/model/reporter.d.ts +30 -0
- package/es/model/reporter.js +131 -0
- package/es/model/shell.d.ts +33 -0
- package/es/model/shell.js +80 -0
- package/es/style.js +1 -0
- package/es/types/client.d.ts +133 -0
- package/es/types/client.js +4 -0
- package/es/types/collector.d.ts +7 -0
- package/es/types/collector.js +1 -0
- package/es/types/processor.d.ts +8 -0
- package/es/types/processor.js +1 -0
- package/es/types/reporter.d.ts +8 -0
- package/es/types/reporter.js +1 -0
- package/es/types/rum-event.d.ts +163 -0
- package/es/types/rum-event.js +24 -0
- package/es/types/shell.d.ts +28 -0
- package/es/types/shell.js +1 -0
- package/es/utils/base.d.ts +39 -0
- package/es/utils/base.js +131 -0
- package/es/utils/exception.d.ts +7 -0
- package/es/utils/exception.js +10 -0
- package/es/utils/is.d.ts +12 -0
- package/es/utils/is.js +33 -0
- package/es/utils/match.d.ts +7 -0
- package/es/utils/match.js +37 -0
- package/es/utils/number.d.ts +17 -0
- package/es/utils/number.js +40 -0
- package/es/utils/polyfills.d.ts +7 -0
- package/es/utils/polyfills.js +28 -0
- package/es/utils/trace.d.ts +28 -0
- package/es/utils/trace.js +101 -0
- package/lib/types/rum-event.d.ts +11 -2
- package/lib/types/rum-event.js +11 -1
- package/package.json +4 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isMatchOption } from "./match";
|
|
2
|
+
import { isArray, isBoolean, isNumber } from "./is";
|
|
3
|
+
import { encode } from "js-base64";
|
|
4
|
+
export function isTraceOption(option) {
|
|
5
|
+
return option && isMatchOption(option.match) && isArray(option.propagatorTypes);
|
|
6
|
+
}
|
|
7
|
+
export function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, subOption) {
|
|
8
|
+
if (subOption === void 0) {
|
|
9
|
+
subOption = {};
|
|
10
|
+
}
|
|
11
|
+
var tracingHeaders = {};
|
|
12
|
+
var sample = sampled ? '1' : '0';
|
|
13
|
+
// skywalking 标准具备排他性,如果包含sw8,则只使用sw8
|
|
14
|
+
if (propagatorTypes.includes('sw8')) {
|
|
15
|
+
propagatorTypes = ['sw8'];
|
|
16
|
+
}
|
|
17
|
+
propagatorTypes.forEach(function (propagatorType) {
|
|
18
|
+
switch (propagatorType) {
|
|
19
|
+
case 'jaeger':
|
|
20
|
+
tracingHeaders['uber-trace-id'] = traceId + ":" + spanId + ":0:" + sample;
|
|
21
|
+
break;
|
|
22
|
+
case 'b3':
|
|
23
|
+
// https://github.com/openzipkin/b3-propagation
|
|
24
|
+
tracingHeaders['b3'] = traceId + "-" + spanId + "-" + sample;
|
|
25
|
+
break;
|
|
26
|
+
case 'b3multi':
|
|
27
|
+
tracingHeaders['X-B3-TraceId'] = traceId;
|
|
28
|
+
tracingHeaders['X-B3-SpanId'] = spanId;
|
|
29
|
+
tracingHeaders['X-B3-Sampled'] = sample;
|
|
30
|
+
break;
|
|
31
|
+
case 'sw8':
|
|
32
|
+
// https://github.com/apache/skywalking-client-js
|
|
33
|
+
var traceIdStr = String(encode(traceId));
|
|
34
|
+
var segmentId = String(encode(spanId));
|
|
35
|
+
var service = String(encode(subOption.appId));
|
|
36
|
+
var instance = String(encode(subOption.appVersion));
|
|
37
|
+
var endpoint = String(encode(subOption.viewName));
|
|
38
|
+
var peer = String(encode(subOption.host));
|
|
39
|
+
tracingHeaders['sw8'] = sample + "-" + traceIdStr + "-" + segmentId + "-" + 0 + "-" + service + "-" + instance + "-" + endpoint + "-" + peer;
|
|
40
|
+
break;
|
|
41
|
+
case 'tracecontext':
|
|
42
|
+
default:
|
|
43
|
+
// https://www.w3.org/TR/trace-context/
|
|
44
|
+
tracingHeaders['traceparent'] = "00-" + traceId + "-" + spanId + "-0" + sample;
|
|
45
|
+
if (subOption.tracestate) {
|
|
46
|
+
tracingHeaders['tracestate'] = subOption.tracestate;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (subOption.baggage) {
|
|
52
|
+
tracingHeaders['baggage'] = subOption.baggage;
|
|
53
|
+
}
|
|
54
|
+
return tracingHeaders;
|
|
55
|
+
}
|
|
56
|
+
export function parseTracingOptions(tracingOption) {
|
|
57
|
+
var defPropagatorTypes = ['tracecontext'];
|
|
58
|
+
if (isBoolean(tracingOption) || !tracingOption) {
|
|
59
|
+
return {
|
|
60
|
+
enable: !!tracingOption,
|
|
61
|
+
sample: 100,
|
|
62
|
+
propagatorTypes: defPropagatorTypes,
|
|
63
|
+
allowedUrls: [],
|
|
64
|
+
tracestate: true,
|
|
65
|
+
baggage: false
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
var _tracingOption$enable = tracingOption.enable,
|
|
69
|
+
enable = _tracingOption$enable === void 0 ? true : _tracingOption$enable,
|
|
70
|
+
_tracingOption$sample = tracingOption.sample,
|
|
71
|
+
sample = _tracingOption$sample === void 0 ? 100 : _tracingOption$sample,
|
|
72
|
+
_tracingOption$propag = tracingOption.propagatorTypes,
|
|
73
|
+
propagatorTypes = _tracingOption$propag === void 0 ? defPropagatorTypes : _tracingOption$propag,
|
|
74
|
+
_tracingOption$allowe = tracingOption.allowedUrls,
|
|
75
|
+
allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe,
|
|
76
|
+
_tracingOption$traces = tracingOption.tracestate,
|
|
77
|
+
tracestate = _tracingOption$traces === void 0 ? true : _tracingOption$traces,
|
|
78
|
+
_tracingOption$baggag = tracingOption.baggage,
|
|
79
|
+
baggage = _tracingOption$baggag === void 0 ? false : _tracingOption$baggag;
|
|
80
|
+
var traceOptions = [];
|
|
81
|
+
if (isArray(allowedUrls) && allowedUrls.length) {
|
|
82
|
+
allowedUrls.forEach(function (item) {
|
|
83
|
+
if (isMatchOption(item)) {
|
|
84
|
+
traceOptions.push({
|
|
85
|
+
match: item,
|
|
86
|
+
propagatorTypes: propagatorTypes
|
|
87
|
+
});
|
|
88
|
+
} else if (isTraceOption(item)) {
|
|
89
|
+
traceOptions.push(item);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
enable: isBoolean(enable) ? enable : true,
|
|
95
|
+
sample: isNumber(sample) ? sample : 100,
|
|
96
|
+
propagatorTypes: propagatorTypes,
|
|
97
|
+
allowedUrls: traceOptions,
|
|
98
|
+
tracestate: tracestate,
|
|
99
|
+
baggage: baggage
|
|
100
|
+
};
|
|
101
|
+
}
|
package/lib/types/rum-event.d.ts
CHANGED
|
@@ -42,13 +42,21 @@ export interface RumViewEvent extends RumBaseEvent {
|
|
|
42
42
|
url?: string;
|
|
43
43
|
timing_data?: string;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* 枚举值,表示资源是否加载成功
|
|
47
|
+
*/
|
|
48
|
+
export declare enum ResourceStatus {
|
|
49
|
+
Unknown = -1,
|
|
50
|
+
Failed = 0,
|
|
51
|
+
Success = 1
|
|
52
|
+
}
|
|
45
53
|
export interface RumResourceEvent extends RumBaseEvent {
|
|
46
54
|
name?: string;
|
|
47
55
|
type?: string;
|
|
48
56
|
method?: string;
|
|
49
57
|
status_code?: number | string;
|
|
50
58
|
message?: string;
|
|
51
|
-
success?: -1 | 0 | 1;
|
|
59
|
+
success?: -1 | 0 | 1 | ResourceStatus;
|
|
52
60
|
trace_id?: string;
|
|
53
61
|
duration?: number;
|
|
54
62
|
size?: number;
|
|
@@ -96,7 +104,8 @@ export interface RumCustomEvent extends RumBaseEvent {
|
|
|
96
104
|
export type RumEvent = RumViewEvent | RumResourceEvent | RumExceptionEvent | RumActionEvent | RumCustomEvent;
|
|
97
105
|
export declare enum AppType {
|
|
98
106
|
browser = "browser",
|
|
99
|
-
miniapp = "miniapp"
|
|
107
|
+
miniapp = "miniapp",
|
|
108
|
+
uniapp = "uniapp"
|
|
100
109
|
}
|
|
101
110
|
export interface RumEventBundle {
|
|
102
111
|
app: {
|
package/lib/types/rum-event.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.RumEventType = exports.AppType = void 0;
|
|
4
|
+
exports.RumEventType = exports.ResourceStatus = exports.AppType = void 0;
|
|
5
5
|
var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
6
6
|
RumEventType["VIEW"] = "view";
|
|
7
7
|
RumEventType["RESOURCE"] = "resource";
|
|
@@ -11,8 +11,18 @@ var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
|
11
11
|
RumEventType["CUSTOM"] = "custom";
|
|
12
12
|
return RumEventType;
|
|
13
13
|
}({});
|
|
14
|
+
/**
|
|
15
|
+
* 枚举值,表示资源是否加载成功
|
|
16
|
+
*/
|
|
17
|
+
var ResourceStatus = exports.ResourceStatus = /*#__PURE__*/function (ResourceStatus) {
|
|
18
|
+
ResourceStatus[ResourceStatus["Unknown"] = -1] = "Unknown";
|
|
19
|
+
ResourceStatus[ResourceStatus["Failed"] = 0] = "Failed";
|
|
20
|
+
ResourceStatus[ResourceStatus["Success"] = 1] = "Success";
|
|
21
|
+
return ResourceStatus;
|
|
22
|
+
}({});
|
|
14
23
|
var AppType = exports.AppType = /*#__PURE__*/function (AppType) {
|
|
15
24
|
AppType["browser"] = "browser";
|
|
16
25
|
AppType["miniapp"] = "miniapp";
|
|
26
|
+
AppType["uniapp"] = "uniapp";
|
|
17
27
|
return AppType;
|
|
18
28
|
}({});
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arms/rum-core",
|
|
3
|
-
"version": "0.0.25-beta.
|
|
3
|
+
"version": "0.0.25-beta.15",
|
|
4
4
|
"description": "arms rum javascript sdk core",
|
|
5
5
|
"author": "guangli.fj <guangli.fj@alibaba-inc.com>",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
|
+
"module": "es/index.js",
|
|
8
9
|
"directories": {
|
|
9
10
|
"lib": "lib",
|
|
10
11
|
"test": "__tests__"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
|
-
"lib"
|
|
14
|
+
"lib",
|
|
15
|
+
"es"
|
|
14
16
|
],
|
|
15
17
|
"publishConfig": {
|
|
16
18
|
"access": "public"
|
|
@@ -18,7 +20,6 @@
|
|
|
18
20
|
"scripts": {
|
|
19
21
|
"start": "build-scripts build --watch",
|
|
20
22
|
"build": "build-scripts build --skip-demo",
|
|
21
|
-
"prepublishOnly": "npm run build",
|
|
22
23
|
"test": "node ./__tests__/@arms/core.test.js"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|