@arms/rum-core 0.0.25-beta.18 → 0.0.25-beta.20
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 +1 -0
- package/lib/index.js +7 -0
- package/lib/model/context.js +1 -1
- package/lib/model/reporter.d.ts +3 -2
- package/lib/model/reporter.js +61 -3
- package/lib/types/client.d.ts +3 -1
- package/lib/types/reporter.d.ts +2 -2
- package/lib/types/rum-event.d.ts +13 -6
- package/lib/types/rum-event.js +1 -0
- package/lib/utils/base.js +9 -21
- package/lib/utils/verify.d.ts +2 -0
- package/lib/utils/verify.js +39 -0
- package/package.json +2 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -99,4 +99,11 @@ Object.keys(_trace).forEach(function (key) {
|
|
|
99
99
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
100
100
|
if (key in exports && exports[key] === _trace[key]) return;
|
|
101
101
|
exports[key] = _trace[key];
|
|
102
|
+
});
|
|
103
|
+
var _verify = require("./utils/verify");
|
|
104
|
+
Object.keys(_verify).forEach(function (key) {
|
|
105
|
+
if (key === "default" || key === "__esModule") return;
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
107
|
+
if (key in exports && exports[key] === _verify[key]) return;
|
|
108
|
+
exports[key] = _verify[key];
|
|
102
109
|
});
|
package/lib/model/context.js
CHANGED
package/lib/model/reporter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IContext } from '../types/client';
|
|
2
|
-
import { RumEvent, IViewData } from '../types/rum-event';
|
|
2
|
+
import { RumEvent, IViewData, RumEventBundle } from '../types/rum-event';
|
|
3
3
|
export default abstract class Reporter {
|
|
4
4
|
name: string;
|
|
5
5
|
/**
|
|
@@ -19,10 +19,11 @@ export default abstract class Reporter {
|
|
|
19
19
|
* eventQueue 提取最新 View 作为公共 View,event 中不同 View Event 保留 View id
|
|
20
20
|
*/
|
|
21
21
|
protected flushEventQueue(): void;
|
|
22
|
+
mergeEvent(ctx: IContext, events: RumEvent[], view: IViewData): void;
|
|
22
23
|
/**
|
|
23
24
|
* 接口请求由各平台 sdk reporter 实现
|
|
24
25
|
*/
|
|
25
|
-
abstract request(ctx: IContext,
|
|
26
|
+
abstract request(ctx: IContext, bundle: RumEventBundle): void;
|
|
26
27
|
/**
|
|
27
28
|
* 初始化时
|
|
28
29
|
*/
|
package/lib/model/reporter.js
CHANGED
|
@@ -5,8 +5,10 @@ exports["default"] = void 0;
|
|
|
5
5
|
var _rumEvent = require("../types/rum-event");
|
|
6
6
|
var _exception = require("../utils/exception");
|
|
7
7
|
var _is = require("../utils/is");
|
|
8
|
+
var _verify = require("../utils/verify");
|
|
8
9
|
var FLUSH_TIME = 3000;
|
|
9
10
|
var MAX_EVENT_COUNT = 20;
|
|
11
|
+
var attrs = ['app', 'user', 'device', 'os', 'geo', 'isp', 'net', 'attributes'];
|
|
10
12
|
var Reporter = exports["default"] = /*#__PURE__*/function () {
|
|
11
13
|
function Reporter() {
|
|
12
14
|
this.name = 'reporter';
|
|
@@ -108,21 +110,77 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
|
|
|
108
110
|
var curView = views[views.length - 1];
|
|
109
111
|
views.forEach(function (view) {
|
|
110
112
|
if (view.id === curView.id) {
|
|
111
|
-
var
|
|
113
|
+
var events = eventQueue.filter(function (event) {
|
|
112
114
|
var _event$view;
|
|
113
115
|
return ((_event$view = event.view) === null || _event$view === void 0 ? void 0 : _event$view.id) === view.id;
|
|
114
116
|
});
|
|
115
|
-
|
|
117
|
+
events.forEach(function (event) {
|
|
116
118
|
delete event.view;
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
121
|
});
|
|
120
122
|
var session = ctx.session;
|
|
121
123
|
var sampled = session ? session.getSampled() : true;
|
|
122
|
-
sampled && this.
|
|
124
|
+
sampled && this.mergeEvent(ctx, eventQueue, curView);
|
|
123
125
|
this.eventQueue = [];
|
|
126
|
+
};
|
|
127
|
+
_proto.mergeEvent = function mergeEvent(ctx, events, view) {
|
|
128
|
+
var _config$net;
|
|
129
|
+
var config = ctx.getConfig();
|
|
130
|
+
var session = ctx.session;
|
|
131
|
+
var sessionId = session.getSessionId();
|
|
132
|
+
events.forEach(function (event) {
|
|
133
|
+
if (event.session_id === sessionId) {
|
|
134
|
+
delete event.session_id;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
var bundle = {
|
|
138
|
+
app: {
|
|
139
|
+
id: config.pid,
|
|
140
|
+
env: config.env || 'prod',
|
|
141
|
+
version: config.version,
|
|
142
|
+
type: ''
|
|
143
|
+
},
|
|
144
|
+
user: {
|
|
145
|
+
id: session.getUserId()
|
|
146
|
+
},
|
|
147
|
+
session: {
|
|
148
|
+
id: sessionId
|
|
149
|
+
},
|
|
150
|
+
net: {
|
|
151
|
+
model: (_config$net = config.net) === null || _config$net === void 0 ? void 0 : _config$net.model
|
|
152
|
+
},
|
|
153
|
+
view: view,
|
|
154
|
+
events: events
|
|
155
|
+
};
|
|
156
|
+
attrs.forEach(function (key) {
|
|
157
|
+
var obj = config[key];
|
|
158
|
+
(0, _is.isObject)(obj) && Object.keys(obj).forEach(function (k) {
|
|
159
|
+
var val = obj[k];
|
|
160
|
+
// user 的 id 不能被覆盖
|
|
161
|
+
if (key === 'user' && k === 'id') return;
|
|
162
|
+
if (key === 'attributes') {
|
|
163
|
+
bundle[key] = (0, _verify.verifyAttributes)(obj);
|
|
164
|
+
} else if ((0, _is.isString)(val) || (0, _is.isNumber)(val)) {
|
|
165
|
+
if (!(key in bundle)) {
|
|
166
|
+
bundle[key] = {};
|
|
167
|
+
}
|
|
168
|
+
bundle[key][k] = val;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
if (typeof config.beforeReport === 'function') {
|
|
173
|
+
bundle = config.beforeReport(bundle);
|
|
174
|
+
if (!bundle) return;
|
|
175
|
+
}
|
|
176
|
+
this.request(ctx, bundle);
|
|
124
177
|
}
|
|
125
178
|
|
|
179
|
+
// /**
|
|
180
|
+
// * 接口请求由各平台 sdk reporter 实现
|
|
181
|
+
// */
|
|
182
|
+
// abstract request(ctx: IContext, events: RumEvent[], view: IViewData): void;
|
|
183
|
+
|
|
126
184
|
/**
|
|
127
185
|
* 接口请求由各平台 sdk reporter 实现
|
|
128
186
|
*/;
|
package/lib/types/client.d.ts
CHANGED
|
@@ -33,9 +33,10 @@ export interface SessionConfig {
|
|
|
33
33
|
sampleRate?: number;
|
|
34
34
|
maxDuration?: number;
|
|
35
35
|
overtime?: number;
|
|
36
|
+
storage?: string;
|
|
36
37
|
}
|
|
37
38
|
export interface IRumSession {
|
|
38
|
-
init(
|
|
39
|
+
init(ctx: IContext): void;
|
|
39
40
|
sessionConfig: SessionConfig;
|
|
40
41
|
getSessionId: () => string;
|
|
41
42
|
getSampled: () => boolean;
|
|
@@ -43,6 +44,7 @@ export interface IRumSession {
|
|
|
43
44
|
getEventId: () => string;
|
|
44
45
|
getViewId: () => string;
|
|
45
46
|
getUserId: () => string;
|
|
47
|
+
getBaseEvent: () => any;
|
|
46
48
|
}
|
|
47
49
|
export interface IClient {
|
|
48
50
|
/**
|
package/lib/types/reporter.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IContext } from './client';
|
|
2
|
-
import {
|
|
2
|
+
import { RumEventBundle } from './rum-event';
|
|
3
3
|
export interface IReporter {
|
|
4
4
|
name: string;
|
|
5
5
|
init(ctx: IContext): void;
|
|
6
|
-
request(ctx: IContext,
|
|
6
|
+
request(ctx: IContext, bundle: RumEventBundle): void;
|
|
7
7
|
report(ctx: IContext): void;
|
|
8
8
|
}
|
package/lib/types/rum-event.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export declare enum RumEventType {
|
|
|
4
4
|
EXCEPTION = "exception",
|
|
5
5
|
LONG_TASK = "longtask",
|
|
6
6
|
ACTION = "action",
|
|
7
|
-
CUSTOM = "custom"
|
|
7
|
+
CUSTOM = "custom",
|
|
8
|
+
APPLICATION = "application"
|
|
8
9
|
}
|
|
9
10
|
export interface BaseObject {
|
|
10
11
|
[key: string]: BaseObjectValue;
|
|
@@ -15,7 +16,7 @@ export interface IViewData {
|
|
|
15
16
|
}
|
|
16
17
|
export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
|
|
17
18
|
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData;
|
|
18
|
-
export interface RumBaseEvent {
|
|
19
|
+
export interface RumBaseEvent extends BaseObject {
|
|
19
20
|
event_type?: RumEventType;
|
|
20
21
|
event_id?: string;
|
|
21
22
|
session_id?: string;
|
|
@@ -23,7 +24,7 @@ export interface RumBaseEvent {
|
|
|
23
24
|
times?: number;
|
|
24
25
|
view?: IViewData;
|
|
25
26
|
snapshots?: string;
|
|
26
|
-
|
|
27
|
+
attributes?: BaseObject;
|
|
27
28
|
}
|
|
28
29
|
export interface RumViewEvent extends RumBaseEvent {
|
|
29
30
|
loading_type?: 'initial_load' | 'route_change';
|
|
@@ -102,7 +103,12 @@ export interface RumCustomEvent extends RumBaseEvent {
|
|
|
102
103
|
group?: string;
|
|
103
104
|
value: number;
|
|
104
105
|
}
|
|
105
|
-
export
|
|
106
|
+
export interface RumApplicationEvent extends RumBaseEvent {
|
|
107
|
+
type: string;
|
|
108
|
+
name: string;
|
|
109
|
+
duration: number;
|
|
110
|
+
}
|
|
111
|
+
export type RumEvent = RumViewEvent | RumResourceEvent | RumExceptionEvent | RumActionEvent | RumCustomEvent | RumApplicationEvent;
|
|
106
112
|
export declare enum AppType {
|
|
107
113
|
browser = "browser",
|
|
108
114
|
miniapp = "miniapp",
|
|
@@ -111,7 +117,7 @@ export declare enum AppType {
|
|
|
111
117
|
export interface RumEventBundle {
|
|
112
118
|
app: {
|
|
113
119
|
id: string;
|
|
114
|
-
type: AppType;
|
|
120
|
+
type: AppType | string;
|
|
115
121
|
name?: string;
|
|
116
122
|
version?: string;
|
|
117
123
|
channel?: string;
|
|
@@ -160,5 +166,6 @@ export interface RumEventBundle {
|
|
|
160
166
|
name?: string;
|
|
161
167
|
};
|
|
162
168
|
events: Array<RumEvent>;
|
|
163
|
-
|
|
169
|
+
attributes?: BaseObject;
|
|
170
|
+
_v?: string;
|
|
164
171
|
}
|
package/lib/types/rum-event.js
CHANGED
|
@@ -9,6 +9,7 @@ var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
|
9
9
|
RumEventType["LONG_TASK"] = "longtask";
|
|
10
10
|
RumEventType["ACTION"] = "action";
|
|
11
11
|
RumEventType["CUSTOM"] = "custom";
|
|
12
|
+
RumEventType["APPLICATION"] = "application";
|
|
12
13
|
return RumEventType;
|
|
13
14
|
}({});
|
|
14
15
|
/**
|
package/lib/utils/base.js
CHANGED
|
@@ -14,27 +14,15 @@ var _is = require("./is");
|
|
|
14
14
|
*/
|
|
15
15
|
function interceptFunction(target, name, callback) {
|
|
16
16
|
var registeredMethod = target[name];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
target[name] = function () {
|
|
27
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
28
|
-
args[_key] = arguments[_key];
|
|
29
|
-
}
|
|
30
|
-
callback.apply(this, args);
|
|
31
|
-
if (registeredMethod) {
|
|
32
|
-
return registeredMethod.apply(this, args);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
} catch (e) {
|
|
36
|
-
//
|
|
37
|
-
}
|
|
17
|
+
target[name] = function () {
|
|
18
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
19
|
+
args[_key] = arguments[_key];
|
|
20
|
+
}
|
|
21
|
+
callback.apply(this, args);
|
|
22
|
+
if ((0, _is.isFunction)(registeredMethod)) {
|
|
23
|
+
return registeredMethod.apply(this, args);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
38
26
|
}
|
|
39
27
|
|
|
40
28
|
/**
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.verifyAttributes = verifyAttributes;
|
|
5
|
+
var _is = require("./is");
|
|
6
|
+
function verifyAttributes(attrs) {
|
|
7
|
+
if (!(0, _is.isObject)(attrs)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var copyAttrs = Object.assign({}, attrs);
|
|
11
|
+
Object.keys(copyAttrs).forEach(function (key) {
|
|
12
|
+
var val = copyAttrs[key];
|
|
13
|
+
// 验证 key 长度
|
|
14
|
+
if (key.length > 50) {
|
|
15
|
+
var shortKey = key.substring(0, 50);
|
|
16
|
+
copyAttrs[shortKey] = val;
|
|
17
|
+
delete copyAttrs[key];
|
|
18
|
+
key = shortKey;
|
|
19
|
+
}
|
|
20
|
+
// 验证 value 类型和长度
|
|
21
|
+
if (!(0, _is.isString)(val) && !(0, _is.isNumber)(val)) {
|
|
22
|
+
delete copyAttrs[key];
|
|
23
|
+
} else if ((0, _is.isString)(val) && val.length > 2e3) {
|
|
24
|
+
copyAttrs[key] = val.substring(0, 2e3);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
var keys = Object.keys(copyAttrs);
|
|
28
|
+
if (!keys.length) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (keys.length > 20) {
|
|
32
|
+
keys.forEach(function (key, index) {
|
|
33
|
+
if (index > 19) {
|
|
34
|
+
delete copyAttrs[key];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return copyAttrs;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arms/rum-core",
|
|
3
|
-
"version": "0.0.25-beta.
|
|
3
|
+
"version": "0.0.25-beta.20",
|
|
4
4
|
"description": "arms rum javascript sdk core",
|
|
5
5
|
"author": "guangli.fj <guangli.fj@alibaba-inc.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"js-base64": "^3.7.7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
+
"@babel/runtime": "^7.24.5",
|
|
29
30
|
"typescript": "^4.9.4"
|
|
30
31
|
}
|
|
31
32
|
}
|