@arms/rum-core 0.1.4 → 0.1.6

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 (44) hide show
  1. package/README.md +26 -2
  2. package/es/index.d.ts +1 -0
  3. package/es/index.js +1 -0
  4. package/es/model/client.d.ts +2 -1
  5. package/es/model/client.js +27 -1
  6. package/es/model/configManager.js +2 -2
  7. package/es/model/reporter.js +4 -1
  8. package/es/monitor/index.d.ts +6 -0
  9. package/es/monitor/index.js +3 -0
  10. package/es/monitor/logger.d.ts +34 -0
  11. package/es/monitor/logger.js +112 -0
  12. package/es/monitor/telemetry.d.ts +42 -0
  13. package/es/monitor/telemetry.js +210 -0
  14. package/es/monitor/types.d.ts +46 -0
  15. package/es/monitor/types.js +1 -0
  16. package/es/types/client.d.ts +22 -1
  17. package/es/types/rum-event.d.ts +242 -54
  18. package/es/types/rum-event.js +67 -1
  19. package/es/utils/base.js +2 -2
  20. package/es/utils/events.js +2 -1
  21. package/es/utils/protobuf.d.ts +24 -0
  22. package/es/utils/protobuf.js +123 -0
  23. package/lib/index.d.ts +1 -0
  24. package/lib/index.js +7 -0
  25. package/lib/model/client.d.ts +2 -1
  26. package/lib/model/client.js +27 -1
  27. package/lib/model/configManager.js +2 -2
  28. package/lib/model/reporter.js +4 -1
  29. package/lib/monitor/index.d.ts +6 -0
  30. package/lib/monitor/index.js +12 -0
  31. package/lib/monitor/logger.d.ts +34 -0
  32. package/lib/monitor/logger.js +117 -0
  33. package/lib/monitor/telemetry.d.ts +42 -0
  34. package/lib/monitor/telemetry.js +214 -0
  35. package/lib/monitor/types.d.ts +46 -0
  36. package/lib/monitor/types.js +3 -0
  37. package/lib/types/client.d.ts +22 -1
  38. package/lib/types/rum-event.d.ts +242 -54
  39. package/lib/types/rum-event.js +50 -1
  40. package/lib/utils/base.js +2 -2
  41. package/lib/utils/events.js +2 -1
  42. package/lib/utils/protobuf.d.ts +24 -0
  43. package/lib/utils/protobuf.js +127 -0
  44. package/package.json +10 -1
@@ -6,6 +6,7 @@ exports["default"] = void 0;
6
6
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
7
7
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _logger = require("../monitor/logger");
9
10
  var _rumEvent = require("../types/rum-event");
10
11
  var _exception = require("../utils/exception");
11
12
  var _is = require("../utils/is");
@@ -222,6 +223,8 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
222
223
  setTimeout(function () {
223
224
  return _this2.tryRequest(bundle, retry + 1);
224
225
  }, retryDelay);
226
+ } else {
227
+ _logger.logger.error('reporter', "Request failed after " + (retry + 1) + " attempts", _t);
225
228
  }
226
229
  case 4:
227
230
  case "end":
