@arms/rum-core 0.0.39 → 0.1.1

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 (53) 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 +177 -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 +53 -11
  11. package/es/model/shell.d.ts +1 -15
  12. package/es/model/shell.js +62 -52
  13. package/es/types/client.d.ts +60 -8
  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 +2 -0
  18. package/es/utils/base.d.ts +4 -4
  19. package/es/utils/base.js +70 -42
  20. package/es/utils/combineConfig.js +89 -101
  21. package/es/utils/match.d.ts +6 -0
  22. package/es/utils/match.js +34 -0
  23. package/es/utils/trace.d.ts +5 -1
  24. package/es/utils/url.d.ts +2 -0
  25. package/es/utils/url.js +61 -0
  26. package/lib/index.d.ts +3 -0
  27. package/lib/index.js +21 -0
  28. package/lib/model/client.d.ts +2 -1
  29. package/lib/model/client.js +2 -2
  30. package/lib/model/configManager.d.ts +58 -0
  31. package/lib/model/configManager.js +182 -0
  32. package/lib/model/context.d.ts +3 -1
  33. package/lib/model/context.js +13 -2
  34. package/lib/model/reporter.d.ts +2 -4
  35. package/lib/model/reporter.js +54 -11
  36. package/lib/model/shell.d.ts +1 -15
  37. package/lib/model/shell.js +61 -53
  38. package/lib/types/client.d.ts +60 -8
  39. package/lib/types/client.js +5 -1
  40. package/lib/types/config.d.ts +49 -0
  41. package/lib/types/config.js +3 -0
  42. package/lib/types/rum-event.d.ts +2 -0
  43. package/lib/utils/base.d.ts +4 -4
  44. package/lib/utils/base.js +71 -43
  45. package/lib/utils/combineConfig.js +90 -107
  46. package/lib/utils/match.d.ts +6 -0
  47. package/lib/utils/match.js +35 -0
  48. package/lib/utils/trace.d.ts +5 -1
  49. package/lib/utils/url.d.ts +2 -0
  50. package/lib/utils/url.js +65 -0
  51. package/package.json +2 -2
  52. package/es/utils/combineConfig.d.ts +0 -15
  53. package/lib/utils/combineConfig.d.ts +0 -15
@@ -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,10 +131,15 @@ 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
140
+ * v0.0.40开始,不强依赖该参数,通过Endpoint获取 service_id 确定应用
86
141
  */
87
- pid: string;
142
+ pid?: string;
88
143
  /**
89
144
  * 应用环境
90
145
  */
