@arms/rum-reactnative 0.1.1 → 0.1.3-beta.0
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/README.md +399 -15
- package/RumSdkReactnative.podspec +28 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +6 -0
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +512 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +33 -0
- package/android/src/main/java/com/rumsdkreactnative/crash/CrashContextManager.kt +157 -0
- package/android/src/main/java/com/rumsdkreactnative/crash/CrashHandler.kt +444 -0
- package/android/src/main/java/com/rumsdkreactnative/crash/CrashInitProvider.kt +50 -0
- package/android/src/main/java/com/rumsdkreactnative/crash/NdkCrashHandler.kt +66 -0
- package/android/src/main/jni/CMakeLists.txt +21 -0
- package/android/src/main/jni/rum_backtrace.c +144 -0
- package/android/src/main/jni/rum_crash_handler.c +200 -0
- package/android/src/main/jni/rum_crash_writer.c +442 -0
- package/android/src/main/jni/rum_module_info.c +316 -0
- package/android/src/main/jni/rum_module_info.h +54 -0
- package/android/src/main/jni/rum_test_crash.cpp +55 -0
- package/app.plugin.js +11 -0
- package/docs/ReactNative SDK/351/205/215/347/275/256/345/217/202/350/200/203.md" +671 -0
- package/docs/SDK /347/211/210/346/234/254/350/257/264/346/230/216.md" +12 -0
- package/docs//346/216/245/345/205/245ReactNative/345/272/224/347/224/250.md +238 -0
- package/ios/PrivacyInfo.xcprivacy +93 -0
- package/ios/RumCrashReporter.h +38 -0
- package/ios/RumCrashReporter.mm +861 -0
- package/ios/RumSdkReactnative.h +5 -0
- package/ios/RumSdkReactnative.mm +291 -0
- package/ios/fishhook/fishhook.c +264 -0
- package/ios/fishhook/fishhook.h +76 -0
- package/lib/commonjs/NativeRumSdkReactnative.js +50 -0
- package/lib/commonjs/collector/action/index.js +108 -0
- package/lib/commonjs/collector/exception/crash.js +148 -0
- package/lib/commonjs/collector/exception/index.js +238 -0
- package/lib/commonjs/collector/index.js +42 -0
- package/lib/commonjs/collector/resource/api.js +286 -0
- package/lib/commonjs/collector/view/perf.js +79 -0
- package/lib/commonjs/collector/view/pv.js +88 -0
- package/lib/commonjs/expoConfigPlugin.js +37 -0
- package/lib/commonjs/index.js +29 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/plugin.js +47 -0
- package/lib/commonjs/processor/default-processor.js +27 -0
- package/lib/commonjs/processor/session-processor.js +47 -0
- package/lib/commonjs/reporter/index.js +148 -0
- package/lib/commonjs/reporter/monitor-reporter.js +43 -0
- package/lib/commonjs/shell.js +91 -0
- package/lib/commonjs/types/client.js +6 -0
- package/lib/commonjs/types/crash.js +37 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/utils/action.js +305 -0
- package/lib/commonjs/utils/api.js +83 -0
- package/lib/commonjs/utils/base.js +95 -0
- package/lib/commonjs/utils/crash.js +146 -0
- package/lib/commonjs/utils/platform.js +162 -0
- package/lib/commonjs/utils/session.js +158 -0
- package/lib/commonjs/utils/url.js +59 -0
- package/lib/commonjs/utils/view.js +93 -0
- package/lib/module/NativeRumSdkReactnative.js +47 -0
- package/lib/module/collector/action/index.js +45 -10
- package/lib/module/collector/exception/crash.js +143 -0
- package/lib/module/collector/exception/index.js +144 -46
- package/lib/module/collector/index.js +8 -0
- package/lib/module/collector/resource/api.js +6 -6
- package/lib/module/collector/view/pv.js +13 -2
- package/lib/module/expoConfigPlugin.js +33 -0
- package/lib/module/index.js +1 -0
- package/lib/module/plugin.js +4 -1
- package/lib/module/processor/session-processor.js +22 -0
- package/lib/module/reporter/index.js +102 -16
- package/lib/module/reporter/monitor-reporter.js +38 -0
- package/lib/module/shell.js +32 -7
- package/lib/module/types/crash.js +33 -0
- package/lib/module/utils/action.js +299 -0
- package/lib/module/utils/api.js +10 -10
- package/lib/module/utils/base.js +9 -9
- package/lib/module/utils/crash.js +141 -0
- package/lib/module/utils/platform.js +127 -72
- package/lib/module/utils/session.js +23 -4
- package/lib/module/utils/view.js +2 -1
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeRumSdkReactnative.d.ts +49 -0
- package/lib/typescript/{src → commonjs/src}/collector/action/index.d.ts +7 -1
- package/lib/typescript/commonjs/src/collector/exception/crash.d.ts +28 -0
- package/lib/typescript/{src → commonjs/src}/collector/exception/index.d.ts +7 -0
- package/lib/typescript/commonjs/src/collector/index.d.ts +6 -0
- package/lib/typescript/{src → commonjs/src}/collector/view/pv.d.ts +2 -2
- package/lib/typescript/commonjs/src/expoConfigPlugin.d.ts +28 -0
- package/lib/typescript/commonjs/src/index.d.ts +6 -0
- package/lib/typescript/{src → commonjs/src}/processor/session-processor.d.ts +2 -0
- package/lib/typescript/{src → commonjs/src}/reporter/index.d.ts +3 -1
- package/lib/typescript/commonjs/src/reporter/monitor-reporter.d.ts +8 -0
- package/lib/typescript/commonjs/src/shell.d.ts +57 -0
- package/lib/typescript/{src → commonjs/src}/types/client.d.ts +2 -2
- package/lib/typescript/commonjs/src/types/crash.d.ts +95 -0
- package/lib/typescript/commonjs/src/utils/action.d.ts +63 -0
- package/lib/typescript/{src → commonjs/src}/utils/api.d.ts +1 -1
- package/lib/typescript/commonjs/src/utils/crash.d.ts +12 -0
- package/lib/typescript/commonjs/src/utils/platform.d.ts +22 -0
- package/lib/typescript/{src → commonjs/src}/utils/session.d.ts +4 -0
- package/lib/typescript/module/src/NativeRumSdkReactnative.d.ts +49 -0
- package/lib/typescript/module/src/collector/action/index.d.ts +21 -0
- package/lib/typescript/module/src/collector/exception/crash.d.ts +28 -0
- package/lib/typescript/module/src/collector/exception/index.d.ts +32 -0
- package/lib/typescript/module/src/collector/index.d.ts +6 -0
- package/lib/typescript/module/src/collector/resource/api.d.ts +21 -0
- package/lib/typescript/module/src/collector/view/perf.d.ts +1 -0
- package/lib/typescript/module/src/collector/view/pv.d.ts +16 -0
- package/lib/typescript/module/src/expoConfigPlugin.d.ts +28 -0
- package/lib/typescript/module/src/index.d.ts +6 -0
- package/lib/typescript/module/src/plugin.d.ts +3 -0
- package/lib/typescript/module/src/processor/default-processor.d.ts +6 -0
- package/lib/typescript/module/src/processor/session-processor.d.ts +11 -0
- package/lib/typescript/module/src/reporter/index.d.ts +18 -0
- package/lib/typescript/module/src/reporter/monitor-reporter.d.ts +8 -0
- package/lib/typescript/module/src/shell.d.ts +57 -0
- package/lib/typescript/module/src/types/client.d.ts +27 -0
- package/lib/typescript/module/src/types/crash.d.ts +95 -0
- package/lib/typescript/module/src/types/index.d.ts +118 -0
- package/lib/typescript/module/src/utils/action.d.ts +63 -0
- package/lib/typescript/module/src/utils/api.d.ts +59 -0
- package/lib/typescript/module/src/utils/base.d.ts +8 -0
- package/lib/typescript/module/src/utils/crash.d.ts +12 -0
- package/lib/typescript/module/src/utils/platform.d.ts +22 -0
- package/lib/typescript/module/src/utils/session.d.ts +41 -0
- package/lib/typescript/module/src/utils/url.d.ts +17 -0
- package/lib/typescript/module/src/utils/view.d.ts +13 -0
- package/package.json +61 -26
- package/LICENSE +0 -20
- package/lib/module/collector/action/index.js.map +0 -1
- package/lib/module/collector/exception/index.js.map +0 -1
- package/lib/module/collector/resource/api.js.map +0 -1
- package/lib/module/collector/view/perf.js.map +0 -1
- package/lib/module/collector/view/pv.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/plugin.js.map +0 -1
- package/lib/module/processor/default-processor.js.map +0 -1
- package/lib/module/processor/session-processor.js.map +0 -1
- package/lib/module/reporter/index.js.map +0 -1
- package/lib/module/shell.js.map +0 -1
- package/lib/module/types/client.js.map +0 -1
- package/lib/module/types/index.js.map +0 -1
- package/lib/module/utils/api.js.map +0 -1
- package/lib/module/utils/base.js.map +0 -1
- package/lib/module/utils/platform.js.map +0 -1
- package/lib/module/utils/session.js.map +0 -1
- package/lib/module/utils/url.js.map +0 -1
- package/lib/module/utils/view.js.map +0 -1
- package/lib/typescript/src/collector/action/index.d.ts.map +0 -1
- package/lib/typescript/src/collector/exception/index.d.ts.map +0 -1
- package/lib/typescript/src/collector/resource/api.d.ts.map +0 -1
- package/lib/typescript/src/collector/view/perf.d.ts.map +0 -1
- package/lib/typescript/src/collector/view/pv.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -4
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/plugin.d.ts.map +0 -1
- package/lib/typescript/src/processor/default-processor.d.ts.map +0 -1
- package/lib/typescript/src/processor/session-processor.d.ts.map +0 -1
- package/lib/typescript/src/reporter/index.d.ts.map +0 -1
- package/lib/typescript/src/shell.d.ts +0 -26
- package/lib/typescript/src/shell.d.ts.map +0 -1
- package/lib/typescript/src/types/client.d.ts.map +0 -1
- package/lib/typescript/src/types/index.d.ts.map +0 -1
- package/lib/typescript/src/utils/api.d.ts.map +0 -1
- package/lib/typescript/src/utils/base.d.ts.map +0 -1
- package/lib/typescript/src/utils/platform.d.ts +0 -15
- package/lib/typescript/src/utils/platform.d.ts.map +0 -1
- package/lib/typescript/src/utils/session.d.ts.map +0 -1
- package/lib/typescript/src/utils/url.d.ts.map +0 -1
- package/lib/typescript/src/utils/view.d.ts.map +0 -1
- /package/lib/typescript/{src → commonjs/src}/collector/resource/api.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/collector/view/perf.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/plugin.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/processor/default-processor.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/types/index.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/base.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/url.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/view.d.ts +0 -0
- /package/lib/typescript/{package.json → module/package.json} +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { isFunction, RumEventType } from '@arms/rum-core';
|
|
4
4
|
import { addNavigateListener, removeNavigateListener } from "../../utils/view.js";
|
|
5
|
+
import { CRASH_CONTEXT_EVENT } from "../../types/crash.js";
|
|
5
6
|
export default class PvCollector {
|
|
6
7
|
name = 'pv-collector';
|
|
7
8
|
pageMap = {};
|
|
@@ -25,7 +26,7 @@ export default class PvCollector {
|
|
|
25
26
|
id: key,
|
|
26
27
|
params
|
|
27
28
|
};
|
|
28
|
-
if (name ===
|
|
29
|
+
if (name === '__root') return;
|
|
29
30
|
this.sendPv(page);
|
|
30
31
|
};
|
|
31
32
|
sendPv = page => {
|
|
@@ -35,7 +36,7 @@ export default class PvCollector {
|
|
|
35
36
|
// 路由没有发生变化,不发送
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
|
-
page.name = this.getViewName(page.path, page);
|
|
39
|
+
page.name = this.getViewName(page.path || page.name || '', page);
|
|
39
40
|
if (prevPage && prevPage.id in this.pageMap) {
|
|
40
41
|
delete this.pageMap[prevPage.id];
|
|
41
42
|
ctx.removeView(prevPage.id);
|
|
@@ -54,6 +55,16 @@ export default class PvCollector {
|
|
|
54
55
|
loading_type: 'initial_load',
|
|
55
56
|
...page
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
// 同步当前 view 上下文到原生侧(崩溃报告关联用)
|
|
60
|
+
const sessionId = ctx.session?.getSessionId?.() || '';
|
|
61
|
+
const userId = ctx.session?.getUserId?.() || '';
|
|
62
|
+
ctx.emitter.emit(CRASH_CONTEXT_EVENT, {
|
|
63
|
+
session_id: sessionId,
|
|
64
|
+
user_id: userId,
|
|
65
|
+
view_id: page.id,
|
|
66
|
+
view_name: page.name
|
|
67
|
+
});
|
|
57
68
|
};
|
|
58
69
|
getViewName(url, page) {
|
|
59
70
|
let {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Expo config plugin for @arms/rum-reactnative.
|
|
5
|
+
*
|
|
6
|
+
* 在 app.config 中声明后,将 SDK 配置写入 `expoConfig.extra.rumSdk`,运行时可通过
|
|
7
|
+
* `Constants.expoConfig?.extra?.rumSdk` 读取,避免在 JS 入口硬编码 endpoint。
|
|
8
|
+
*
|
|
9
|
+
* app.config.ts 示例:
|
|
10
|
+
* plugins: [['@arms/rum-reactnative', { endpoint: '...', env: 'prod' }]]
|
|
11
|
+
*
|
|
12
|
+
* 仅做配置透传,不注入原生构建设置(podspec / gradle 已由 autolinking 处理)。
|
|
13
|
+
* 零运行时依赖,非 Expo 用户安装本包不会拉入 @expo/* 。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** 本插件触碰到的 expo config 切片,故意放宽以避免对 @expo/config-types 的硬依赖。 */
|
|
17
|
+
|
|
18
|
+
const withRumSdk = (config, props) => {
|
|
19
|
+
const extra = {
|
|
20
|
+
...(config.extra ?? {})
|
|
21
|
+
};
|
|
22
|
+
extra.rumSdk = {
|
|
23
|
+
endpoint: props?.endpoint,
|
|
24
|
+
env: props?.env ?? 'prod',
|
|
25
|
+
version: props?.version
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
...config,
|
|
29
|
+
extra
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default withRumSdk;
|
|
33
|
+
//# sourceMappingURL=expoConfigPlugin.js.map
|
package/lib/module/index.js
CHANGED
package/lib/module/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
4
|
-
import { isString } from
|
|
4
|
+
import { isString } from '@arms/rum-core';
|
|
5
5
|
import { VERSION } from "./utils/platform.js";
|
|
6
6
|
import armsRum from "./shell.js";
|
|
7
7
|
const RumSdkModule = NativeModules.RumSdkModule;
|
|
@@ -25,9 +25,12 @@ if (RumSdkModule) {
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
// pid 为可选配置,未提供时使用默认值(格式:react-native@{VERSION})
|
|
29
|
+
// 这确保了即使未在ARMS控制台创建应用,SDK也能正常初始化和上报
|
|
28
30
|
if (!config.pid) {
|
|
29
31
|
config.pid = `react-native@${VERSION}`;
|
|
30
32
|
}
|
|
33
|
+
// endpoint 为必填配置,未提供时使用本地回环地址作为兜底
|
|
31
34
|
if (!config.endpoint) {
|
|
32
35
|
config.endpoint = `http://127.0.0.1/?version=${VERSION}`;
|
|
33
36
|
}
|
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { debounce, ONE_SECOND } from '@arms/rum-core';
|
|
4
|
+
import { CRASH_CONTEXT_EVENT } from "../types/crash.js";
|
|
5
|
+
import { getCurView } from "../utils/view.js";
|
|
4
6
|
export default class SessionProcessor {
|
|
5
7
|
name = 'session-processor';
|
|
8
|
+
lastSessionId = '';
|
|
6
9
|
setup(ctx) {
|
|
7
10
|
this.ctx = ctx;
|
|
8
11
|
this.update = debounce(this.update, ONE_SECOND);
|
|
12
|
+
// 延迟到下一个事件循环执行,确保 collectors 已完成 setup 并注册了
|
|
13
|
+
// CRASH_CONTEXT_EVENT 监听器(rum-core 中 processors.setup() 先于
|
|
14
|
+
// collectors.setup() 执行)。消除 session 创建后 1 秒内的 context
|
|
15
|
+
// 同步窗口,同时避免 emit 事件因无监听器而被丢弃
|
|
16
|
+
setTimeout(() => this.syncCrashContext(), 0);
|
|
9
17
|
// sdk.onTouchStart(this.update)
|
|
10
18
|
}
|
|
11
19
|
update = e => {
|
|
12
20
|
if (e && !e.isTrusted) return;
|
|
13
21
|
this.ctx?.session.updateSession();
|
|
22
|
+
this.syncCrashContext();
|
|
14
23
|
};
|
|
15
24
|
process(ctx) {
|
|
16
25
|
this.update();
|
|
17
26
|
return ctx.getRumEvent();
|
|
18
27
|
}
|
|
28
|
+
syncCrashContext() {
|
|
29
|
+
if (!this.ctx) return;
|
|
30
|
+
const sessionId = this.ctx.session.getSessionId();
|
|
31
|
+
if (sessionId === this.lastSessionId) return;
|
|
32
|
+
this.lastSessionId = sessionId;
|
|
33
|
+
const view = getCurView(this.ctx);
|
|
34
|
+
this.ctx.emitter.emit(CRASH_CONTEXT_EVENT, {
|
|
35
|
+
session_id: sessionId,
|
|
36
|
+
user_id: this.ctx.session.getUserId(),
|
|
37
|
+
view_id: view?.id || '',
|
|
38
|
+
view_name: view?.name || ''
|
|
39
|
+
});
|
|
40
|
+
}
|
|
19
41
|
}
|
|
20
42
|
//# sourceMappingURL=session-processor.js.map
|
|
@@ -1,10 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { Reporter } from '@arms/rum-core';
|
|
3
|
+
import { Reporter, Telemetry, logger } from '@arms/rum-core';
|
|
4
4
|
import { fixAttrs } from "../utils/platform.js";
|
|
5
|
+
import { CRASH_ID_FIELD, CRASH_REPORT_ACK_EVENT } from "../types/crash.js";
|
|
5
6
|
// @ts-ignore
|
|
6
7
|
import { AppState } from 'react-native';
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* 从 bundle.events 的 snapshots 中提取携带的 crash_id(瞬态字段)。
|
|
11
|
+
* crash_id 由 CrashCollector 注入到 snapshots JSON 字符串中,
|
|
12
|
+
* reporter 提取后用于 ack,并在序列化前从 snapshots 中剥离,不会发送到后端。
|
|
13
|
+
* 兼容旧版降级路径:crash_id 可能残留在事件根级。
|
|
14
|
+
*/
|
|
15
|
+
function extractCrashIds(bundle) {
|
|
16
|
+
const ids = [];
|
|
17
|
+
const events = bundle?.events;
|
|
18
|
+
if (Array.isArray(events)) {
|
|
19
|
+
for (const ev of events) {
|
|
20
|
+
if (!ev) continue;
|
|
21
|
+
// 优先从 snapshots 提取
|
|
22
|
+
let cid;
|
|
23
|
+
try {
|
|
24
|
+
const snapshotsObj = JSON.parse(ev.snapshots);
|
|
25
|
+
cid = snapshotsObj?.[CRASH_ID_FIELD];
|
|
26
|
+
} catch {
|
|
27
|
+
// snapshots 解析失败
|
|
28
|
+
}
|
|
29
|
+
// 兼容旧版降级路径:检查根级
|
|
30
|
+
if (!cid) {
|
|
31
|
+
cid = ev[CRASH_ID_FIELD];
|
|
32
|
+
}
|
|
33
|
+
if (typeof cid === 'string' && cid) ids.push(cid);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ids;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 序列化前剥离事件上的 crash_id 瞬态字段:
|
|
41
|
+
* - 从 snapshots JSON 字符串中移除;
|
|
42
|
+
* - 兼容旧版降级路径:从事件根级移除。
|
|
43
|
+
*/
|
|
44
|
+
function stripCrashIds(bundle) {
|
|
45
|
+
const events = bundle?.events;
|
|
46
|
+
if (!Array.isArray(events)) return;
|
|
47
|
+
for (const ev of events) {
|
|
48
|
+
if (!ev) continue;
|
|
49
|
+
// 从 snapshots 中移除
|
|
50
|
+
if (typeof ev.snapshots === 'string') {
|
|
51
|
+
try {
|
|
52
|
+
const snapshotsObj = JSON.parse(ev.snapshots);
|
|
53
|
+
if (snapshotsObj && CRASH_ID_FIELD in snapshotsObj) {
|
|
54
|
+
delete snapshotsObj[CRASH_ID_FIELD];
|
|
55
|
+
ev.snapshots = JSON.stringify(snapshotsObj);
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
// snapshots 解析失败,跳过
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 兼容旧版降级路径:从根级移除
|
|
62
|
+
if (CRASH_ID_FIELD in ev) {
|
|
63
|
+
delete ev[CRASH_ID_FIELD];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
8
68
|
/**
|
|
9
69
|
* rn-app reporter
|
|
10
70
|
*/
|
|
@@ -16,8 +76,7 @@ class RNReporter extends Reporter {
|
|
|
16
76
|
try {
|
|
17
77
|
this.appStateListener = AppState.addEventListener('change', this.onAppStateChanged);
|
|
18
78
|
} catch (error) {
|
|
19
|
-
|
|
20
|
-
console.info(error);
|
|
79
|
+
logger.warn('reporter', 'AppState listener binding failed', error);
|
|
21
80
|
}
|
|
22
81
|
}
|
|
23
82
|
init(ctx) {
|
|
@@ -29,26 +88,53 @@ class RNReporter extends Reporter {
|
|
|
29
88
|
if (typeof this.flushEventQueue === 'function') {
|
|
30
89
|
this.flushEventQueue();
|
|
31
90
|
}
|
|
91
|
+
// 后台前 flush 自监控数据
|
|
92
|
+
Telemetry.get()?.flush();
|
|
32
93
|
}
|
|
33
94
|
// else if (nextAppState === 'active') {
|
|
34
95
|
// console.warn('RUM:应用回到前台');
|
|
35
96
|
// }
|
|
36
97
|
};
|
|
37
|
-
request(ctx, bundle) {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
98
|
+
async request(ctx, bundle) {
|
|
99
|
+
// 先从事件中提取崩溃 crash_id(瞬态字段),用于上报后 ack 删文件
|
|
100
|
+
const crashIds = extractCrashIds(bundle);
|
|
101
|
+
try {
|
|
102
|
+
const batchedEvents = await fixAttrs(bundle);
|
|
103
|
+
// 序列化前剥离瞬态字段,避免发送到后端
|
|
104
|
+
stripCrashIds(batchedEvents);
|
|
105
|
+
const config = ctx.getConfig();
|
|
106
|
+
fetch(config.endpoint, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'text/plain'
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify(batchedEvents)
|
|
112
|
+
}).then(res => {
|
|
113
|
+
this.ackCrashes(ctx, crashIds, !!(res && res.ok));
|
|
114
|
+
}).catch(err => {
|
|
115
|
+
this.catchHandle(err);
|
|
116
|
+
this.ackCrashes(ctx, crashIds, false);
|
|
117
|
+
});
|
|
118
|
+
} catch (err) {
|
|
119
|
+
this.catchHandle(err);
|
|
120
|
+
this.ackCrashes(ctx, crashIds, false);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 通过共享 emitter 通知崩溃采集器上报结果(成功则删文件,失败保留重试) */
|
|
125
|
+
ackCrashes(ctx, crashIds, success) {
|
|
126
|
+
if (!crashIds.length) return;
|
|
127
|
+
try {
|
|
128
|
+
ctx.emitter?.emit(CRASH_REPORT_ACK_EVENT, {
|
|
129
|
+
crashIds,
|
|
130
|
+
success
|
|
131
|
+
});
|
|
132
|
+
} catch (e) {
|
|
133
|
+
logger.warn('reporter', 'emit crash ack failed', e);
|
|
134
|
+
}
|
|
49
135
|
}
|
|
50
136
|
catchHandle = err => {
|
|
51
|
-
|
|
137
|
+
logger.error('reporter', 'sendRequest failed', err);
|
|
52
138
|
};
|
|
53
139
|
destroy() {
|
|
54
140
|
this.appStateListener?.remove();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { convertBundlesToLogGroup } from '@arms/rum-core';
|
|
4
|
+
export class RNMonitorReporter {
|
|
5
|
+
constructor(endpoint) {
|
|
6
|
+
this.endpoint = this.buildMonitorEndpoint(endpoint);
|
|
7
|
+
}
|
|
8
|
+
send(data) {
|
|
9
|
+
if (!data || data.length === 0) return;
|
|
10
|
+
try {
|
|
11
|
+
// 使用 rum-core 的 Protobuf 编码器将数据编码为 SLS LogGroup 二进制格式
|
|
12
|
+
const protobufBody = convertBundlesToLogGroup(data);
|
|
13
|
+
fetch(this.endpoint, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/x-protobuf',
|
|
17
|
+
'x-log-apiversion': '0.6.0',
|
|
18
|
+
'x-log-compresstype': '',
|
|
19
|
+
'x-log-date': new Date().toUTCString()
|
|
20
|
+
},
|
|
21
|
+
body: protobufBody
|
|
22
|
+
}).catch(() => {
|
|
23
|
+
// 静默处理,避免反馈循环(不调用 logger)
|
|
24
|
+
});
|
|
25
|
+
} catch (_) {
|
|
26
|
+
// 吞掉异常,防止自监控影响宿主应用
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
buildMonitorEndpoint(endpoint) {
|
|
30
|
+
try {
|
|
31
|
+
const url = new URL(endpoint);
|
|
32
|
+
return `${url.origin}/rum/monitor`;
|
|
33
|
+
} catch (_) {
|
|
34
|
+
return endpoint;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=monitor-reporter.js.map
|
package/lib/module/shell.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { Shell } from '@arms/rum-core';
|
|
4
|
-
import
|
|
5
|
-
import ExceptionCollector from "./collector/exception/index.js";
|
|
6
|
-
import ApiCollector from "./collector/resource/api.js";
|
|
3
|
+
import { isFunction, Shell, callMonitored } from '@arms/rum-core';
|
|
4
|
+
import * as collectors from "./collector/index.js";
|
|
7
5
|
import DefaultProcessor from "./processor/default-processor.js";
|
|
8
6
|
import SessionProcessor from "./processor/session-processor.js";
|
|
9
7
|
import Reporter from "./reporter/index.js";
|
|
8
|
+
import { RNMonitorReporter } from "./reporter/monitor-reporter.js";
|
|
10
9
|
import { VERSION } from "./utils/platform.js";
|
|
11
10
|
import { RumSession } from "./utils/session.js";
|
|
12
11
|
import { startTrackingViews, stopTrackingViews } from "./utils/view.js";
|
|
12
|
+
const builtInCollectors = [...Object.values(collectors).filter(Collector => isFunction(Collector))];
|
|
13
13
|
/**
|
|
14
14
|
* 对外导出 shell 层, 所有 shell 层模型的 API 设计约定:
|
|
15
15
|
* 1. API 命名空间按照 variables / functions / events 来组织
|
|
@@ -23,10 +23,12 @@ export class ArmsRum extends Shell {
|
|
|
23
23
|
* 初始化
|
|
24
24
|
*/
|
|
25
25
|
init(config) {
|
|
26
|
-
this.client.useCollectors(
|
|
26
|
+
this.client.useCollectors(builtInCollectors.map(Collector => callMonitored(() => new Collector(), undefined, [], 'shell', `init ${Collector.name}`)).filter(Boolean));
|
|
27
27
|
this.client.useProcessors([new DefaultProcessor(), new SessionProcessor()]);
|
|
28
28
|
this.client.useReporter(new Reporter());
|
|
29
|
-
|
|
29
|
+
// 传入 MonitorReporter 激活自监控
|
|
30
|
+
const monitorReporter = config.endpoint ? new RNMonitorReporter(config.endpoint) : undefined;
|
|
31
|
+
this.client.init(config, new RumSession(), undefined, monitorReporter);
|
|
30
32
|
return this;
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -37,7 +39,6 @@ export class ArmsRum extends Shell {
|
|
|
37
39
|
setConfig(...params) {
|
|
38
40
|
const ctx = this.client.getContext();
|
|
39
41
|
if (params.length === 2) {
|
|
40
|
-
const ctx = this.client.getContext();
|
|
41
42
|
const oldConfig = ctx.getConfig();
|
|
42
43
|
ctx.setConfig({
|
|
43
44
|
...oldConfig,
|
|
@@ -47,6 +48,27 @@ export class ArmsRum extends Shell {
|
|
|
47
48
|
ctx.setConfig(params[0]);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 开启路由变化监听,自动采集 PV 数据
|
|
54
|
+
*
|
|
55
|
+
* 必须在 NavigationContainer 的 `onReady` 回调中调用,以确保
|
|
56
|
+
* navigationRef 已正确初始化。
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* <NavigationContainer
|
|
61
|
+
* ref={navigationRef}
|
|
62
|
+
* onReady={() => {
|
|
63
|
+
* ArmsRum.startTrackingViews(navigationRef);
|
|
64
|
+
* }}
|
|
65
|
+
* >
|
|
66
|
+
* ...
|
|
67
|
+
* </NavigationContainer>
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param navigationRef - NavigationContainer 的 ref 引用
|
|
71
|
+
*/
|
|
50
72
|
startTrackingViews(navigationRef) {
|
|
51
73
|
if (!navigationRef) return;
|
|
52
74
|
startTrackingViews(navigationRef);
|
|
@@ -54,6 +76,9 @@ export class ArmsRum extends Shell {
|
|
|
54
76
|
stopTrackingViews() {
|
|
55
77
|
stopTrackingViews();
|
|
56
78
|
}
|
|
79
|
+
getCollector(name) {
|
|
80
|
+
return this.client.getCollectors().find(collector => collector.name === name);
|
|
81
|
+
}
|
|
57
82
|
}
|
|
58
83
|
export default new ArmsRum();
|
|
59
84
|
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 崩溃相关类型定义
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** 崩溃上下文同步事件名 */
|
|
8
|
+
export const CRASH_CONTEXT_EVENT = 'crash_context_change';
|
|
9
|
+
|
|
10
|
+
/** 崩溃上报确认事件名(reporter -> crash collector,用于 ack 后删除文件) */
|
|
11
|
+
export const CRASH_REPORT_ACK_EVENT = 'crash_report_ack';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 挂在崩溃 RumEvent 上的瞬态字段名,携带 crash_id。
|
|
15
|
+
* reporter 上报前提取用于 ack、并在序列化前剥离,不会发送到后端。
|
|
16
|
+
*/
|
|
17
|
+
export const CRASH_ID_FIELD = '__rum_crash_id';
|
|
18
|
+
|
|
19
|
+
/** 崩溃上报确认事件负载 */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 崩溃上下文快照(session / view 变更时同步到原生侧)。
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 原生崩溃栈帧数据结构。
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 原生崩溃数据结构(与原生侧 RumCrashReporter / CrashContextManager 写入的 JSON 对齐)。
|
|
31
|
+
* 仅声明 JS 层会用到的字段,未列出的字段会通过 snapshots 透传给后端。
|
|
32
|
+
*/
|
|
33
|
+
//# sourceMappingURL=crash.js.map
|