@arms/rum-core 0.0.40 → 0.1.2

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.
Files changed (49) hide show
  1. package/es/index.d.ts +3 -0
  2. package/es/index.js +3 -0
  3. package/es/model/client.d.ts +2 -1
  4. package/es/model/client.js +2 -2
  5. package/es/model/configManager.d.ts +58 -0
  6. package/es/model/configManager.js +178 -0
  7. package/es/model/context.d.ts +3 -1
  8. package/es/model/context.js +13 -2
  9. package/es/model/reporter.d.ts +2 -4
  10. package/es/model/reporter.js +48 -9
  11. package/es/model/shell.d.ts +1 -15
  12. package/es/model/shell.js +23 -52
  13. package/es/types/client.d.ts +58 -7
  14. package/es/types/client.js +6 -1
  15. package/es/types/config.d.ts +49 -0
  16. package/es/types/config.js +1 -0
  17. package/es/types/rum-event.d.ts +1 -0
  18. package/es/utils/base.d.ts +4 -4
  19. package/es/utils/base.js +62 -33
  20. package/es/utils/match.d.ts +6 -0
  21. package/es/utils/match.js +34 -0
  22. package/es/utils/trace.d.ts +5 -1
  23. package/lib/index.d.ts +3 -0
  24. package/lib/index.js +21 -0
  25. package/lib/model/client.d.ts +2 -1
  26. package/lib/model/client.js +2 -2
  27. package/lib/model/configManager.d.ts +58 -0
  28. package/lib/model/configManager.js +183 -0
  29. package/lib/model/context.d.ts +3 -1
  30. package/lib/model/context.js +13 -2
  31. package/lib/model/reporter.d.ts +2 -4
  32. package/lib/model/reporter.js +48 -9
  33. package/lib/model/shell.d.ts +1 -15
  34. package/lib/model/shell.js +22 -53
  35. package/lib/types/client.d.ts +58 -7
  36. package/lib/types/client.js +5 -1
  37. package/lib/types/config.d.ts +49 -0
  38. package/lib/types/config.js +3 -0
  39. package/lib/types/rum-event.d.ts +1 -0
  40. package/lib/utils/base.d.ts +4 -4
  41. package/lib/utils/base.js +63 -34
  42. package/lib/utils/match.d.ts +6 -0
  43. package/lib/utils/match.js +35 -0
  44. package/lib/utils/trace.d.ts +5 -1
  45. package/package.json +1 -1
  46. package/es/utils/combineConfig.d.ts +0 -15
  47. package/es/utils/combineConfig.js +0 -101
  48. package/lib/utils/combineConfig.d.ts +0 -15
  49. package/lib/utils/combineConfig.js +0 -107
@@ -3,6 +3,7 @@ import { IProcessor } from './processor';
3
3
  import { IReporter } from './reporter';
4
4
  import { RumEvent, RumEventBundle, IViewData } from './rum-event';
5
5
  import { MatchOption } from "../utils/match";