@@ -237,7 +240,7 @@ var Reporter = exports["default"] = /*#__PURE__*/function () {
237
240
  /**
238
241
  * 接口请求由各平台 sdk reporter 实现
239
242
  */
240
- ;
243
+ ;
241
244
  /**
242
245
  * 初始化时
243
246
  */
@@ -0,0 +1,6 @@
1
+ export { logger, callMonitored } from './logger';
2
+ export type { ILogger } from './logger';
3
+ export { Telemetry, convertBundlesToLogGroup } from './telemetry';
4
+ export type { TelemetryContext } from './telemetry';
5
+ export type { MonitorLogEvent, MonitorLogLevel, MonitorEventBundle, IMonitorReporter, ISelfMonitorConfig } from './types';
6
+ export { encodeLogGroup } from '../utils/protobuf';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.logger = exports.encodeLogGroup = exports.convertBundlesToLogGroup = exports.callMonitored = exports.Telemetry = void 0;
5
+ var _logger = require("./logger");
6
+ exports.logger = _logger.logger;
7
+ exports.callMonitored = _logger.callMonitored;
8
+ var _telemetry = require("./telemetry");
9
+ exports.Telemetry = _telemetry.Telemetry;
10
+ exports.convertBundlesToLogGroup = _telemetry.convertBundlesToLogGroup;
11
+ var _protobuf = require("../utils/protobuf");
12
+ exports.encodeLogGroup = _protobuf.encodeLogGroup;
@@ -0,0 +1,34 @@
1
+ import { MonitorLogEvent, MonitorLogLevel } from './types';
2
+ type LogArgs = [module: string, message: string, error?: unknown, context?: Record<string, unknown>];
3
+ export interface ILogger {
4
+ debug(...args: LogArgs): void;
5
+ info(...args: LogArgs): void;
6
+ warn(...args: LogArgs): void;
7
+ error(...args: LogArgs): void;
8
+ crash(...args: LogArgs): void;
9
+ }
10
+ declare class Logger implements ILogger {
11
+ private console;
12
+ private reportLevels;
13
+ private onError?;
14
+ setConsole(enabled: boolean): void;
15
+ setReportLevels(levels: MonitorLogLevel[]): void;
16
+ setOnError(handler?: (event: MonitorLogEvent) => void): void;
17
+ debug(...args: LogArgs): void;
18
+ info(...args: LogArgs): void;
19
+ warn(...args: LogArgs): void;
20
+ error(...args: LogArgs): void;
21
+ crash(...args: LogArgs): void;
22
+ private log;
23
+ /**
24
+ * 函数包装器 — 用于箭头函数属性
25
+ * 用法: private handler = logger.wrap((e) => {...}, 'module', 'message?')
26
+ */
27
+ wrap<T extends (...args: any[]) => unknown>(fn: T, module: string, message?: string): T;
28
+ }
29
+ export declare const logger: Logger;
30
+ /**
31
+ * 执行被监控函数,异常时自动上报
32
+ */
33
+ export declare function callMonitored<T extends (...args: any[]) => unknown>(fn: T, context?: any, args?: any, module?: string, message?: string): ReturnType<T> | undefined;
34
+ export {};
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.callMonitored = callMonitored;
5
+ exports.logger = void 0;
6
+ var DEFAULT_REPORT_LEVELS = ['debug', 'error', 'crash'];
7
+ var Logger = /*#__PURE__*/function () {
8
+ function Logger() {
9
+ this.console = false;
10
+ this.reportLevels = DEFAULT_REPORT_LEVELS;
11
+ this.onError = void 0;
12
+ }
13
+ var _proto = Logger.prototype;
14
+ _proto.setConsole = function setConsole(enabled) {
15
+ this.console = enabled;
16
+ };
17
+ _proto.setReportLevels = function setReportLevels(levels) {
18
+ this.reportLevels = levels;
19
+ };
20
+ _proto.setOnError = function setOnError(handler) {
21
+ this.onError = handler;
22
+ };
23
+ _proto.debug = function debug() {
24
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
25
+ args[_key] = arguments[_key];
26
+ }
27
+ this.log('debug', args);
28
+ };
29
+ _proto.info = function info() {
30
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
31
+ args[_key2] = arguments[_key2];
32
+ }
33
+ this.log('info', args);
34
+ };
35
+ _proto.warn = function warn() {
36
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
37
+ args[_key3] = arguments[_key3];
38
+ }
39
+ this.log('warn', args);
40
+ };
41
+ _proto.error = function error() {
42
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
43
+ args[_key4] = arguments[_key4];
44
+ }
45
+ this.log('error', args);
46
+ };
47
+ _proto.crash = function crash() {
48
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
49
+ args[_key5] = arguments[_key5];
50
+ }
51
+ this.log('crash', args);
52
+ };
53
+ _proto.log = function log(level, _ref) {
54
+ var _this$onError;
55
+ var module = _ref[0],
56
+ message = _ref[1],
57
+ error = _ref[2],
58
+ context = _ref[3];
59
+ if (this.console) {
60
+ var consoleFn = level === 'crash' ? 'error' : level === 'debug' ? 'log' : level;
61
+ console[consoleFn]("[RUM-SDK][" + module + "]", message, error || '');
62
+ }
63
+
64
+ // 仅上报配置中指定的级别
65
+ if (!this.reportLevels.includes(level)) return;
66
+ var stack;
67
+ if (error instanceof Error) {
68
+ stack = error.stack;
69
+ } else if (error && typeof error === 'object' && 'stack' in error) {
70
+ stack = String(error.stack);
71
+ }
72
+
73
+ // 截断过长的 stack(与 content 同等 12KB 上限)
74
+ if (stack && stack.length > 12288) {
75
+ stack = stack.slice(0, 12288);
76
+ }
77
+ (_this$onError = this.onError) === null || _this$onError === void 0 ? void 0 : _this$onError.call(this, Object.assign({
78
+ level: level,
79
+ content: message,
80
+ type: module,
81
+ stack: stack
82
+ }, context));
83
+ }
84
+
85
+ /**
86
+ * 函数包装器 — 用于箭头函数属性
87
+ * 用法: private handler = logger.wrap((e) => {...}, 'module', 'message?')
88
+ */;
89
+ _proto.wrap = function wrap(fn, module, message) {
90
+ return function () {
91
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
92
+ args[_key6] = arguments[_key6];
93
+ }
94
+ return callMonitored(fn, this, args, module, message);
95
+ };
96
+ };
97
+ return Logger;
98
+ }();
99
+ var logger = exports.logger = new Logger();
100
+
101
+ /**
102
+ * 执行被监控函数,异常时自动上报
103
+ */
104
+ function callMonitored(fn, context, args, module, message) {
105
+ try {
106
+ var result = fn.apply(context, args);
107
+ // 检测 async 函数返回的 Promise,附加 .catch 处理
108
+ if (result && typeof result["catch"] === 'function') {
109
+ result["catch"](function (e) {
110
+ logger.error(module || 'unknown', message || (e instanceof Error ? e.message : String(e)), e);
111
+ });
112
+ }
113
+ return result;
114
+ } catch (e) {
115
+ logger.error(module || 'unknown', message || (e instanceof Error ? e.message : String(e)), e);
116
+ }
117
+ }
@@ -0,0 +1,42 @@
1
+ import { MonitorLogEvent, MonitorEventBundle, IMonitorReporter, ISelfMonitorConfig } from './types';
2
+ export interface TelemetryContext {
3
+ appType: string;
4
+ sdkVersion: string;
5
+ endpoint: string;
6
+ getSessionId?: () => string | undefined;
7
+ getViewId?: () => string | undefined;
8
+ getSessionSampled?: () => boolean;
9
+ /** 自监控配置 */
10
+ selfMonitor?: ISelfMonitorConfig | boolean;
11
+ [key: string]: unknown;
12
+ }
13
+ export declare class Telemetry {
14
+ private static instance;
15
+ static init(context: TelemetryContext, reporter?: IMonitorReporter): Telemetry;
16
+ static get(): Telemetry | undefined;
17
+ private buffer;
18
+ private queue;
19
+ private sentEvents;
20
+ private started;
21
+ private enabled;
22
+ private sampled;
23
+ private timer;
24
+ private reporter?;
25
+ private context;
26
+ private isReporting;
27
+ private endpointParams;
28
+ constructor(context: TelemetryContext, reporter?: IMonitorReporter);
29
+ private start;
30
+ addEvent(event: MonitorLogEvent): void;
31
+ flush(): void;
32
+ setReporter(reporter: IMonitorReporter): void;
33
+ private flushBuffer;
34
+ private processSnapshot;
35
+ private shouldSend;
36
+ private buildBundle;
37
+ private sendBatch;
38
+ }
39
+ /**
40
+ * 将 MonitorEventBundle 数组转换并编码为 SLS LogGroup Protobuf 格式
41
+ */
42
+ export declare function convertBundlesToLogGroup(data: MonitorEventBundle[]): Uint8Array;
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.Telemetry = void 0;
6
+ exports.convertBundlesToLogGroup = convertBundlesToLogGroup;
7
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
+ var _logger = require("./logger");
9
+ var _url = require("../utils/url");
10
+ var _protobuf = require("../utils/protobuf");
11
+ var _number = require("../utils/number");
12
+ var _Telemetry;
13
+ var MAX_EVENTS_PER_PAGE = 15;
14
+ var BUFFER_SIZE = 100;
15
+ var LOG_CONTENT_MAX_SIZE = 12288;
16
+ var FLUSH_TIME = 5000;
17
+ var MAX_BATCH_SIZE = 10;
18
+ var DEFAULT_SAMPLE_RATE = 100;
19
+
20
+ /** 事件快照:在事件产生时就捕获上下文 */
21
+ var Telemetry = exports.Telemetry = /*#__PURE__*/function () {
22
+ function Telemetry(context, reporter) {
23
+ this.buffer = [];
24
+ this.queue = [];
25
+ this.sentEvents = new Set();
26
+ this.started = false;
27
+ this.enabled = true;
28
+ this.sampled = void 0;
29
+ this.timer = null;
30
+ this.reporter = void 0;
31
+ this.context = void 0;
32
+ this.isReporting = false;
33
+ this.endpointParams = void 0;
34
+ this.context = context;
35
+ this.reporter = reporter;
36
+ this.endpointParams = (0, _url.getUrlParams)(context.endpoint);
37
+
38
+ // 解析自监控配置
39
+ var selfMonitor = context.selfMonitor;
40
+ if (typeof selfMonitor === 'boolean') {
41
+ this.enabled = selfMonitor;
42
+ this.sampled = (0, _number.performDraw)(DEFAULT_SAMPLE_RATE);
43
+ } else if (selfMonitor && typeof selfMonitor === 'object') {
44
+ this.enabled = selfMonitor.enable !== false;
45
+ var rate = selfMonitor.sampling;
46
+ this.sampled = (0, _number.performDraw)(typeof rate === 'number' && rate >= 0 && rate <= 100 ? rate : DEFAULT_SAMPLE_RATE);
47
+ if (selfMonitor.console) {
48
+ _logger.logger.setConsole(true);
49
+ }
50
+ if (selfMonitor.reportLevels) {
51
+ _logger.logger.setReportLevels(selfMonitor.reportLevels);
52
+ }
53
+ } else {
54
+ this.enabled = true;
55
+ this.sampled = (0, _number.performDraw)(DEFAULT_SAMPLE_RATE);
56
+ }
57
+ }
58
+ Telemetry.init = function init(context, reporter) {
59
+ if (Telemetry.instance) {
60
+ Telemetry.instance.flush();
61
+ }
62
+ Telemetry.instance = new Telemetry(context, reporter);
63
+ Telemetry.instance.start();
64
+ return Telemetry.instance;
65
+ };
66
+ Telemetry.get = function get() {
67
+ return Telemetry.instance;
68
+ };
69
+ var _proto = Telemetry.prototype;
70
+ _proto.start = function start() {
71
+ var _this = this;
72
+ if (this.started) return;
73
+ this.started = true;
74
+ _logger.logger.setOnError(function (event) {
75
+ return _this.addEvent(event);
76
+ });
77
+ this.flushBuffer();
78
+ };
79
+ _proto.addEvent = function addEvent(event) {
80
+ var _this$context$getSess, _this$context, _this$context$getView, _this$context2;
81
+ if (!this.enabled || !event) return;
82
+ if (event.content && event.content.length > LOG_CONTENT_MAX_SIZE) {
83
+ event = (0, _extends2["default"])({}, event, {
84
+ content: event.content.slice(0, LOG_CONTENT_MAX_SIZE)
85
+ });
86
+ }
87
+ if (event.stack && event.stack.length > LOG_CONTENT_MAX_SIZE) {
88
+ event = (0, _extends2["default"])({}, event, {
89
+ stack: event.stack.slice(0, LOG_CONTENT_MAX_SIZE)
90
+ });
91
+ }
92
+
93
+ // 在事件产生时就捕获快照
94
+ var snapshot = {
95
+ event: event,
96
+ sessionId: (_this$context$getSess = (_this$context = this.context).getSessionId) === null || _this$context$getSess === void 0 ? void 0 : _this$context$getSess.call(_this$context),
97
+ viewId: (_this$context$getView = (_this$context2 = this.context).getViewId) === null || _this$context$getView === void 0 ? void 0 : _this$context$getView.call(_this$context2),
98
+ timestamp: Date.now()
99
+ };
100
+ if (!this.started || !this.reporter) {
101
+ if (this.buffer.length < BUFFER_SIZE) {
102
+ this.buffer.push(snapshot);
103
+ }
104
+ return;
105
+ }
106
+ this.processSnapshot(snapshot);
107
+ };
108
+ _proto.flush = function flush() {
109
+ if (this.timer) {
110
+ clearTimeout(this.timer);
111
+ this.timer = null;
112
+ }
113
+ this.sendBatch();
114
+ };
115
+ _proto.setReporter = function setReporter(reporter) {
116
+ this.reporter = reporter;
117
+ if (this.started) {
118
+ this.flushBuffer();
119
+ }
120
+ };
121
+ _proto.flushBuffer = function flushBuffer() {
122
+ var _this2 = this;
123
+ var buffered = this.buffer.splice(0);
124
+ buffered.forEach(function (snapshot) {
125
+ return _this2.processSnapshot(snapshot);
126
+ });
127
+ };
128
+ _proto.processSnapshot = function processSnapshot(snapshot) {
129
+ var _this3 = this;
130
+ if (!this.shouldSend(snapshot.event)) return;
131
+ var bundle = this.buildBundle(snapshot);
132
+ this.queue.push(bundle);
133
+ if (this.queue.length >= MAX_BATCH_SIZE) {
134
+ this.flush();
135
+ } else if (!this.timer) {
136
+ this.timer = setTimeout(function () {
137
+ return _this3.flush();
138
+ }, FLUSH_TIME);
139
+ }
140
+ };
141
+ _proto.shouldSend = function shouldSend(event) {
142
+ // 先检查 Session 采样,未命中则不上报
143
+ if (this.context.getSessionSampled && !this.context.getSessionSampled()) return false;
144
+ // 再检查自监控自身采样
145
+ if (!this.sampled) return false;
146
+ if (this.sentEvents.size >= MAX_EVENTS_PER_PAGE) return false;
147
+ var key = (event.content || '') + (event.stack || '');
148
+ if (this.sentEvents.has(key)) return false;
149
+ this.sentEvents.add(key);
150
+ return true;
151
+ };
152
+ _proto.buildBundle = function buildBundle(snapshot) {
153
+ var _this$context3 = this.context,
154
+ appType = _this$context3.appType,
155
+ sdkVersion = _this$context3.sdkVersion,
156
+ endpoint = _this$context3.endpoint;
157
+ return (0, _extends2["default"])({
158
+ 'app.type': appType,
159
+ _v: sdkVersion,
160
+ endpoint: endpoint,
161
+ 'session.id': snapshot.sessionId,
162
+ 'view.id': snapshot.viewId,
163
+ timestamp: snapshot.timestamp,
164
+ event_type: 'log',
165
+ log: snapshot.event
166
+ }, this.endpointParams);
167
+ };
168
+ _proto.sendBatch = function sendBatch() {
169
+ if (this.queue.length === 0 || !this.reporter) return;
170
+ if (this.isReporting) return;
171
+ var batch = this.queue.splice(0);
172
+ this.isReporting = true;
173
+ try {
174
+ this.reporter.send(batch);
175
+ } catch (e) {
176
+ // 不通过 logger(避免反馈循环),直接 console 仅供开发调试
177
+ try {
178
+ console.warn('[RUM-Telemetry] send failed:', e);
179
+ } catch (_) {}
180
+ } finally {
181
+ this.isReporting = false;
182
+ }
183
+ };
184
+ return Telemetry;
185
+ }();
186
+ /**
187
+ * 将 MonitorEventBundle 数组转换并编码为 SLS LogGroup Protobuf 格式
188
+ */
189
+ _Telemetry = Telemetry;
190
+ Telemetry.instance = void 0;
191
+ function convertBundlesToLogGroup(data) {
192
+ var logs = data.map(function (bundle) {
193
+ var contents = [];
194
+
195
+ // 遍历 bundle 顶层字段,跳过 timestamp(映射到 time),对象类型整体序列化
196
+ for (var _i = 0, _Object$entries = Object.entries(bundle); _i < _Object$entries.length; _i++) {
197
+ var _Object$entries$_i = _Object$entries[_i],
198
+ _key = _Object$entries$_i[0],
199
+ val = _Object$entries$_i[1];
200
+ if (_key === 'timestamp') continue;
201
+ if (val !== undefined && val !== null) {
202
+ contents.push({
203
+ key: _key,
204
+ value: typeof val === 'object' ? JSON.stringify(val) : String(val)
205
+ });
206
+ }
207
+ }
208
+ return {
209
+ time: Math.floor(bundle.timestamp / 1000),
210
+ contents: contents
211
+ };
212
+ });
213
+ return (0, _protobuf.encodeLogGroup)(logs);
214
+ }
@@ -0,0 +1,46 @@
1
+ export type MonitorLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'crash';
2
+ export interface MonitorLogEvent {
3
+ level: MonitorLogLevel;
4
+ content: string;
5
+ stack?: string;
6
+ type?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ export interface MonitorEventBundle {
10
+ 'app.type': string;
11
+ _v: string;
12
+ endpoint: string;
13
+ 'session.id'?: string;
14
+ 'view.id'?: string;
15
+ timestamp: number;
16
+ event_type: 'log';
17
+ log?: MonitorLogEvent;
18
+ [key: string]: unknown;
19
+ }
20
+ export interface IMonitorReporter {
21
+ send(data: MonitorEventBundle[]): void;
22
+ }
23
+ /**
24
+ * 自监控配置
25
+ */
26
+ export interface ISelfMonitorConfig {
27
+ /**
28
+ * 是否启用自监控,默认 true
29
+ */
30
+ enable?: boolean;
31
+ /**
32
+ * 采样率,取值范围 0 - 100,支持小数(如 50.5 表示 50.5%)
33
+ * 所有级别日志统一受采样率控制
34
+ */
35
+ sampling?: number;
36
+ /**
37
+ * 是否在浏览器控制台输出自监控日志,默认 false
38
+ * 设为 true 时,所有级别日志会同时输出到控制台
39
+ */
40
+ console?: boolean;
41
+ /**
42
+ * 需要上报到 Telemetry 的日志级别列表
43
+ * 默认值: ['debug', 'error', 'crash']
44
+ */
45
+ reportLevels?: MonitorLogLevel[];
46
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
@@ -5,6 +5,7 @@ import { RumEvent, RumEventBundle, IViewData } from './rum-event';
5
5
  import { MatchOption } from '../utils/match';
6
6
  import { IConfigManager } from './config';
7
7
  import { EventEmitter } from '../utils/events';
8
+ import { ISelfMonitorConfig, IMonitorReporter } from '../monitor/types';
8
9
  export declare enum EventType {
9
10
  /**
10
11
  * 收集数据
@@ -33,7 +34,15 @@ export interface IContext {
33
34
  [key: string]: any;
34
35
  }
35
36
  export interface SessionConfig {
37
+ /**
38
+ * Session 采样率,取值范围 0 - 1 的小数
39
+ * @deprecated 该字段将在未来版本下线,请使用 {@link SessionConfig.sampling} 替代
40
+ */
36
41
  sampleRate?: number;
42
+ /**
43
+ * Session 采样率,取值范围 0 - 100,支持小数(如 50.5 表示 50.5%)
44
+ */
45
+ sampling?: number;
37
46
  maxDuration?: number;
38
47
  overtime?: number;
39
48
  storage?: string;
@@ -46,6 +55,10 @@ export interface IReportConfig {
46
55
  }
47
56
  export interface IRumSession {
48
57
  init(ctx: IContext): void;
58
+ /** 平台类型标识,如 'browser'/'miniapp' */
59
+ appType: string;
60
+ /** SDK 版本号 */
61
+ sdkVersion: string;
49
62
  sessionConfig: SessionConfig;
50
63
  getSessionId: () => string;
51
64
  getSampled: () => boolean;
@@ -102,7 +115,7 @@ export interface IClient {
102
115
  /**
103
116
  * 初始化
104
117
  */
105
- init: (configuration: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager) => void;
118
+ init: (configuration: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager, monitorReporter?: IMonitorReporter) => void;
106
119
  /**
107
120
  * 业务自定义上传数据
108
121
  */
@@ -227,5 +240,13 @@ export interface IConfiguration {
227
240
  attributeName: string;
228
241
  attributeValue?: Array<string | RegExp> | null;
229
242
  }>;
243
+ /**
244
+ * 自监控(Self-Monitor)配置
245
+ * 用于控制 SDK 内部异常和错误的自动上报行为
246
+ * - `boolean`: 简单启用/禁用自监控
247
+ * - `ISelfMonitorConfig`: 详细配置,可指定采样率等
248
+ * @default true
249
+ */
250
+ selfMonitor?: boolean | ISelfMonitorConfig;
230
251
  [key: string]: unknown;
231
252
  }