@arms/rum-core 0.0.5 → 0.0.8
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/index.d.ts +2 -1
- package/lib/index.js +8 -5
- package/lib/model/context.d.ts +2 -2
- package/lib/model/reporter.d.ts +2 -2
- package/lib/model/shell.d.ts +25 -0
- package/lib/model/shell.js +53 -0
- package/lib/types/client.d.ts +1 -10
- package/lib/types/reporter.d.ts +2 -2
- package/lib/types/rum-event.d.ts +16 -14
- package/lib/types/rum-event.js +1 -1
- package/lib/utils/trace.d.ts +2 -1
- package/lib/utils/trace.js +12 -18
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Client from './model/client';
|
|
2
2
|
import Context from './model/context';
|
|
3
3
|
import Reporter from './model/reporter';
|
|
4
|
+
import Shell from './model/shell';
|
|
4
5
|
export * from './types/client';
|
|
5
6
|
export * from './types/collector';
|
|
6
7
|
export * from './types/processor';
|
|
@@ -13,4 +14,4 @@ export * from './utils/is';
|
|
|
13
14
|
export * from './utils/number';
|
|
14
15
|
export * from './utils/match';
|
|
15
16
|
export * from './utils/trace';
|
|
16
|
-
export { Client, Context, Reporter };
|
|
17
|
+
export { Client, Context, Reporter, Shell };
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,8 @@ exports.__esModule = true;
|
|
|
5
5
|
var _exportNames = {
|
|
6
6
|
Client: true,
|
|
7
7
|
Context: true,
|
|
8
|
-
Reporter: true
|
|
8
|
+
Reporter: true,
|
|
9
|
+
Shell: true
|
|
9
10
|
};
|
|
10
11
|
var _client = _interopRequireDefault(require("./model/client"));
|
|
11
12
|
exports.Client = _client["default"];
|
|
@@ -13,6 +14,8 @@ var _context = _interopRequireDefault(require("./model/context"));
|
|
|
13
14
|
exports.Context = _context["default"];
|
|
14
15
|
var _reporter = _interopRequireDefault(require("./model/reporter"));
|
|
15
16
|
exports.Reporter = _reporter["default"];
|
|
17
|
+
var _shell = _interopRequireDefault(require("./model/shell"));
|
|
18
|
+
exports.Shell = _shell["default"];
|
|
16
19
|
var _client2 = require("./types/client");
|
|
17
20
|
Object.keys(_client2).forEach(function (key) {
|
|
18
21
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -48,12 +51,12 @@ Object.keys(_rumEvent).forEach(function (key) {
|
|
|
48
51
|
if (key in exports && exports[key] === _rumEvent[key]) return;
|
|
49
52
|
exports[key] = _rumEvent[key];
|
|
50
53
|
});
|
|
51
|
-
var
|
|
52
|
-
Object.keys(
|
|
54
|
+
var _shell2 = require("./types/shell");
|
|
55
|
+
Object.keys(_shell2).forEach(function (key) {
|
|
53
56
|
if (key === "default" || key === "__esModule") return;
|
|
54
57
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
55
|
-
if (key in exports && exports[key] ===
|
|
56
|
-
exports[key] =
|
|
58
|
+
if (key in exports && exports[key] === _shell2[key]) return;
|
|
59
|
+
exports[key] = _shell2[key];
|
|
57
60
|
});
|
|
58
61
|
var _base = require("./utils/base");
|
|
59
62
|
Object.keys(_base).forEach(function (key) {
|
package/lib/model/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IConfiguration, IContext
|
|
2
|
-
import { RumEvent } from "../types/rum-event";
|
|
1
|
+
import { IConfiguration, IContext } from "../types/client";
|
|
2
|
+
import { RumEvent, IViewData } from "../types/rum-event";
|
|
3
3
|
declare class Context implements IContext {
|
|
4
4
|
private config;
|
|
5
5
|
private rumEvent;
|
package/lib/model/reporter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IContext
|
|
2
|
-
import { RumEvent } from '../types/rum-event';
|
|
1
|
+
import { IContext } from '../types/client';
|
|
2
|
+
import { RumEvent, IViewData } from '../types/rum-event';
|
|
3
3
|
export default abstract class Reporter {
|
|
4
4
|
name: string;
|
|
5
5
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IClient, IConfiguration } from "../types/client";
|
|
2
|
+
import { RumEvent } from "../types/rum-event";
|
|
3
|
+
import { IShell } from "../types/shell";
|
|
4
|
+
export default abstract class Shell implements IShell {
|
|
5
|
+
client: IClient;
|
|
6
|
+
constructor(config?: IConfiguration);
|
|
7
|
+
/**
|
|
8
|
+
* 初始化
|
|
9
|
+
*/
|
|
10
|
+
abstract init(configuration: IConfiguration): void;
|
|
11
|
+
sendEvent(payload: RumEvent): void;
|
|
12
|
+
/**
|
|
13
|
+
* get config
|
|
14
|
+
*/
|
|
15
|
+
getConfig(): IConfiguration;
|
|
16
|
+
/**
|
|
17
|
+
* set config
|
|
18
|
+
*/
|
|
19
|
+
abstract setConfig<T extends keyof IConfiguration>(key: T, value: IConfiguration[T]): void;
|
|
20
|
+
abstract setConfig(value: IConfiguration): void;
|
|
21
|
+
/**
|
|
22
|
+
* 自定义上传数据
|
|
23
|
+
*/
|
|
24
|
+
sendCustom(payload: RumEvent): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports["default"] = void 0;
|
|
6
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
|
+
var _rumEvent = require("../types/rum-event");
|
|
8
|
+
var _rumCore = require("@arms/rum-core");
|
|
9
|
+
var Shell = exports["default"] = /*#__PURE__*/function () {
|
|
10
|
+
function Shell(config) {
|
|
11
|
+
this.client = void 0;
|
|
12
|
+
this.client = new _rumCore.Client();
|
|
13
|
+
if (config && this.init) {
|
|
14
|
+
this.init(config);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 初始化
|
|
20
|
+
*/
|
|
21
|
+
var _proto = Shell.prototype;
|
|
22
|
+
_proto.sendEvent = function sendEvent(payload) {
|
|
23
|
+
if (this.client) {
|
|
24
|
+
this.client.sendEvent(payload);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* get config
|
|
30
|
+
*/;
|
|
31
|
+
_proto.getConfig = function getConfig() {
|
|
32
|
+
if (this.client) {
|
|
33
|
+
return this.client.getContext().getConfig();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* set config
|
|
39
|
+
*/;
|
|
40
|
+
/**
|
|
41
|
+
* 自定义上传数据
|
|
42
|
+
*/
|
|
43
|
+
_proto.sendCustom = function sendCustom(payload) {
|
|
44
|
+
if (!payload.name || !payload.type) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
var data = (0, _extends2["default"])({}, payload, {
|
|
48
|
+
event_type: _rumEvent.RumEventType.CUSTOM
|
|
49
|
+
});
|
|
50
|
+
this.sendEvent(data);
|
|
51
|
+
};
|
|
52
|
+
return Shell;
|
|
53
|
+
}();
|
package/lib/types/client.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { ICollector } from './collector';
|
|
2
2
|
import { IProcessor } from './processor';
|
|
3
3
|
import { IReporter } from './reporter';
|
|
4
|
-
import { RumEvent, RumEventBundle } from './rum-event';
|
|
5
|
-
import { ITracingOption } from '../utils/trace';
|
|
4
|
+
import { RumEvent, RumEventBundle, IViewData } from './rum-event';
|
|
6
5
|
export declare enum EventType {
|
|
7
6
|
/**
|
|
8
7
|
* 收集数据
|
|
9
8
|
*/
|
|
10
9
|
collect = "collect"
|
|
11
10
|
}
|
|
12
|
-
export interface IViewData {
|
|
13
|
-
id: string;
|
|
14
|
-
name: string;
|
|
15
|
-
}
|
|
16
11
|
export interface IContext {
|
|
17
12
|
/**
|
|
18
13
|
* user config
|
|
@@ -96,9 +91,5 @@ export interface IConfiguration {
|
|
|
96
91
|
* 各个 collector config
|
|
97
92
|
*/
|
|
98
93
|
collectors?: any;
|
|
99
|
-
/**
|
|
100
|
-
* tracing 配置 'tracecontext' | 'b3' | 'b3multi' | 'jaeger';
|
|
101
|
-
*/
|
|
102
|
-
tracing?: boolean | ITracingOption;
|
|
103
94
|
[key: string]: any;
|
|
104
95
|
}
|
package/lib/types/reporter.d.ts
CHANGED
package/lib/types/rum-event.d.ts
CHANGED
|
@@ -6,22 +6,22 @@ export declare enum RumEventType {
|
|
|
6
6
|
ACTION = "action",
|
|
7
7
|
CUSTOM = "custom"
|
|
8
8
|
}
|
|
9
|
-
export type BaseObjectKey = string | number;
|
|
10
|
-
export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
|
|
11
|
-
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[];
|
|
12
9
|
export interface BaseObject {
|
|
13
|
-
[key:
|
|
10
|
+
[key: string]: BaseObjectValue;
|
|
11
|
+
}
|
|
12
|
+
export interface IViewData {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
14
15
|
}
|
|
16
|
+
export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
|
|
17
|
+
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData;
|
|
15
18
|
export interface RumBaseEvent {
|
|
16
|
-
event_type
|
|
19
|
+
event_type?: RumEventType;
|
|
17
20
|
event_id?: string;
|
|
18
21
|
timestamp?: number;
|
|
19
22
|
times?: number;
|
|
20
|
-
view?:
|
|
21
|
-
|
|
22
|
-
name: string;
|
|
23
|
-
};
|
|
24
|
-
[key: `$attr.${string}`]: BaseObjectValue;
|
|
23
|
+
view?: IViewData;
|
|
24
|
+
[key: string]: BaseObjectValue;
|
|
25
25
|
}
|
|
26
26
|
export interface RumViewEvent extends RumBaseEvent {
|
|
27
27
|
loading_type?: 'initial_load' | 'route_change';
|
|
@@ -34,6 +34,7 @@ export interface RumViewEvent extends RumBaseEvent {
|
|
|
34
34
|
dom_interactive?: number;
|
|
35
35
|
dom_content_loaded?: number;
|
|
36
36
|
dom_complete?: number;
|
|
37
|
+
load_event?: number;
|
|
37
38
|
referrer?: string;
|
|
38
39
|
url?: string;
|
|
39
40
|
timing_data?: string;
|
|
@@ -56,7 +57,7 @@ export interface RumResourceEvent extends RumBaseEvent {
|
|
|
56
57
|
first_byte_duration?: number;
|
|
57
58
|
download_duration?: number;
|
|
58
59
|
url: string;
|
|
59
|
-
timing_data?:
|
|
60
|
+
timing_data?: string;
|
|
60
61
|
}
|
|
61
62
|
export interface RumExceptionEvent extends RumBaseEvent {
|
|
62
63
|
source?: string;
|
|
@@ -85,13 +86,14 @@ export interface RumActionEvent extends RumBaseEvent {
|
|
|
85
86
|
snapshots?: string;
|
|
86
87
|
}
|
|
87
88
|
export interface RumCustomEvent extends RumBaseEvent {
|
|
88
|
-
id: string;
|
|
89
89
|
type: string;
|
|
90
|
-
|
|
90
|
+
name: string;
|
|
91
|
+
group?: string;
|
|
92
|
+
value: number;
|
|
91
93
|
}
|
|
92
94
|
export type RumEvent = RumViewEvent | RumResourceEvent | RumExceptionEvent | RumActionEvent | RumCustomEvent;
|
|
93
95
|
export declare enum AppType {
|
|
94
|
-
|
|
96
|
+
browser = "browser",
|
|
95
97
|
miniapp = "miniapp"
|
|
96
98
|
}
|
|
97
99
|
export interface RumEventBundle {
|
package/lib/types/rum-event.js
CHANGED
|
@@ -12,7 +12,7 @@ var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
|
12
12
|
return RumEventType;
|
|
13
13
|
}({});
|
|
14
14
|
var AppType = exports.AppType = /*#__PURE__*/function (AppType) {
|
|
15
|
-
AppType["
|
|
15
|
+
AppType["browser"] = "browser";
|
|
16
16
|
AppType["miniapp"] = "miniapp";
|
|
17
17
|
return AppType;
|
|
18
18
|
}({});
|
package/lib/utils/trace.d.ts
CHANGED
|
@@ -10,11 +10,12 @@ export interface ITracingOption {
|
|
|
10
10
|
sample?: number | undefined;
|
|
11
11
|
allowedUrls?: Array<MatchOption | TraceOption> | undefined;
|
|
12
12
|
tracestate?: boolean;
|
|
13
|
+
baggage?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export declare function generateTraceId(): any;
|
|
15
16
|
export declare function generateSpanId(): any;
|
|
16
17
|
export interface ITracingHeaders {
|
|
17
18
|
[key: string]: string;
|
|
18
19
|
}
|
|
19
|
-
export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], tracestate?: string): ITracingHeaders;
|
|
20
|
+
export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], tracestate?: string, baggage?: string): ITracingHeaders;
|
|
20
21
|
export declare function parseTracingOptions(tracingOption: boolean | ITracingOption): ITracingOption;
|
package/lib/utils/trace.js
CHANGED
|
@@ -12,7 +12,7 @@ var SPAN_ID_BYTES = 8;
|
|
|
12
12
|
var TRACE_ID_BYTES = 16;
|
|
13
13
|
var SHARED_CHAR_CODES_ARRAY = Array(32);
|
|
14
14
|
function isTraceOption(option) {
|
|
15
|
-
return option && (0, _match.isMatchOption)(option.match) &&
|
|
15
|
+
return option && (0, _match.isMatchOption)(option.match) && (0, _is.isArray)(option.propagatorTypes);
|
|
16
16
|
}
|
|
17
17
|
function generateId(bytes) {
|
|
18
18
|
for (var i = 0; i < bytes * 2; i++) {
|
|
@@ -38,20 +38,7 @@ function generateTraceId() {
|
|
|
38
38
|
function generateSpanId() {
|
|
39
39
|
return generateId(SPAN_ID_BYTES);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
// export function getB3Header(traceId: string, spanId: string) {
|
|
43
|
-
// return `${traceId}-${spanId}-1`
|
|
44
|
-
// }
|
|
45
|
-
//
|
|
46
|
-
// export function getW3CTraceHeader(traceId: string, spanId: string) {
|
|
47
|
-
// return `00-${traceId}-${spanId}-01`
|
|
48
|
-
// }
|
|
49
|
-
//
|
|
50
|
-
// export function getJaegerTraceHeader(traceId: string, spanId: string) {
|
|
51
|
-
// return `${traceId}:${spanId}:0:1`
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, tracestate) {
|
|
41
|
+
function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, tracestate, baggage) {
|
|
55
42
|
var tracingHeaders = {};
|
|
56
43
|
var sample = sampled ? '1' : '0';
|
|
57
44
|
propagatorTypes.forEach(function (propagatorType) {
|
|
@@ -77,6 +64,9 @@ function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, tracestat
|
|
|
77
64
|
break;
|
|
78
65
|
}
|
|
79
66
|
});
|
|
67
|
+
if (baggage) {
|
|
68
|
+
tracingHeaders['baggage'] = baggage;
|
|
69
|
+
}
|
|
80
70
|
return tracingHeaders;
|
|
81
71
|
}
|
|
82
72
|
function parseTracingOptions(tracingOption) {
|
|
@@ -85,7 +75,8 @@ function parseTracingOptions(tracingOption) {
|
|
|
85
75
|
enable: !!tracingOption,
|
|
86
76
|
sample: 100,
|
|
87
77
|
allowedUrls: [],
|
|
88
|
-
tracestate: true
|
|
78
|
+
tracestate: true,
|
|
79
|
+
baggage: false
|
|
89
80
|
};
|
|
90
81
|
}
|
|
91
82
|
var _tracingOption$enable = tracingOption.enable,
|
|
@@ -95,7 +86,9 @@ function parseTracingOptions(tracingOption) {
|
|
|
95
86
|
_tracingOption$allowe = tracingOption.allowedUrls,
|
|
96
87
|
allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe,
|
|
97
88
|
_tracingOption$traces = tracingOption.tracestate,
|
|
98
|
-
tracestate = _tracingOption$traces === void 0 ? true : _tracingOption$traces
|
|
89
|
+
tracestate = _tracingOption$traces === void 0 ? true : _tracingOption$traces,
|
|
90
|
+
_tracingOption$baggag = tracingOption.baggage,
|
|
91
|
+
baggage = _tracingOption$baggag === void 0 ? false : _tracingOption$baggag;
|
|
99
92
|
var traceOptions = [];
|
|
100
93
|
if ((0, _is.isArray)(allowedUrls) && allowedUrls.length) {
|
|
101
94
|
allowedUrls.forEach(function (item) {
|
|
@@ -113,6 +106,7 @@ function parseTracingOptions(tracingOption) {
|
|
|
113
106
|
enable: (0, _is.isBoolean)(enable) ? enable : true,
|
|
114
107
|
sample: (0, _is.isNumber)(sample) ? sample : 100,
|
|
115
108
|
allowedUrls: traceOptions,
|
|
116
|
-
tracestate: tracestate
|
|
109
|
+
tracestate: tracestate,
|
|
110
|
+
baggage: baggage
|
|
117
111
|
};
|
|
118
112
|
}
|