6
+ import { IConfigManager } from "./config";
6
7
  export declare enum EventType {
7
8
  /**
8
9
  * 收集数据
@@ -35,6 +36,12 @@ export interface SessionConfig {
35
36
  overtime?: number;
36
37
  storage?: string;
37
38
  }
39
+ export interface IReportConfig {
40
+ flushTime?: number;
41
+ maxEventCount?: number;
42
+ maxRetryCount?: number;
43
+ retryDelay?: number;
44
+ }
38
45
  export interface IRumSession {
39
46
  init(ctx: IContext): void;
40
47
  sessionConfig: SessionConfig;
@@ -46,11 +53,54 @@ export interface IRumSession {
46
53
  getUserId: () => string;
47
54
  getBaseEvent: () => any;
48
55
  }
56
+ /**
57
+ * 远端监控配置接口
58
+ * @remarks 用于控制RUM数据采集的远程配置策略
59
+ */
60
+ export interface IRemoteConfig {
61
+ /**
62
+ * 是否启用远端配置 (default: false)
63
+ * @example true - 开启云端配置动态管控
64
+ */
65
+ enable?: boolean;
66
+ /**
67
+ * 配置服务器URL (required when enable=true)
68
+ * @format URL
69
+ */
70
+ url?: string;
71
+ /**
72
+ * 配置获取策略模式 (default: 'launch-first')
73
+ * @enum
74
+ * - 'launch-first': 启动优先模式,先使用本地配置快速启动,异步获取最新配置
75
+ * - 'remote-first': 云端优先模式,阻塞等待云端配置,超时后降级到本地
76
+ */
77
+ mode?: 'launch-first' | 'remote-first';
78
+ /**
79
+ * 配置缓存有效期(单位:毫秒,默认:3600000/1小时)
80
+ * @remarks 控制本地配置缓存刷新频率,超时后重新请求云端配置
81
+ * @example 1800000 - 30分钟更新一次配置
82
+ */
83
+ cacheTimeout?: number;
84
+ /**
85
+ * 配置远程配置拉取Region,兼容 0.0.x 版本远端配置
86
+ * @remarks 拉取远端配置地域
87
+ * @example cn-hangzhou 国内主要地区
88
+ */
89
+ region?: string;
90
+ [key: string]: unknown;
91
+ }
92
+ export interface ICollectorConfig {
93
+ name: string;
94
+ enable?: boolean;
95
+ sampling?: number;
96
+ filters?: MatchOption[];
97
+ [key: string]: unknown;
98
+ }
49
99
  export interface IClient {
50
100
  /**
51
101
  * 初始化
52
102
  */
53
- init: (configuration: IConfiguration, rumSession?: IRumSession) => void;
103
+ init: (configuration: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager) => void;
54
104
  /**
55
105
  * 业务自定义上传数据
56
106
  */
@@ -81,6 +131,10 @@ export interface IClient {
81
131
  useReporter(reporter: IReporter): void;
82
132
  }
83
133
  export interface IConfiguration {
134
+ /**
135
+ * 是否开启SDK
136
+ */
137
+ enable?: boolean;
84
138
  /**
85
139
  * 项目 id
86
140
  * v0.0.40开始,不强依赖该参数,通过Endpoint获取 service_id 确定应用
@@ -126,15 +180,12 @@ export interface IConfiguration {
126
180
  /**
127
181
  * reporter 发送节奏配置
128
182
  */
129
- reportConfig?: {
130
- flushTime?: number;
131
- maxEventCount?: number;
132
- };
183
+ reportConfig?: IReportConfig;
133
184
  /**
134
185
  * 配置下发
135
186
  * - 运行时动态配置更新,根据端侧特点来做定制化配置
136
187
  */
137
- remoteConfig?: Boolean;
188
+ remoteConfig?: IRemoteConfig | Boolean;
138
189
  /**
139
190
  * session config
140
191
  */
@@ -143,7 +194,7 @@ export interface IConfiguration {
143
194
  * 各个 collector config
144
195
  */
145
196
  collectors?: {
146
- [key: string]: boolean;
197
+ [key: string]: boolean | ICollectorConfig;
147
198
  };
148
199
  /**
149
200
  * 事件过滤器配置
@@ -4,4 +4,9 @@ export var EventType = /*#__PURE__*/function (EventType) {
4
4
  */
5
5
  EventType["collect"] = "collect";
6
6
  return EventType;
7
- }({});
7
+ }({});
8
+
9
+ /**
10
+ * 远端监控配置接口
11
+ * @remarks 用于控制RUM数据采集的远程配置策略
12
+ */
@@ -0,0 +1,49 @@
1
+ import { IConfiguration } from './client';
2
+ export interface ICacheConfiguration {
3
+ /**
4
+ * 时间戳
5
+ */
6
+ timestamp: number;
7
+ /**
8
+ * 内容
9
+ */
10
+ content: any;
11
+ }
12
+ /**
13
+ * 配置管理器接口
14
+ * 统一管理配置的获取、存储、合并等操作
15
+ */
16
+ export interface IConfigManager {
17
+ /**
18
+ * 初始化配置管理器
19
+ * @param config 初始配置
20
+ */
21
+ init(config: IConfiguration): Promise<void> | void;
22
+ /**
23
+ * 获取配置
24
+ * @returns 配置数据
25
+ */
26
+ getConfig(): Promise<IConfiguration> | any;
27
+ /**
28
+ * 更新配置
29
+ * @param config 新配置
30
+ */
31
+ setConfig(config: Partial<IConfiguration>): Promise<void> | void;
32
+ /**
33
+ * 抽象方法:获取远程配置
34
+ * 各平台需要实现此方法来适配不同的网络请求方式
35
+ * @param config 当前配置
36
+ */
37
+ fetchRemoteCfg(config: IConfiguration): Promise<any>;
38
+ /**
39
+ * 合并配置
40
+ * @param baseConfig 基础配置
41
+ * @param remoteConfig 远程配置
42
+ * @returns 合并后的配置
43
+ */
44
+ mergeRemoteCfg(baseConfig: IConfiguration, remoteConfig: any): IConfiguration | null;
45
+ /**
46
+ * 销毁配置管理器
47
+ */
48
+ destroy(): void;
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -176,5 +176,6 @@ export interface RumEventBundle {
176
176
  events: Array<RumEvent>;
177
177
  properties?: BaseObject;
178
178
  _v?: string;
179
+ _retry?: number;
179
180
  [key: string]: unknown;
180
181
  }
@@ -53,8 +53,8 @@ export declare function getType(obj: any): any;
53
53
  */
54
54
  export declare function transStrToReg(str: string): string | RegExp;
55
55
  /**
56
- *
57
- * @param config 配置
58
- * @param keys 需要转换的字段
56
+ * 解析正则表达式字符串,支持 /pattern/flags 格式
57
+ * @param str 正则表达式字符串,如 "/a/ig" 或 "a"
58
+ * @returns RegExp 对象
59
59
  */
60
- export declare function toRegFormat(config: any, keys: any[]): void;
60
+ export declare function parseRegExpString(str: string): RegExp;
package/es/utils/base.js CHANGED
@@ -174,42 +174,71 @@ export function transStrToReg(str) {
174
174
  return str;
175
175
  }
176
176
 
177
+ // /**
178
+ // *
179
+ // * @param config 配置
180
+ // * @param keys 需要转换的字段
181
+ // */
182
+ // export function toRegFormat(config: any, keys: any[]) {
183
+ // if (getType(keys) === 'string') {
184
+ // keys = [keys];
185
+ // }
186
+ // for (let i = 0, len = keys.length; i < len; i++) {
187
+ // const paths = keys[i].split('.');
188
+ // const lastIndex = paths.length - 1;
189
+ // if (!config) break;
190
+ // let tmp = config;
191
+ // for (let j = 0, jlen = paths.length; j < jlen; j++) {
192
+ // if (paths[j] === '[]') {
193
+ // if (getType(tmp) === 'array') {
194
+ // let lastPath = paths.splice(j + 1);
195
+ // lastPath = lastPath.join('.');
196
+ // for (let x = 0, xlen = tmp.length; x < xlen; x++) {
197
+ // toRegFormat(tmp[x], lastPath);
198
+ // }
199
+ // }
200
+ // break;
201
+ // }
202
+ // // 最后一层了,需要往前一层才能修改对象
203
+ // if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
204
+ // tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
205
+ // break;
206
+ // }
207
+ // tmp = tmp[paths[j]];
208
+ // if (!tmp) break;
209
+ // }
210
+ // if (!tmp || getType(tmp) !== 'array') continue;
211
+ // for (let j = 0, jlen = tmp.length; j < jlen; j++) {
212
+ // tmp[j] = transStrToReg(tmp[j]);
213
+ // }
214
+ // }
215
+ // }
216
+
177
217
  /**
178
- *
179
- * @param config 配置
180
- * @param keys 需要转换的字段
218
+ * 解析正则表达式字符串,支持 /pattern/flags 格式
219
+ * @param str 正则表达式字符串,如 "/a/ig" 或 "a"
220
+ * @returns RegExp 对象
181
221
  */
182
- export function toRegFormat(config, keys) {
183
- if (getType(keys) === 'string') {
184
- keys = [keys];
222
+ export function parseRegExpString(str) {
223
+ if (typeof str !== 'string') {
224
+ throw new TypeError('input must be a string');
185
225
  }
186
- for (var i = 0, len = keys.length; i < len; i++) {
187
- var paths = keys[i].split('.');
188
- var lastIndex = paths.length - 1;
189
- if (!config) break;
190
- var tmp = config;
191
- for (var j = 0, jlen = paths.length; j < jlen; j++) {
192
- if (paths[j] === '[]') {
193
- if (getType(tmp) === 'array') {
194
- var lastPath = paths.splice(j + 1);
195
- lastPath = lastPath.join('.');
196
- for (var x = 0, xlen = tmp.length; x < xlen; x++) {
197
- toRegFormat(tmp[x], lastPath);
198
- }
199
- }
200
- break;
201
- }
202
- // 最后一层了,需要往前一层才能修改对象
203
- if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
204
- tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
205
- break;
206
- }
207
- tmp = tmp[paths[j]];
208
- if (!tmp) break;
209
- }
210
- if (!tmp || getType(tmp) !== 'array') continue;
211
- for (var _j = 0, _jlen = tmp.length; _j < _jlen; _j++) {
212
- tmp[_j] = transStrToReg(tmp[_j]);
226
+
227
+ // 检查是否是 /pattern/flags 格式
228
+ if (str.length > 2 && str[0] === '/') {
229
+ // 从后往前找最后一个 /,作为分隔符
230
+ var lastSlashIndex = str.lastIndexOf('/');
231
+ if (lastSlashIndex > 0) {
232
+ // 提取 pattern(第一个 / 和最后一个 / 之间的内容)
233
+ var pattern = str.substring(1, lastSlashIndex);
234
+ // 提取 flags(最后一个 / 之后的内容)
235
+ var flags = str.substring(lastSlashIndex + 1);
236
+ return new RegExp(pattern, flags);
213
237
  }
238
+ // 如果只有一个 /,当作 /pattern/ 格式处理(无 flags)
239
+ return new RegExp(str.substring(1, str.length - 1));
214
240
  }
241
+
242
+ // 如果不是 /pattern/flags 格式,直接作为 pattern 使用
243
+ return new RegExp(str);
215
244
  }
@@ -5,3 +5,9 @@ export declare function isMatchOption(item: unknown): item is MatchOption;
5
5
  */
6
6
  export declare function matchList(list: MatchOption[], value: string, useStartsWith?: boolean, options?: unknown): boolean;
7
7
  export declare function urlMatch(url: string, list?: MatchOption | MatchOption[]): boolean;
8
+ export interface IRule {
9
+ match: string;
10
+ match_exp: string;
11
+ [key: string]: unknown;
12
+ }
13
+ export declare function parseRule2Match(rule: IRule | MatchOption): MatchOption;
package/es/utils/match.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isArray, isFunction, isRegExp, isString } from "./is";
2
2
  import { startsWith } from "./polyfills";
3
+ import { parseRegExpString } from "./base";
3
4
  export function isMatchOption(item) {
4
5
  return isString(item) || isFunction(item) || isRegExp(item);
5
6
  }
@@ -37,4 +38,37 @@ export function urlMatch(url, list) {
37
38
  } catch (e) {
38
39
  return false;
39
40
  }
41
+ }
42
+ export function parseRule2Match(rule) {
43
+ if (isMatchOption(rule)) {
44
+ return rule;
45
+ }
46
+ var match;
47
+ switch (rule.match_exp) {
48
+ case 'equals':
49
+ match = function match(value) {
50
+ return value === rule.match;
51
+ };
52
+ break;
53
+ case 'not_equals':
54
+ match = function match(value) {
55
+ return value !== rule.match;
56
+ };
57
+ break;
58
+ case 'regex':
59
+ match = parseRegExpString(rule.match);
60
+ break;
61
+ case 'includes':
62
+ match = function match(value) {
63
+ return value.includes(rule.match);
64
+ };
65
+ break;
66
+ case 'starts_with':
67
+ default:
68
+ match = function match(value) {
69
+ return startsWith(value, rule.match);
70
+ };
71
+ break;
72
+ }
73
+ return match;
40
74
  }
@@ -1,8 +1,12 @@
1
1
  import { MatchOption } from "./match";
2
2
  export type PropagatorType = 'tracecontext' | 'b3' | 'b3multi' | 'jaeger' | 'sw8';
3
3
  export type TraceOption = {
4
+ enable?: boolean;
5
+ sampling?: number;
4
6
  match: MatchOption;
5
- propagatorTypes: PropagatorType[];
7
+ propagatorTypes?: PropagatorType[];
8
+ baggage?: boolean;
9
+ tracestate?: boolean;
6
10
  };
7
11
  export declare function isTraceOption(option: any): option is TraceOption;
8
12
  export interface ITracingOption {
package/lib/index.d.ts CHANGED
@@ -2,12 +2,14 @@ import Client from './model/client';
2
2
  import Context from './model/context';
3
3
  import Reporter from './model/reporter';
4
4
  import Shell from './model/shell';
5
+ export * from './model/configManager';
5
6
  export * from './types/client';
6
7
  export * from './types/collector';
7
8
  export * from './types/processor';
8
9
  export * from './types/reporter';
9
10
  export * from './types/rum-event';
10
11
  export * from './types/shell';
12
+ export * from './types/config';
11
13
  export * from './utils/base';
12
14
  export * from './utils/polyfills';
13
15
  export * from './utils/is';
@@ -15,4 +17,5 @@ export * from './utils/number';
15
17
  export * from './utils/match';
16
18
  export * from './utils/trace';
17
19
  export * from './utils/verify';
20
+ export * from './utils/url';
18
21
  export { Client, Context, Reporter, Shell };
package/lib/index.js CHANGED
@@ -16,6 +16,13 @@ var _reporter = _interopRequireDefault(require("./model/reporter"));
16
16
  exports.Reporter = _reporter["default"];
17
17
  var _shell = _interopRequireDefault(require("./model/shell"));
18
18
  exports.Shell = _shell["default"];
19
+ var _configManager = require("./model/configManager");
20
+ Object.keys(_configManager).forEach(function (key) {
21
+ if (key === "default" || key === "__esModule") return;
22
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
23
+ if (key in exports && exports[key] === _configManager[key]) return;
24
+ exports[key] = _configManager[key];
25
+ });
19
26
  var _client2 = require("./types/client");
20
27
  Object.keys(_client2).forEach(function (key) {
21
28
  if (key === "default" || key === "__esModule") return;
@@ -58,6 +65,13 @@ Object.keys(_shell2).forEach(function (key) {
58
65
  if (key in exports && exports[key] === _shell2[key]) return;
59
66
  exports[key] = _shell2[key];
60
67
  });
68
+ var _config = require("./types/config");
69
+ Object.keys(_config).forEach(function (key) {
70
+ if (key === "default" || key === "__esModule") return;
71
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
72
+ if (key in exports && exports[key] === _config[key]) return;
73
+ exports[key] = _config[key];
74
+ });
61
75
  var _base = require("./utils/base");
62
76
  Object.keys(_base).forEach(function (key) {
63
77
  if (key === "default" || key === "__esModule") return;
@@ -106,4 +120,11 @@ Object.keys(_verify).forEach(function (key) {
106
120
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
107
121
  if (key in exports && exports[key] === _verify[key]) return;
108
122
  exports[key] = _verify[key];
123
+ });
124
+ var _url = require("./utils/url");
125
+ Object.keys(_url).forEach(function (key) {
126
+ if (key === "default" || key === "__esModule") return;
127
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
128
+ if (key in exports && exports[key] === _url[key]) return;
129
+ exports[key] = _url[key];
109
130
  });
@@ -1,4 +1,5 @@
1
1
  import { IClient, IConfiguration, IContext, IRumSession } from '../types/client';
2
+ import { IConfigManager } from "../types/config";
2
3
  import { RumEvent } from '../types/rum-event';
3
4
  import { IProcessor } from '../types/processor';
4
5
  import { ICollector } from '../types/collector';
@@ -9,7 +10,7 @@ declare class Client implements IClient {
9
10
  private processors;
10
11
  private reporter;
11
12
  private ctx;
12
- init(config: IConfiguration, rumSession?: IRumSession): void;
13
+ init(config: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager): void;
13
14
  sendEvent: (payload: RumEvent) => void;
14
15
  setContext(ctx: IContext): void;
15
16
  getContext(): IContext;
@@ -23,9 +23,9 @@ var Client = /*#__PURE__*/function () {
23
23
  };
24
24
  }
25
25
  var _proto = Client.prototype;
26
- _proto.init = function init(config, rumSession) {
26
+ _proto.init = function init(config, rumSession, configManager) {
27
27
  var _this2 = this;
28
- this.ctx = new _context["default"](config, rumSession);
28
+ this.ctx = new _context["default"](config, rumSession, configManager);
29
29
  var ctx = this.ctx,
30
30
  collectors = this.collectors,
31
31
  processors = this.processors,
@@ -0,0 +1,58 @@
1
+ import { ICacheConfiguration, IConfigManager } from '../types/config';
2
+ import { IConfiguration } from '../types/client';
3
+ /**
4
+ * 配置管理器
5
+ * 提供配置管理的通用实现,各平台可以继承并实现特定方法
6
+ */
7
+ export declare abstract class ConfigManager implements IConfigManager {
8
+ protected currentConfig: IConfiguration | null;
9
+ protected initialized: boolean;
10
+ /**
11
+ * 初始化配置管理器
12
+ * @param config 初始配置
13
+ */
14
+ init(config: IConfiguration): Promise<void>;
15
+ /**
16
+ * 获取配置
17
+ * @returns 配置数据
18
+ */
19
+ getConfig(): IConfiguration;
20
+ /**
21
+ * 更新配置
22
+ * @param config 新配置
23
+ */
24
+ setConfig(config: Partial<IConfiguration>): Promise<void>;
25
+ /**
26
+ * 检查缓存是否有效
27
+ * @param cachedData 缓存数据
28
+ * @param cacheTimeout 缓存超时时间
29
+ */
30
+ protected isCacheValid(cachedData: any, cacheTimeout?: number): boolean;
31
+ /**
32
+ * 合并配置
33
+ * @param remoteCfg 远程配置
34
+ * @returns 合并后的配置
35
+ */
36
+ mergeRemoteCfg(remoteCfg: any): IConfiguration | null;
37
+ abstract fetchRemoteCfg(config: IConfiguration): Promise<any>;
38
+ /**
39
+ * 抽象方法:获取本地存储的配置
40
+ * 各平台需要实现此方法来适配不同的本地存储方式
41
+ */
42
+ abstract getCacheConfig(): Promise<ICacheConfiguration> | ICacheConfiguration | void;
43
+ /**
44
+ * 抽象方法:存储配置到本地
45
+ * 各平台需要实现此方法来适配不同的本地存储方式
46
+ * @param config 配置数据
47
+ */
48
+ abstract setCacheConfig(config: ICacheConfiguration): void;
49
+ /**
50
+ * 抽象方法:解析远端配置为本地配置
51
+ * @param json 远端下发的配置数据
52
+ */
53
+ abstract parseConfig(json: any): unknown;
54
+ /**
55
+ * 销毁配置管理器
56
+ */
57
+ destroy(): void;
58
+ }