@arms/rum-core 0.0.34 → 0.0.36
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 +18 -0
- package/es/index.js +18 -0
- package/es/model/client.d.ts +21 -0
- package/es/model/client.js +76 -0
- package/es/model/context.d.ts +18 -0
- package/es/model/context.js +38 -0
- package/es/model/reporter.d.ts +31 -0
- package/es/model/reporter.js +196 -0
- package/es/model/shell.d.ts +51 -0
- package/es/model/shell.js +160 -0
- package/es/style.js +1 -0
- package/es/types/client.d.ts +162 -0
- package/es/types/client.js +7 -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 +177 -0
- package/es/types/rum-event.js +26 -0
- package/es/types/shell.d.ts +28 -0
- package/es/types/shell.js +1 -0
- package/es/utils/base.d.ts +60 -0
- package/es/utils/base.js +216 -0
- package/es/utils/combineConfig.d.ts +15 -0
- package/es/utils/combineConfig.js +101 -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 +39 -0
- package/es/utils/match.d.ts +7 -0
- package/es/utils/match.js +40 -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 +105 -0
- package/es/utils/verify.d.ts +2 -0
- package/es/utils/verify.js +35 -0
- package/lib/model/reporter.js +1 -4
- package/lib/model/shell.d.ts +2 -1
- package/lib/model/shell.js +26 -20
- package/lib/utils/base.d.ts +2 -2
- package/lib/utils/base.js +9 -5
- package/package.json +6 -2
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Client from './model/client';
|
|
2
|
+
import Context from './model/context';
|
|
3
|
+
import Reporter from './model/reporter';
|
|
4
|
+
import Shell from './model/shell';
|
|
5
|
+
export * from './types/client';
|
|
6
|
+
export * from './types/collector';
|
|
7
|
+
export * from './types/processor';
|
|
8
|
+
export * from './types/reporter';
|
|
9
|
+
export * from './types/rum-event';
|
|
10
|
+
export * from './types/shell';
|
|
11
|
+
export * from './utils/base';
|
|
12
|
+
export * from './utils/polyfills';
|
|
13
|
+
export * from './utils/is';
|
|
14
|
+
export * from './utils/number';
|
|
15
|
+
export * from './utils/match';
|
|
16
|
+
export * from './utils/trace';
|
|
17
|
+
export * from './utils/verify';
|
|
18
|
+
export { Client, Context, Reporter, Shell };
|
package/es/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Client from './model/client';
|
|
2
|
+
import Context from './model/context';
|
|
3
|
+
import Reporter from './model/reporter';
|
|
4
|
+
import Shell from './model/shell';
|
|
5
|
+
export * from './types/client';
|
|
6
|
+
export * from './types/collector';
|
|
7
|
+
export * from './types/processor';
|
|
8
|
+
export * from './types/reporter';
|
|
9
|
+
export * from './types/rum-event';
|
|
10
|
+
export * from './types/shell';
|
|
11
|
+
export * from './utils/base';
|
|
12
|
+
export * from './utils/polyfills';
|
|
13
|
+
export * from './utils/is';
|
|
14
|
+
export * from './utils/number';
|
|
15
|
+
export * from './utils/match';
|
|
16
|
+
export * from './utils/trace';
|
|
17
|
+
export * from './utils/verify';
|
|
18
|
+
export { Client, Context, Reporter, Shell };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IClient, IConfiguration, IContext, IRumSession } from '../types/client';
|
|
2
|
+
import { RumEvent } from '../types/rum-event';
|
|
3
|
+
import { IProcessor } from '../types/processor';
|
|
4
|
+
import { ICollector } from '../types/collector';
|
|
5
|
+
import { IReporter } from '../types/reporter';
|
|
6
|
+
declare class Client implements IClient {
|
|
7
|
+
private emitter;
|
|
8
|
+
private collectors;
|
|
9
|
+
private processors;
|
|
10
|
+
private reporter;
|
|
11
|
+
private ctx;
|
|
12
|
+
init(config: IConfiguration, rumSession?: IRumSession): void;
|
|
13
|
+
sendEvent: (payload: RumEvent) => void;
|
|
14
|
+
setContext(ctx: IContext): void;
|
|
15
|
+
getContext(): IContext;
|
|
16
|
+
useCollectors(collectors: ICollector[]): void;
|
|
17
|
+
getCollectors(): ICollector[];
|
|
18
|
+
useProcessors(processors: IProcessor[]): void;
|
|
19
|
+
useReporter(reporter: IReporter): void;
|
|
20
|
+
}
|
|
21
|
+
export default Client;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
+
import { EventType } from '../types/client';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import Context from './context';
|
|
7
|
+
import { isFunction } from "../utils/is";
|
|
8
|
+
var Client = /*#__PURE__*/function () {
|
|
9
|
+
function Client() {
|
|
10
|
+
var _this = this;
|
|
11
|
+
this.emitter = new EventEmitter();
|
|
12
|
+
this.collectors = void 0;
|
|
13
|
+
this.processors = void 0;
|
|
14
|
+
this.reporter = void 0;
|
|
15
|
+
this.ctx = void 0;
|
|
16
|
+
this.sendEvent = function (payload) {
|
|
17
|
+
_this.emitter.emit(EventType.collect, payload);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
var _proto = Client.prototype;
|
|
21
|
+
_proto.init = function init(config, rumSession) {
|
|
22
|
+
var _this2 = this;
|
|
23
|
+
this.ctx = new Context(config, rumSession);
|
|
24
|
+
var ctx = this.ctx,
|
|
25
|
+
collectors = this.collectors,
|
|
26
|
+
processors = this.processors,
|
|
27
|
+
reporter = this.reporter;
|
|
28
|
+
processors.forEach(function (processor) {
|
|
29
|
+
isFunction(processor.setup) && processor.setup(ctx);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// collector 收集数据统一 push 到各匹配 processor
|
|
33
|
+
this.emitter.on(EventType.collect, function (payload) {
|
|
34
|
+
ctx.setRumEvent(payload);
|
|
35
|
+
for (var _iterator = _createForOfIteratorHelperLoose(processors), _step; !(_step = _iterator()).done;) {
|
|
36
|
+
var processor = _step.value;
|
|
37
|
+
// default match return true
|
|
38
|
+
if (!processor.match) {
|
|
39
|
+
processor.match = function () {
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (processor.match(ctx)) {
|
|
44
|
+
var res = processor.process(ctx);
|
|
45
|
+
if (res) {
|
|
46
|
+
ctx.setRumEvent(res);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
reporter.report(ctx);
|
|
51
|
+
});
|
|
52
|
+
collectors.forEach(function (collector) {
|
|
53
|
+
collector.setup(ctx, _this2.sendEvent);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
_proto.setContext = function setContext(ctx) {
|
|
57
|
+
this.ctx = ctx;
|
|
58
|
+
};
|
|
59
|
+
_proto.getContext = function getContext() {
|
|
60
|
+
return this.ctx;
|
|
61
|
+
};
|
|
62
|
+
_proto.useCollectors = function useCollectors(collectors) {
|
|
63
|
+
this.collectors = collectors;
|
|
64
|
+
};
|
|
65
|
+
_proto.getCollectors = function getCollectors() {
|
|
66
|
+
return this.collectors;
|
|
67
|
+
};
|
|
68
|
+
_proto.useProcessors = function useProcessors(processors) {
|
|
69
|
+
this.processors = processors;
|
|
70
|
+
};
|
|
71
|
+
_proto.useReporter = function useReporter(reporter) {
|
|
72
|
+
this.reporter = reporter;
|
|
73
|
+
};
|
|
74
|
+
return Client;
|
|
75
|
+
}();
|
|
76
|
+
export default Client;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IConfiguration, IContext, IRumSession } from "../types/client";
|
|
2
|
+
import { RumEvent, IViewData } from "../types/rum-event";
|
|
3
|
+
declare class Context implements IContext {
|
|
4
|
+
private config;
|
|
5
|
+
private rumEvent;
|
|
6
|
+
private views;
|
|
7
|
+
session: IRumSession;
|
|
8
|
+
constructor(config: IConfiguration, rumSession?: IRumSession);
|
|
9
|
+
getConfig(): IConfiguration;
|
|
10
|
+
setConfig(config: IConfiguration): void;
|
|
11
|
+
getViews(): IViewData[];
|
|
12
|
+
addView(view: IViewData): void;
|
|
13
|
+
removeView(viewId: string): void;
|
|
14
|
+
getRumEvent(): RumEvent;
|
|
15
|
+
setRumEvent(rumEvent: RumEvent): void;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
export default Context;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var Context = /*#__PURE__*/function () {
|
|
2
|
+
function Context(config, rumSession) {
|
|
3
|
+
this.config = config;
|
|
4
|
+
this.rumEvent = void 0;
|
|
5
|
+
this.views = [];
|
|
6
|
+
this.session = void 0;
|
|
7
|
+
if (rumSession) {
|
|
8
|
+
this.session = rumSession;
|
|
9
|
+
this.session.init(this);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
var _proto = Context.prototype;
|
|
13
|
+
_proto.getConfig = function getConfig() {
|
|
14
|
+
return this.config;
|
|
15
|
+
};
|
|
16
|
+
_proto.setConfig = function setConfig(config) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
};
|
|
19
|
+
_proto.getViews = function getViews() {
|
|
20
|
+
return this.views;
|
|
21
|
+
};
|
|
22
|
+
_proto.addView = function addView(view) {
|
|
23
|
+
this.views.push(view);
|
|
24
|
+
};
|
|
25
|
+
_proto.removeView = function removeView(viewId) {
|
|
26
|
+
this.views = this.views.filter(function (view) {
|
|
27
|
+
return view.id !== viewId;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
_proto.getRumEvent = function getRumEvent() {
|
|
31
|
+
return this.rumEvent;
|
|
32
|
+
};
|
|
33
|
+
_proto.setRumEvent = function setRumEvent(rumEvent) {
|
|
34
|
+
this.rumEvent = rumEvent;
|
|
35
|
+
};
|
|
36
|
+
return Context;
|
|
37
|
+
}();
|
|
38
|
+
export default Context;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IContext } from '../types/client';
|
|
2
|
+
import { RumEvent, IViewData, RumEventBundle } from '../types/rum-event';
|
|
3
|
+
export default abstract class Reporter {
|
|
4
|
+
name: string;
|
|
5
|
+
/**
|
|
6
|
+
* 新上报事件优先检测队列是否超过 50 条,如果超过立即 report。
|
|
7
|
+
* 如果没超过则检测 FlushTime 内有无新上报事件,如果有新事件,重置 timer,无则 report
|
|
8
|
+
*/
|
|
9
|
+
protected eventQueue: RumEvent[];
|
|
10
|
+
protected ctx: IContext;
|
|
11
|
+
private timer;
|
|
12
|
+
getReportCfg(): {
|
|
13
|
+
flushTime?: number;
|
|
14
|
+
maxEventCount?: number;
|
|
15
|
+
};
|
|
16
|
+
report(ctx: IContext): void;
|
|
17
|
+
private pushToQueue;
|
|
18
|
+
/**
|
|
19
|
+
* eventQueue 提取最新 View 作为公共 View,event 中不同 View Event 保留 View id
|
|
20
|
+
*/
|
|
21
|
+
protected flushEventQueue(): void;
|
|
22
|
+
mergeEvent(ctx: IContext, events: RumEvent[], view: IViewData): void;
|
|
23
|
+
/**
|
|
24
|
+
* 接口请求由各平台 sdk reporter 实现
|
|
25
|
+
*/
|
|
26
|
+
abstract request(ctx: IContext, bundle: RumEventBundle): void;
|
|
27
|
+
/**
|
|
28
|
+
* 初始化时
|
|
29
|
+
*/
|
|
30
|
+
protected init(ctx: IContext): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { RumEventType } from '../types/rum-event';
|
|
2
|
+
import { getErrorID } from '../utils/exception';
|
|
3
|
+
import { isNumber, isObject, isString } from "../utils/is";
|
|
4
|
+
import { verifyProperties } from "../utils/verify";
|
|
5
|
+
var FLUSH_TIME = 3000;
|
|
6
|
+
var MAX_EVENT_COUNT = 20;
|
|
7
|
+
var attrs = ['app', 'user', 'device', 'os', 'geo', 'isp', 'net', 'properties'];
|
|
8
|
+
var Reporter = /*#__PURE__*/function () {
|
|
9
|
+
function Reporter() {
|
|
10
|
+
this.name = 'reporter';
|
|
11
|
+
/**
|
|
12
|
+
* 新上报事件优先检测队列是否超过 50 条,如果超过立即 report。
|
|
13
|
+
* 如果没超过则检测 FlushTime 内有无新上报事件,如果有新事件,重置 timer,无则 report
|
|
14
|
+
*/
|
|
15
|
+
this.eventQueue = [];
|
|
16
|
+
this.ctx = void 0;
|
|
17
|
+
this.timer = void 0;
|
|
18
|
+
}
|
|
19
|
+
var _proto = Reporter.prototype;
|
|
20
|
+
_proto.getReportCfg = function getReportCfg() {
|
|
21
|
+
var cfg = this.ctx.getConfig().reportConfig;
|
|
22
|
+
if (!isObject(cfg)) {
|
|
23
|
+
cfg = {};
|
|
24
|
+
}
|
|
25
|
+
if (!cfg.flushTime || cfg.flushTime < 0 || cfg.flushTime > 10000) {
|
|
26
|
+
cfg.flushTime = FLUSH_TIME;
|
|
27
|
+
}
|
|
28
|
+
if (!cfg.maxEventCount || cfg.maxEventCount < 1 || cfg.maxEventCount > 100) {
|
|
29
|
+
cfg.maxEventCount = MAX_EVENT_COUNT;
|
|
30
|
+
}
|
|
31
|
+
return cfg;
|
|
32
|
+
};
|
|
33
|
+
_proto.report = function report(ctx) {
|
|
34
|
+
var _this = this;
|
|
35
|
+
this.ctx = ctx;
|
|
36
|
+
this.init(ctx);
|
|
37
|
+
clearTimeout(this.timer);
|
|
38
|
+
this.pushToQueue();
|
|
39
|
+
var reportConfig = this.getReportCfg();
|
|
40
|
+
// 超过 MaxCount 直接 flush,否则延迟发送
|
|
41
|
+
if (this.eventQueue.length >= reportConfig.maxEventCount) {
|
|
42
|
+
this.flushEventQueue();
|
|
43
|
+
} else {
|
|
44
|
+
this.timer = setTimeout(function () {
|
|
45
|
+
_this.flushEventQueue();
|
|
46
|
+
}, reportConfig.flushTime);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
_proto.pushToQueue = function pushToQueue() {
|
|
50
|
+
var ctx = this.ctx,
|
|
51
|
+
eventQueue = this.eventQueue;
|
|
52
|
+
var event = ctx.getRumEvent();
|
|
53
|
+
|
|
54
|
+
// 针对相同 event,做 times 合并
|
|
55
|
+
// todo,支持其他类型 event 合并
|
|
56
|
+
if (event.event_type === RumEventType.EXCEPTION) {
|
|
57
|
+
var _ref = event,
|
|
58
|
+
message = _ref.message,
|
|
59
|
+
stack = _ref.stack;
|
|
60
|
+
var curErrorId = getErrorID({
|
|
61
|
+
message: message,
|
|
62
|
+
stack: stack
|
|
63
|
+
});
|
|
64
|
+
var targetEvent = this.eventQueue.find(function (cacheEvent) {
|
|
65
|
+
if (cacheEvent.event_type === RumEventType.EXCEPTION) {
|
|
66
|
+
var _ref2 = cacheEvent,
|
|
67
|
+
_message = _ref2.message,
|
|
68
|
+
_stack = _ref2.stack;
|
|
69
|
+
return getErrorID({
|
|
70
|
+
message: _message,
|
|
71
|
+
stack: _stack
|
|
72
|
+
}) === curErrorId;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (targetEvent) {
|
|
76
|
+
targetEvent.times++;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (event.event_type === RumEventType.ACTION) {
|
|
81
|
+
var _ref3 = event,
|
|
82
|
+
target_name = _ref3.target_name;
|
|
83
|
+
var _targetEvent = this.eventQueue.find(function (cacheEvent) {
|
|
84
|
+
if (cacheEvent.event_type === RumEventType.ACTION) {
|
|
85
|
+
return target_name === cacheEvent.target_name;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (_targetEvent) {
|
|
89
|
+
_targetEvent.times++;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
eventQueue.push(event);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* eventQueue 提取最新 View 作为公共 View,event 中不同 View Event 保留 View id
|
|
98
|
+
*/;
|
|
99
|
+
_proto.flushEventQueue = function flushEventQueue() {
|
|
100
|
+
var ctx = this.ctx,
|
|
101
|
+
eventQueue = this.eventQueue;
|
|
102
|
+
if (!eventQueue.length) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
var views = ctx.getViews();
|
|
106
|
+
var curView = views[views.length - 1];
|
|
107
|
+
views.forEach(function (view) {
|
|
108
|
+
if (view.id === curView.id) {
|
|
109
|
+
var events = eventQueue.filter(function (event) {
|
|
110
|
+
var _event$view;
|
|
111
|
+
return ((_event$view = event.view) === null || _event$view === void 0 ? void 0 : _event$view.id) === view.id;
|
|
112
|
+
});
|
|
113
|
+
events.forEach(function (event) {
|
|
114
|
+
delete event.view;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
var session = ctx.session;
|
|
119
|
+
var sampled = session ? session.getSampled() : true;
|
|
120
|
+
sampled && this.mergeEvent(ctx, eventQueue, curView);
|
|
121
|
+
this.eventQueue = [];
|
|
122
|
+
};
|
|
123
|
+
_proto.mergeEvent = function mergeEvent(ctx, events, view) {
|
|
124
|
+
var config = ctx.getConfig();
|
|
125
|
+
var session = ctx.session;
|
|
126
|
+
var sessionId = session.getSessionId();
|
|
127
|
+
// events.forEach(event => {
|
|
128
|
+
// if (event.session_id === sessionId) {
|
|
129
|
+
// delete event.session_id;
|
|
130
|
+
// }
|
|
131
|
+
// });
|
|
132
|
+
for (var i = 0; i < events.length; i++) {
|
|
133
|
+
var e = events[i];
|
|
134
|
+
if (e.session_id === sessionId) {
|
|
135
|
+
delete e.session_id;
|
|
136
|
+
} else {
|
|
137
|
+
events.splice(i, 1);
|
|
138
|
+
i--;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (events.length === 0) return;
|
|
142
|
+
var bundle = {
|
|
143
|
+
app: {
|
|
144
|
+
id: config.pid,
|
|
145
|
+
env: config.env || 'prod',
|
|
146
|
+
version: config.version,
|
|
147
|
+
type: ''
|
|
148
|
+
},
|
|
149
|
+
user: {
|
|
150
|
+
id: session.getUserId()
|
|
151
|
+
},
|
|
152
|
+
session: {
|
|
153
|
+
id: sessionId
|
|
154
|
+
},
|
|
155
|
+
net: {},
|
|
156
|
+
view: view,
|
|
157
|
+
events: events
|
|
158
|
+
};
|
|
159
|
+
attrs.forEach(function (key) {
|
|
160
|
+
var obj = config[key];
|
|
161
|
+
isObject(obj) && Object.keys(obj).forEach(function (k) {
|
|
162
|
+
var val = obj[k];
|
|
163
|
+
// user 的 id 不能被覆盖
|
|
164
|
+
if (key === 'user' && k === 'id') return;
|
|
165
|
+
if (key === 'properties') {
|
|
166
|
+
bundle[key] = verifyProperties(obj);
|
|
167
|
+
} else if (isString(val) || isNumber(val)) {
|
|
168
|
+
if (!(key in bundle)) {
|
|
169
|
+
bundle[key] = {};
|
|
170
|
+
}
|
|
171
|
+
bundle[key][k] = val;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
if (typeof config.beforeReport === 'function') {
|
|
176
|
+
bundle = config.beforeReport(bundle);
|
|
177
|
+
if (!bundle) return;
|
|
178
|
+
}
|
|
179
|
+
this.request(ctx, bundle);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// /**
|
|
183
|
+
// * 接口请求由各平台 sdk reporter 实现
|
|
184
|
+
// */
|
|
185
|
+
// abstract request(ctx: IContext, events: RumEvent[], view: IViewData): void;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 接口请求由各平台 sdk reporter 实现
|
|
189
|
+
*/;
|
|
190
|
+
/**
|
|
191
|
+
* 初始化时
|
|
192
|
+
*/
|
|
193
|
+
_proto.init = function init(ctx) {};
|
|
194
|
+
return Reporter;
|
|
195
|
+
}();
|
|
196
|
+
export { Reporter as default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IClient, IConfiguration } from "../types/client";
|
|
2
|
+
import { RumCustomEvent, RumEvent, RumExceptionEvent, RumResourceEvent, RumViewEvent } 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
|
+
getCombinedConfig(config?: IConfiguration): any;
|
|
8
|
+
updateFromRemoteConfig(config: any, reSetup?: boolean): void;
|
|
9
|
+
/**
|
|
10
|
+
* 初始化
|
|
11
|
+
*/
|
|
12
|
+
abstract init(configuration: IConfiguration): void;
|
|
13
|
+
sendEvent(payload: RumEvent): void;
|
|
14
|
+
/**
|
|
15
|
+
* get config
|
|
16
|
+
*/
|
|
17
|
+
getConfig(): IConfiguration;
|
|
18
|
+
/**
|
|
19
|
+
* 获取远程配置
|
|
20
|
+
*/
|
|
21
|
+
abstract getRemoteConfig(url: string, config: any): object;
|
|
22
|
+
/**
|
|
23
|
+
* 存储远程配置到本地
|
|
24
|
+
*/
|
|
25
|
+
abstract storeRemoteConfig(config: any, pid: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 提取本地存储的配置
|
|
28
|
+
*/
|
|
29
|
+
abstract getLocalConfig(duration: number, pid: string): any;
|
|
30
|
+
/**
|
|
31
|
+
* set config
|
|
32
|
+
*/
|
|
33
|
+
abstract setConfig<T extends keyof IConfiguration>(key: T, value: IConfiguration[T]): void;
|
|
34
|
+
abstract setConfig(value: IConfiguration): void;
|
|
35
|
+
/**
|
|
36
|
+
* 自定义事件上报
|
|
37
|
+
*/
|
|
38
|
+
sendCustom(payload: RumCustomEvent): void;
|
|
39
|
+
/**
|
|
40
|
+
* 自定义视图上报
|
|
41
|
+
*/
|
|
42
|
+
sendView(payload: RumViewEvent): void;
|
|
43
|
+
/**
|
|
44
|
+
* 自定义异常上报
|
|
45
|
+
*/
|
|
46
|
+
sendException(payload: RumExceptionEvent | Error): void;
|
|
47
|
+
/**
|
|
48
|
+
* 自定义资源上报
|
|
49
|
+
*/
|
|
50
|
+
sendResource(payload: RumResourceEvent): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { RumEventType } from "../types/rum-event";
|
|
3
|
+
import Client from '../model/client';
|
|
4
|
+
import { isNumber, isFunction, isObject } from "../utils/is";
|
|
5
|
+
import combineConfig, { isRemoteConfigEnable, getRemoteConfigUrl } from "../utils/combineConfig";
|
|
6
|
+
var Shell = /*#__PURE__*/function () {
|
|
7
|
+
function Shell(config) {
|
|
8
|
+
this.client = void 0;
|
|
9
|
+
this.client = new Client();
|
|
10
|
+
if (config && this.init) {
|
|
11
|
+
this.init(config);
|
|
12
|
+
}
|
|
13
|
+
// if (config && this.init) {
|
|
14
|
+
// this.init(this.getCombinedConfig(config));
|
|
15
|
+
|
|
16
|
+
// // 拉取远程配置进行更新
|
|
17
|
+
// this.updateFromRemoteConfig(config);
|
|
18
|
+
// }
|
|
19
|
+
}
|
|
20
|
+
var _proto = Shell.prototype;
|
|
21
|
+
_proto.getCombinedConfig = function getCombinedConfig(config) {
|
|
22
|
+
var combinedConf;
|
|
23
|
+
if (isRemoteConfigEnable(config) && isFunction(this.getLocalConfig)) {
|
|
24
|
+
var localConfig = this.getLocalConfig(0, config.pid);
|
|
25
|
+
combinedConf = combineConfig(config, localConfig);
|
|
26
|
+
}
|
|
27
|
+
return combinedConf || config;
|
|
28
|
+
};
|
|
29
|
+
_proto.updateFromRemoteConfig = function updateFromRemoteConfig(config, reSetup) {
|
|
30
|
+
if (reSetup === void 0) {
|
|
31
|
+
reSetup = true;
|
|
32
|
+
}
|
|
33
|
+
// 请求动态配置
|
|
34
|
+
if (config.pid && isRemoteConfigEnable(config) && isFunction(this.getRemoteConfig)) {
|
|
35
|
+
var that = this;
|
|
36
|
+
var proms = this.getRemoteConfig(getRemoteConfigUrl(config), config);
|
|
37
|
+
proms === null || proms === void 0 ? void 0 : proms.then(function (remoteConfig) {
|
|
38
|
+
if (!remoteConfig || remoteConfig.errorStatus !== undefined) return;
|
|
39
|
+
var combinedConf = combineConfig(config, remoteConfig);
|
|
40
|
+
|
|
41
|
+
// 无有效的新配置,无需更新
|
|
42
|
+
if (!combinedConf) return;
|
|
43
|
+
|
|
44
|
+
// 存储到本地
|
|
45
|
+
if (isFunction(that.storeRemoteConfig)) {
|
|
46
|
+
that.storeRemoteConfig(remoteConfig, config.pid);
|
|
47
|
+
}
|
|
48
|
+
if (reSetup === false || config.remoteConfig.reSetup === false) return;
|
|
49
|
+
var context = that.client.getContext();
|
|
50
|
+
// 更新配置
|
|
51
|
+
context.setConfig(combinedConf);
|
|
52
|
+
// 逐个更新collector
|
|
53
|
+
var collectors = that.client.getCollectors();
|
|
54
|
+
collectors.forEach(function (collector) {
|
|
55
|
+
if (isFunction(collector.destroy)) {
|
|
56
|
+
collector.destroy();
|
|
57
|
+
collector.setup(context, that.client.sendEvent);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 初始化
|
|
66
|
+
*/;
|
|
67
|
+
_proto.sendEvent = function sendEvent(payload) {
|
|
68
|
+
if (this.client) {
|
|
69
|
+
this.client.sendEvent(payload);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* get config
|
|
75
|
+
*/;
|
|
76
|
+
_proto.getConfig = function getConfig() {
|
|
77
|
+
if (this.client) {
|
|
78
|
+
return this.client.getContext().getConfig();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 获取远程配置
|
|
84
|
+
*/;
|
|
85
|
+
/**
|
|
86
|
+
* 自定义事件上报
|
|
87
|
+
*/
|
|
88
|
+
_proto.sendCustom = function sendCustom(payload) {
|
|
89
|
+
if (!payload.name || !payload.type) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var data = _extends({}, payload, {
|
|
93
|
+
event_type: RumEventType.CUSTOM
|
|
94
|
+
});
|
|
95
|
+
this.sendEvent(data);
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* 自定义视图上报
|
|
99
|
+
*/
|
|
100
|
+
_proto.sendView = function sendView(payload) {
|
|
101
|
+
if (!isObject(payload)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!payload.type) {
|
|
105
|
+
payload.type = 'custom';
|
|
106
|
+
}
|
|
107
|
+
if (payload.type === 'custom') {
|
|
108
|
+
var n = 0;
|
|
109
|
+
['t1', 't2', 't3'].forEach(function (key) {
|
|
110
|
+
if (!isNumber(payload[key])) {
|
|
111
|
+
delete payload[key];
|
|
112
|
+
}
|
|
113
|
+
key in payload && n++;
|
|
114
|
+
});
|
|
115
|
+
if (n === 0) return;
|
|
116
|
+
}
|
|
117
|
+
var data = _extends({}, payload, {
|
|
118
|
+
event_type: RumEventType.VIEW
|
|
119
|
+
});
|
|
120
|
+
this.sendEvent(data);
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* 自定义异常上报
|
|
124
|
+
*/
|
|
125
|
+
_proto.sendException = function sendException(payload) {
|
|
126
|
+
if (!payload.name || !payload.message) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
var name = payload.name,
|
|
130
|
+
message = payload.message,
|
|
131
|
+
stack = payload.stack;
|
|
132
|
+
var data = _extends({
|
|
133
|
+
times: 1,
|
|
134
|
+
name: name,
|
|
135
|
+
message: message,
|
|
136
|
+
stack: stack
|
|
137
|
+
}, payload, {
|
|
138
|
+
event_type: RumEventType.EXCEPTION,
|
|
139
|
+
type: 'custom',
|
|
140
|
+
source: 'custom'
|
|
141
|
+
});
|
|
142
|
+
this.sendEvent(data);
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* 自定义资源上报
|
|
146
|
+
*/
|
|
147
|
+
_proto.sendResource = function sendResource(payload) {
|
|
148
|
+
if (!payload.name || !payload.type || !isNumber(payload.duration)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
var data = _extends({
|
|
152
|
+
times: 1
|
|
153
|
+
}, payload, {
|
|
154
|
+
event_type: RumEventType.RESOURCE
|
|
155
|
+
});
|
|
156
|
+
this.sendEvent(data);
|
|
157
|
+
};
|
|
158
|
+
return Shell;
|
|
159
|
+
}();
|
|
160
|
+
export { Shell as default };
|
package/es/style.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//empty file
|