@@ -125,15 +180,12 @@ export interface IConfiguration {
125
180
  /**
126
181
  * reporter 发送节奏配置
127
182
  */
128
- reportConfig?: {
129
- flushTime?: number;
130
- maxEventCount?: number;
131
- };
183
+ reportConfig?: IReportConfig;
132
184
  /**
133
185
  * 配置下发
134
186
  * - 运行时动态配置更新,根据端侧特点来做定制化配置
135
187
  */
136
- remoteConfig?: Boolean;
188
+ remoteConfig?: IRemoteConfig | Boolean;
137
189
  /**
138
190
  * session config
139
191
  */
@@ -142,7 +194,7 @@ export interface IConfiguration {
142
194
  * 各个 collector config
143
195
  */
144
196
  collectors?: {
145
- [key: string]: boolean;
197
+ [key: string]: boolean | ICollectorConfig;
146
198
  };
147
199
  /**
148
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,4 +176,6 @@ export interface RumEventBundle {
176
176
  events: Array<RumEvent>;
177
177
  properties?: BaseObject;
178
178
  _v?: string;
179
+ _retry?: number;
180
+ [key: string]: unknown;
179
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
@@ -1,7 +1,5 @@
1
1
  import { isFunction } from "./is";
2
2
 
3
- // 插值前缀
4
- var PRE_SUF_FIX = '__';
5
3
  // 类型匹配正则
6
4
  var TYPE_REG = /^\[object ([a-z]*)\]$/;
7
5
 
@@ -13,8 +11,7 @@ export function interceptFunction(target, name, callback, isPrototype) {
13
11
  isPrototype = false;
14
12
  }
15
13
  var registeredMethod = target[name];
16
- target["" + PRE_SUF_FIX + name + PRE_SUF_FIX] = registeredMethod;
17
- target[name] = function () {
14
+ var proxyMethod = function proxyMethod() {
18
15
  var ctx = isPrototype ? this : target;
19
16
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
20
17
  args[_key] = arguments[_key];
@@ -24,17 +21,19 @@ export function interceptFunction(target, name, callback, isPrototype) {
24
21
  return registeredMethod.apply(ctx, args);
25
22
  }
26
23
  };
24
+ proxyMethod._rum_intercepted = registeredMethod;
25
+ target[name] = proxyMethod;
27
26
  }
28
27
 
29
28
  /**
30
29
  * 还原函数
31
30
  */
32
31
  export function restoreFunction(target, name) {
33
- var key = "" + PRE_SUF_FIX + name + PRE_SUF_FIX;
34
- if (typeof target[key] == 'function') {
35
- target[name] = target[key];
36
- delete target[key];
37
- }
32
+ var proxyMethod = target[name];
33
+ if (isFunction(proxyMethod)) return;
34
+ var originalMethod = proxyMethod._rum_intercepted;
35
+ if (isFunction(originalMethod)) return;
36
+ target[name] = originalMethod;
38
37
  }
39
38
 
40
39
  /**
@@ -175,42 +174,71 @@ export function transStrToReg(str) {
175
174
  return str;
176
175
  }
177
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
+
178
217
  /**
179
- *
180
- * @param config 配置
181
- * @param keys 需要转换的字段
218
+ * 解析正则表达式字符串,支持 /pattern/flags 格式
219
+ * @param str 正则表达式字符串,如 "/a/ig" 或 "a"
220
+ * @returns RegExp 对象
182
221
  */
183
- export function toRegFormat(config, keys) {
184
- if (getType(keys) === 'string') {
185
- keys = [keys];
222
+ export function parseRegExpString(str) {
223
+ if (typeof str !== 'string') {
224
+ throw new TypeError('input must be a string');
186
225
  }
187
- for (var i = 0, len = keys.length; i < len; i++) {
188
- var paths = keys[i].split('.');
189
- var lastIndex = paths.length - 1;
190
- if (!config) break;
191
- var tmp = config;
192
- for (var j = 0, jlen = paths.length; j < jlen; j++) {
193
- if (paths[j] === '[]') {
194
- if (getType(tmp) === 'array') {
195
- var lastPath = paths.splice(j + 1);
196
- lastPath = lastPath.join('.');
197
- for (var x = 0, xlen = tmp.length; x < xlen; x++) {
198
- toRegFormat(tmp[x], lastPath);
199
- }
200
- }
201
- break;
202
- }
203
- // 最后一层了,需要往前一层才能修改对象
204
- if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
205
- tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
206
- break;
207
- }
208
- tmp = tmp[paths[j]];
209
- if (!tmp) break;
210
- }
211
- if (!tmp || getType(tmp) !== 'array') continue;
212
- for (var _j = 0, _jlen = tmp.length; _j < _jlen; _j++) {
213
- 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);
214
237
  }
238
+ // 如果只有一个 /,当作 /pattern/ 格式处理(无 flags)
239
+ return new RegExp(str.substring(1, str.length - 1));
215
240
  }
241
+
242
+ // 如果不是 /pattern/flags 格式,直接作为 pattern 使用
243
+ return new RegExp(str);
216
244
  }
@@ -1,101 +1,89 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import { getType, toRegFormat } from './base';
3
-
4
- // 需要检查是否需要字符串格式化为正则的配置路径
5
- var REG_FORMAT_PATHS = ['filters.exception', 'filters.resource', 'tracing.allowedUrls.[].match'];
6
- export function isRemoteConfigEnable(config) {
7
- return config.remoteConfig === true || config.remoteConfig && config.remoteConfig.enable !== false;
8
- }
9
-
10
- /**
11
- *
12
- * @param config
13
- * @returns
14
- */
15
- export function getRemoteConfigUrl(config) {
16
- if (config.remoteConfig && config.remoteConfig.url) {
17
- return config.remoteConfig.url;
18
- }
19
- var sereis = config.pid.split('@');
20
- if (!sereis || sereis.length < 2) return;
21
- var timestamp = Date.now();
22
- return "//" + sereis[0] + "-sdk.rum.aliyuncs.com/config/" + (config.remoteConfig.region || 'cn-hangzhou') + "/" + sereis[1] + "?t=" + timestamp;
23
- }
24
-
25
- /**
26
- *
27
- * @param oldConfig
28
- * @param remoteConfig
29
- */
30
- function doCover(oldConfig, remoteConfig) {
31
- if (oldConfig === void 0) {
32
- oldConfig = {};
33
- }
34
- if (remoteConfig === void 0) {
35
- remoteConfig = {};
36
- }
37
- for (var key in oldConfig) {
38
- var _remoteConfig, _remoteConfig2;
39
- if (key === 'pid' || key === 'endpoint') continue;
40
- if (((_remoteConfig = remoteConfig) === null || _remoteConfig === void 0 ? void 0 : _remoteConfig[key]) === undefined) continue;
41
- var oldV = oldConfig[key];
42
- var newV = (_remoteConfig2 = remoteConfig) === null || _remoteConfig2 === void 0 ? void 0 : _remoteConfig2[key];
43
- if (getType(oldV) === 'object' && getType(newV) === 'object') {
44
- doCover(oldV, newV);
45
- } else {
46
- oldConfig[key] = newV;
47
- }
48
- }
49
- }
50
-
51
- /**
52
- *
53
- * @param oldConfig
54
- * @param remoteConfig
55
- */
56
- function doSupplement(oldConfig, remoteConfig) {
57
- if (oldConfig === void 0) {
58
- oldConfig = {};
59
- }
60
- if (remoteConfig === void 0) {
61
- remoteConfig = {};
62
- }
63
- for (var key in remoteConfig) {
64
- var _oldConfig;
65
- if (((_oldConfig = oldConfig) === null || _oldConfig === void 0 ? void 0 : _oldConfig[key]) === undefined) {
66
- oldConfig[key] = remoteConfig[key];
67
- } else {
68
- var oldV = oldConfig[key];
69
- var newV = remoteConfig[key];
70
- if (getType(oldV) === 'object' && getType(newV) === 'object') {
71
- doSupplement(oldV, newV);
72
- }
73
- }
74
- }
75
- }
76
-
77
- /**
78
- *
79
- * @param oldConfig
80
- * @param remoteConfig
81
- * @returns config
82
- */
83
- function combineConfig(oldConfig, remoteConfig) {
84
- if (oldConfig === void 0) {
85
- oldConfig = {};
86
- }
87
- if (remoteConfig === void 0) {
88
- remoteConfig = null;
89
- }
90
- if (!remoteConfig) return null;
91
- if (getType(oldConfig) !== 'object' || getType(remoteConfig) !== 'object') return null;
92
- var config = _extends({}, oldConfig);
93
- // 先检查远程配置的,是否有需要将字符串格式化为正则的
94
- toRegFormat(remoteConfig, REG_FORMAT_PATHS);
95
- // 执行覆盖
96
- doCover(config, remoteConfig);
97
- // 执行补充
98
- doSupplement(config, remoteConfig);
99
- return config;
100
- }
101
- export default combineConfig;
1
+ // import{ getType, toRegFormat} from './base';
2
+ //
3
+ //
4
+ // // 需要检查是否需要字符串格式化为正则的配置路径
5
+ // const REG_FORMAT_PATHS = [
6
+ // 'filters.exception',
7
+ // 'filters.resource',
8
+ // 'tracing.allowedUrls.[].match'
9
+ // ];
10
+ //
11
+ // export function isRemoteConfigEnable(config: any) {
12
+ // return config.remoteConfig === true ||
13
+ // (config.remoteConfig && config.remoteConfig.enable !== false);
14
+ // }
15
+ //
16
+ // /**
17
+ // *
18
+ // * @param config
19
+ // * @returns
20
+ // */
21
+ // export function getRemoteConfigUrl(config: any){
22
+ // if(config.remoteConfig && config.remoteConfig.url) {
23
+ // return config.remoteConfig.url;
24
+ // }
25
+ // const sereis = config.pid.split('@');
26
+ // if(!sereis || sereis.length<2) return;
27
+ // const timestamp = Date.now();
28
+ // return `//${sereis[0]}-sdk.rum.aliyuncs.com/config/${config.remoteConfig.region || 'cn-hangzhou'}/${sereis[1]}?t=${timestamp}`;
29
+ // }
30
+ //
31
+ // /**
32
+ // *
33
+ // * @param oldConfig
34
+ // * @param remoteConfig
35
+ // */
36
+ // function doCover(oldConfig: any ={}, remoteConfig: any ={}){
37
+ // for(const key in oldConfig) {
38
+ // if(key === 'pid' || key === 'endpoint') continue;
39
+ // if(remoteConfig?.[key] === undefined) continue;
40
+ // const oldV = oldConfig[key];
41
+ // const newV = remoteConfig?.[key];
42
+ // if(getType(oldV) === 'object' && getType(newV) === 'object') {
43
+ // doCover(oldV, newV);
44
+ // } else {
45
+ // oldConfig[key] = newV;
46
+ // }
47
+ // }
48
+ // }
49
+ //
50
+ // /**
51
+ // *
52
+ // * @param oldConfig
53
+ // * @param remoteConfig
54
+ // */
55
+ // function doSupplement(oldConfig: any ={}, remoteConfig: any ={}) {
56
+ // for(const key in remoteConfig) {
57
+ // if(oldConfig?.[key] === undefined) {
58
+ // oldConfig[key] = remoteConfig[key];
59
+ // } else {
60
+ // const oldV = oldConfig[key];
61
+ // const newV = remoteConfig[key];
62
+ // if(getType(oldV) === 'object' && getType(newV) === 'object') {
63
+ // doSupplement(oldV, newV);
64
+ // }
65
+ // }
66
+ // }
67
+ // }
68
+ //
69
+ // /**
70
+ // *
71
+ // * @param oldConfig
72
+ // * @param remoteConfig
73
+ // * @returns config
74
+ // */
75
+ // function combineConfig(oldConfig={}, remoteConfig=null) {
76
+ // if(!remoteConfig) return null;
77
+ // if(getType(oldConfig) !== 'object' || getType(remoteConfig) !== 'object') return null;
78
+ // const config = {...oldConfig};
79
+ // // 先检查远程配置的,是否有需要将字符串格式化为正则的
80
+ // toRegFormat(remoteConfig, REG_FORMAT_PATHS);
81
+ // // 执行覆盖
82
+ // doCover(config, remoteConfig);
83
+ // // 执行补充
84
+ // doSupplement(config, remoteConfig);
85
+ // return config;
86
+ // }
87
+ //
88
+ //
89
+ // export default combineConfig;
@@ -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 {
@@ -0,0 +1,2 @@
1
+ export type UrlParams = Record<string, string | string[]>;
2
+ export declare function getUrlParams(input: string): UrlParams;