@arms/rum-core 0.0.25-beta.13 → 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/model/client.d.ts +2 -2
- package/lib/model/client.js +6 -2
- package/lib/model/context.d.ts +3 -2
- package/lib/model/context.js +6 -1
- package/lib/model/reporter.js +3 -1
- package/lib/types/client.d.ts +21 -1
- package/lib/types/processor.d.ts +1 -0
- package/lib/types/rum-event.d.ts +11 -2
- package/lib/types/rum-event.js +11 -1
- package/lib/utils/base.d.ts +1 -3
- package/lib/utils/base.js +2 -10
- package/lib/utils/number.d.ts +4 -1
- package/lib/utils/number.js +6 -4
- package/package.json +4 -3
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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 { Client, Context, Reporter, Shell };
|
package/es/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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 { Client, Context, Reporter, Shell };
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
useProcessors(processors: IProcessor[]): void;
|
|
18
|
+
useReporter(reporter: IReporter): void;
|
|
19
|
+
}
|
|
20
|
+
export default Client;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } 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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
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.useProcessors = function useProcessors(processors) {
|
|
66
|
+
this.processors = processors;
|
|
67
|
+
};
|
|
68
|
+
_proto.useReporter = function useReporter(reporter) {
|
|
69
|
+
this.reporter = reporter;
|
|
70
|
+
};
|
|
71
|
+
return Client;
|
|
72
|
+
}();
|
|
73
|
+
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(config);
|
|
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,30 @@
|
|
|
1
|
+
import { IContext } from '../types/client';
|
|
2
|
+
import { RumEvent, IViewData } 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
|
+
/**
|
|
23
|
+
* 接口请求由各平台 sdk reporter 实现
|
|
24
|
+
*/
|
|
25
|
+
abstract request(ctx: IContext, events: RumEvent[], view: IViewData): void;
|
|
26
|
+
/**
|
|
27
|
+
* 初始化时
|
|
28
|
+
*/
|
|
29
|
+
protected init(ctx: IContext): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { RumEventType } from '../types/rum-event';
|
|
2
|
+
import { getErrorID } from '../utils/exception';
|
|
3
|
+
import { isObject } from "../utils/is";
|
|
4
|
+
var FLUSH_TIME = 3000;
|
|
5
|
+
var MAX_EVENT_COUNT = 20;
|
|
6
|
+
var Reporter = /*#__PURE__*/function () {
|
|
7
|
+
function Reporter() {
|
|
8
|
+
this.name = 'reporter';
|
|
9
|
+
/**
|
|
10
|
+
* 新上报事件优先检测队列是否超过 50 条,如果超过立即 report。
|
|
11
|
+
* 如果没超过则检测 FlushTime 内有无新上报事件,如果有新事件,重置 timer,无则 report
|
|
12
|
+
*/
|
|
13
|
+
this.eventQueue = [];
|
|
14
|
+
this.ctx = void 0;
|
|
15
|
+
this.timer = void 0;
|
|
16
|
+
}
|
|
17
|
+
var _proto = Reporter.prototype;
|
|
18
|
+
_proto.getReportCfg = function getReportCfg() {
|
|
19
|
+
var cfg = this.ctx.getConfig().reportConfig;
|
|
20
|
+
if (!isObject(cfg)) {
|
|
21
|
+
cfg = {};
|
|
22
|
+
}
|
|
23
|
+
if (!cfg.flushTime || cfg.flushTime < 0 || cfg.flushTime > 10000) {
|
|
24
|
+
cfg.flushTime = FLUSH_TIME;
|
|
25
|
+
}
|
|
26
|
+
if (!cfg.maxEventCount || cfg.maxEventCount < 1 || cfg.maxEventCount > 100) {
|
|
27
|
+
cfg.maxEventCount = MAX_EVENT_COUNT;
|
|
28
|
+
}
|
|
29
|
+
return cfg;
|
|
30
|
+
};
|
|
31
|
+
_proto.report = function report(ctx) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
this.ctx = ctx;
|
|
34
|
+
this.init(ctx);
|
|
35
|
+
clearTimeout(this.timer);
|
|
36
|
+
this.pushToQueue();
|
|
37
|
+
var reportConfig = this.getReportCfg();
|
|
38
|
+
// 超过 MaxCount 直接 flush,否则延迟发送
|
|
39
|
+
if (this.eventQueue.length >= reportConfig.maxEventCount) {
|
|
40
|
+
this.flushEventQueue();
|
|
41
|
+
} else {
|
|
42
|
+
this.timer = setTimeout(function () {
|
|
43
|
+
_this.flushEventQueue();
|
|
44
|
+
}, reportConfig.flushTime);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
_proto.pushToQueue = function pushToQueue() {
|
|
48
|
+
var ctx = this.ctx,
|
|
49
|
+
eventQueue = this.eventQueue;
|
|
50
|
+
var event = ctx.getRumEvent();
|
|
51
|
+
|
|
52
|
+
// 针对相同 event,做 times 合并
|
|
53
|
+
// todo,支持其他类型 event 合并
|
|
54
|
+
if (event.event_type === RumEventType.EXCEPTION) {
|
|
55
|
+
var _ref = event,
|
|
56
|
+
message = _ref.message,
|
|
57
|
+
stack = _ref.stack;
|
|
58
|
+
var curErrorId = getErrorID({
|
|
59
|
+
message: message,
|
|
60
|
+
stack: stack
|
|
61
|
+
});
|
|
62
|
+
var targetEvent = this.eventQueue.find(function (cacheEvent) {
|
|
63
|
+
if (cacheEvent.event_type === RumEventType.EXCEPTION) {
|
|
64
|
+
var _ref2 = cacheEvent,
|
|
65
|
+
_message = _ref2.message,
|
|
66
|
+
_stack = _ref2.stack;
|
|
67
|
+
return getErrorID({
|
|
68
|
+
message: _message,
|
|
69
|
+
stack: _stack
|
|
70
|
+
}) === curErrorId;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
if (targetEvent) {
|
|
74
|
+
targetEvent.times++;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (event.event_type === RumEventType.ACTION) {
|
|
79
|
+
var _ref3 = event,
|
|
80
|
+
target_name = _ref3.target_name;
|
|
81
|
+
var _targetEvent = this.eventQueue.find(function (cacheEvent) {
|
|
82
|
+
if (cacheEvent.event_type === RumEventType.ACTION) {
|
|
83
|
+
return target_name === cacheEvent.target_name;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (_targetEvent) {
|
|
87
|
+
_targetEvent.times++;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
eventQueue.push(event);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* eventQueue 提取最新 View 作为公共 View,event 中不同 View Event 保留 View id
|
|
96
|
+
*/;
|
|
97
|
+
_proto.flushEventQueue = function flushEventQueue() {
|
|
98
|
+
var ctx = this.ctx,
|
|
99
|
+
eventQueue = this.eventQueue;
|
|
100
|
+
if (!eventQueue.length) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
var views = ctx.getViews();
|
|
104
|
+
var curView = views[views.length - 1];
|
|
105
|
+
views.forEach(function (view) {
|
|
106
|
+
if (view.id === curView.id) {
|
|
107
|
+
var _events = eventQueue.filter(function (event) {
|
|
108
|
+
var _event$view;
|
|
109
|
+
return ((_event$view = event.view) === null || _event$view === void 0 ? void 0 : _event$view.id) === view.id;
|
|
110
|
+
});
|
|
111
|
+
_events.forEach(function (event) {
|
|
112
|
+
delete event.view;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
var session = ctx.session;
|
|
117
|
+
var sampled = session ? session.getSampled() : true;
|
|
118
|
+
sampled && this.request(ctx, eventQueue, curView);
|
|
119
|
+
this.eventQueue = [];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 接口请求由各平台 sdk reporter 实现
|
|
124
|
+
*/;
|
|
125
|
+
/**
|
|
126
|
+
* 初始化时
|
|
127
|
+
*/
|
|
128
|
+
_proto.init = function init(ctx) {};
|
|
129
|
+
return Reporter;
|
|
130
|
+
}();
|
|
131
|
+
export { Reporter as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IClient, IConfiguration } from "../types/client";
|
|
2
|
+
import { RumCustomEvent, RumEvent, RumExceptionEvent, RumResourceEvent } 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: RumCustomEvent): void;
|
|
25
|
+
/**
|
|
26
|
+
* 自定义异常上报
|
|
27
|
+
*/
|
|
28
|
+
sendException(payload: RumExceptionEvent): void;
|
|
29
|
+
/**
|
|
30
|
+
* 自定义资源上报
|
|
31
|
+
*/
|
|
32
|
+
sendResource(payload: RumResourceEvent): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { RumEventType } from "../types/rum-event";
|
|
3
|
+
import Client from '../model/client';
|
|
4
|
+
import { isNumber } from "../utils/is";
|
|
5
|
+
var Shell = /*#__PURE__*/function () {
|
|
6
|
+
function Shell(config) {
|
|
7
|
+
this.client = void 0;
|
|
8
|
+
this.client = new Client();
|
|
9
|
+
if (config && this.init) {
|
|
10
|
+
this.init(config);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 初始化
|
|
16
|
+
*/
|
|
17
|
+
var _proto = Shell.prototype;
|
|
18
|
+
_proto.sendEvent = function sendEvent(payload) {
|
|
19
|
+
if (this.client) {
|
|
20
|
+
this.client.sendEvent(payload);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* get config
|
|
26
|
+
*/;
|
|
27
|
+
_proto.getConfig = function getConfig() {
|
|
28
|
+
if (this.client) {
|
|
29
|
+
return this.client.getContext().getConfig();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* set config
|
|
35
|
+
*/;
|
|
36
|
+
/**
|
|
37
|
+
* 自定义事件上报
|
|
38
|
+
*/
|
|
39
|
+
_proto.sendCustom = function sendCustom(payload) {
|
|
40
|
+
if (!payload.name || !payload.type) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
var data = _extends({}, payload, {
|
|
44
|
+
event_type: RumEventType.CUSTOM
|
|
45
|
+
});
|
|
46
|
+
this.sendEvent(data);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 自定义异常上报
|
|
50
|
+
*/
|
|
51
|
+
_proto.sendException = function sendException(payload) {
|
|
52
|
+
if (!payload.name || !payload.message) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var data = _extends({
|
|
56
|
+
times: 1
|
|
57
|
+
}, payload, {
|
|
58
|
+
event_type: RumEventType.EXCEPTION,
|
|
59
|
+
type: 'custom',
|
|
60
|
+
source: 'custom'
|
|
61
|
+
});
|
|
62
|
+
this.sendEvent(data);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 自定义资源上报
|
|
66
|
+
*/
|
|
67
|
+
_proto.sendResource = function sendResource(payload) {
|
|
68
|
+
if (!payload.name || !payload.type || !isNumber(payload.duration)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
var data = _extends({
|
|
72
|
+
times: 1
|
|
73
|
+
}, payload, {
|
|
74
|
+
event_type: RumEventType.RESOURCE
|
|
75
|
+
});
|
|
76
|
+
this.sendEvent(data);
|
|
77
|
+
};
|
|
78
|
+
return Shell;
|
|
79
|
+
}();
|
|
80
|
+
export { Shell as default };
|
package/es/style.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//empty file
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ICollector } from './collector';
|
|
2
|
+
import { IProcessor } from './processor';
|
|
3
|
+
import { IReporter } from './reporter';
|
|
4
|
+
import { RumEvent, RumEventBundle, IViewData } from './rum-event';
|
|
5
|
+
import { MatchOption } from "../utils/match";
|
|
6
|
+
export declare enum EventType {
|
|
7
|
+
/**
|
|
8
|
+
* 收集数据
|
|
9
|
+
*/
|
|
10
|
+
collect = "collect"
|
|
11
|
+
}
|
|
12
|
+
export interface IContext {
|
|
13
|
+
session: IRumSession;
|
|
14
|
+
/**
|
|
15
|
+
* user config
|
|
16
|
+
*/
|
|
17
|
+
getConfig(): IConfiguration;
|
|
18
|
+
setConfig(config: IConfiguration): void;
|
|
19
|
+
/**
|
|
20
|
+
* view
|
|
21
|
+
*/
|
|
22
|
+
getViews(): IViewData[];
|
|
23
|
+
addView(view: IViewData): void;
|
|
24
|
+
removeView(viewId: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* event
|
|
27
|
+
*/
|
|
28
|
+
getRumEvent(): RumEvent;
|
|
29
|
+
setRumEvent(rumEvent: RumEvent): void;
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}
|
|
32
|
+
export interface SessionConfig {
|
|
33
|
+
sampleRate?: number;
|
|
34
|
+
maxDuration?: number;
|
|
35
|
+
overtime?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface IRumSession {
|
|
38
|
+
init(config: IConfiguration): void;
|
|
39
|
+
sessionConfig: SessionConfig;
|
|
40
|
+
getSessionId: () => string;
|
|
41
|
+
getSampled: () => boolean;
|
|
42
|
+
updateSession: () => void;
|
|
43
|
+
getEventId: () => string;
|
|
44
|
+
getViewId: () => string;
|
|
45
|
+
getUserId: () => string;
|
|
46
|
+
}
|
|
47
|
+
export interface IClient {
|
|
48
|
+
/**
|
|
49
|
+
* 初始化
|
|
50
|
+
*/
|
|
51
|
+
init: (configuration: IConfiguration, rumSession?: IRumSession) => void;
|
|
52
|
+
/**
|
|
53
|
+
* 业务自定义上传数据
|
|
54
|
+
*/
|
|
55
|
+
sendEvent(payload: RumEvent): void;
|
|
56
|
+
/**
|
|
57
|
+
* 修改运行时上下文
|
|
58
|
+
*/
|
|
59
|
+
setContext(ctx: IContext): void;
|
|
60
|
+
/**
|
|
61
|
+
* 获取运行时上下文
|
|
62
|
+
*/
|
|
63
|
+
getContext(): IContext;
|
|
64
|
+
/**
|
|
65
|
+
* 装载 client 需要的 Collector
|
|
66
|
+
*/
|
|
67
|
+
useCollectors(collectors: ICollector[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* 装载 client 需要的 processor
|
|
70
|
+
*/
|
|
71
|
+
useProcessors(processors: IProcessor[]): void;
|
|
72
|
+
/**
|
|
73
|
+
* 装载 client 需要的 report
|
|
74
|
+
*/
|
|
75
|
+
useReporter(reporter: IReporter): void;
|
|
76
|
+
}
|
|
77
|
+
export interface IConfiguration {
|
|
78
|
+
/**
|
|
79
|
+
* 项目 id
|
|
80
|
+
*/
|
|
81
|
+
pid: string;
|
|
82
|
+
/**
|
|
83
|
+
* 应用环境
|
|
84
|
+
*/
|
|
85
|
+
env?: 'prod' | 'gray' | 'pre' | 'daily' | 'local';
|
|
86
|
+
/**
|
|
87
|
+
* 应用版本
|
|
88
|
+
*/
|
|
89
|
+
version?: string;
|
|
90
|
+
/**
|
|
91
|
+
* 用户配置
|
|
92
|
+
*/
|
|
93
|
+
user?: {
|
|
94
|
+
id?: string;
|
|
95
|
+
tags?: string;
|
|
96
|
+
name?: string;
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* 上报地址
|
|
101
|
+
*/
|
|
102
|
+
endpoint: string;
|
|
103
|
+
/**
|
|
104
|
+
* reporter 发送事件之前
|
|
105
|
+
*/
|
|
106
|
+
beforeReport?(bundle: RumEventBundle): any;
|
|
107
|
+
/**
|
|
108
|
+
* reporter 发送节奏配置
|
|
109
|
+
*/
|
|
110
|
+
reportConfig?: {
|
|
111
|
+
flushTime?: number;
|
|
112
|
+
maxEventCount?: number;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* session config
|
|
116
|
+
*/
|
|
117
|
+
sessionConfig?: SessionConfig;
|
|
118
|
+
/**
|
|
119
|
+
* 各个 collector config
|
|
120
|
+
*/
|
|
121
|
+
collectors?: {
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* 事件过滤器配置
|
|
126
|
+
*/
|
|
127
|
+
filters?: {
|
|
128
|
+
view?: MatchOption | MatchOption[];
|
|
129
|
+
resource?: MatchOption | MatchOption[];
|
|
130
|
+
exception?: MatchOption | MatchOption[];
|
|
131
|
+
};
|
|
132
|
+
[key: string]: any;
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IContext } from './client';
|
|
2
|
+
import { RumEvent, IViewData } from './rum-event';
|
|
3
|
+
export interface IReporter {
|
|
4
|
+
name: string;
|
|
5
|
+
init(ctx: IContext): void;
|
|
6
|
+
request(ctx: IContext, events: RumEvent[], view: IViewData): void;
|
|
7
|
+
report(ctx: IContext): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|