@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.
Files changed (178) hide show
  1. package/README.md +399 -15
  2. package/RumSdkReactnative.podspec +28 -0
  3. package/android/build.gradle +83 -0
  4. package/android/gradle.properties +6 -0
  5. package/android/src/main/AndroidManifest.xml +13 -0
  6. package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +512 -0
  7. package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +33 -0
  8. package/android/src/main/java/com/rumsdkreactnative/crash/CrashContextManager.kt +157 -0
  9. package/android/src/main/java/com/rumsdkreactnative/crash/CrashHandler.kt +444 -0
  10. package/android/src/main/java/com/rumsdkreactnative/crash/CrashInitProvider.kt +50 -0
  11. package/android/src/main/java/com/rumsdkreactnative/crash/NdkCrashHandler.kt +66 -0
  12. package/android/src/main/jni/CMakeLists.txt +21 -0
  13. package/android/src/main/jni/rum_backtrace.c +144 -0
  14. package/android/src/main/jni/rum_crash_handler.c +200 -0
  15. package/android/src/main/jni/rum_crash_writer.c +442 -0
  16. package/android/src/main/jni/rum_module_info.c +316 -0
  17. package/android/src/main/jni/rum_module_info.h +54 -0
  18. package/android/src/main/jni/rum_test_crash.cpp +55 -0
  19. package/app.plugin.js +11 -0
  20. package/docs/ReactNative SDK/351/205/215/347/275/256/345/217/202/350/200/203.md" +671 -0
  21. package/docs/SDK /347/211/210/346/234/254/350/257/264/346/230/216.md" +12 -0
  22. package/docs//346/216/245/345/205/245ReactNative/345/272/224/347/224/250.md +238 -0
  23. package/ios/PrivacyInfo.xcprivacy +93 -0
  24. package/ios/RumCrashReporter.h +38 -0
  25. package/ios/RumCrashReporter.mm +861 -0
  26. package/ios/RumSdkReactnative.h +5 -0
  27. package/ios/RumSdkReactnative.mm +291 -0
  28. package/ios/fishhook/fishhook.c +264 -0
  29. package/ios/fishhook/fishhook.h +76 -0
  30. package/lib/commonjs/NativeRumSdkReactnative.js +50 -0
  31. package/lib/commonjs/collector/action/index.js +108 -0
  32. package/lib/commonjs/collector/exception/crash.js +148 -0
  33. package/lib/commonjs/collector/exception/index.js +238 -0
  34. package/lib/commonjs/collector/index.js +42 -0
  35. package/lib/commonjs/collector/resource/api.js +286 -0
  36. package/lib/commonjs/collector/view/perf.js +79 -0
  37. package/lib/commonjs/collector/view/pv.js +88 -0
  38. package/lib/commonjs/expoConfigPlugin.js +37 -0
  39. package/lib/commonjs/index.js +29 -0
  40. package/lib/commonjs/package.json +1 -0
  41. package/lib/commonjs/plugin.js +47 -0
  42. package/lib/commonjs/processor/default-processor.js +27 -0
  43. package/lib/commonjs/processor/session-processor.js +47 -0
  44. package/lib/commonjs/reporter/index.js +148 -0
  45. package/lib/commonjs/reporter/monitor-reporter.js +43 -0
  46. package/lib/commonjs/shell.js +91 -0
  47. package/lib/commonjs/types/client.js +6 -0
  48. package/lib/commonjs/types/crash.js +37 -0
  49. package/lib/commonjs/types/index.js +2 -0
  50. package/lib/commonjs/utils/action.js +305 -0
  51. package/lib/commonjs/utils/api.js +83 -0
  52. package/lib/commonjs/utils/base.js +95 -0
  53. package/lib/commonjs/utils/crash.js +146 -0
  54. package/lib/commonjs/utils/platform.js +162 -0
  55. package/lib/commonjs/utils/session.js +158 -0
  56. package/lib/commonjs/utils/url.js +59 -0
  57. package/lib/commonjs/utils/view.js +93 -0
  58. package/lib/module/NativeRumSdkReactnative.js +47 -0
  59. package/lib/module/collector/action/index.js +45 -10
  60. package/lib/module/collector/exception/crash.js +143 -0
  61. package/lib/module/collector/exception/index.js +144 -46
  62. package/lib/module/collector/index.js +8 -0
  63. package/lib/module/collector/resource/api.js +6 -6
  64. package/lib/module/collector/view/pv.js +13 -2
  65. package/lib/module/expoConfigPlugin.js +33 -0
  66. package/lib/module/index.js +1 -0
  67. package/lib/module/plugin.js +4 -1
  68. package/lib/module/processor/session-processor.js +22 -0
  69. package/lib/module/reporter/index.js +102 -16
  70. package/lib/module/reporter/monitor-reporter.js +38 -0
  71. package/lib/module/shell.js +32 -7
  72. package/lib/module/types/crash.js +33 -0
  73. package/lib/module/utils/action.js +299 -0
  74. package/lib/module/utils/api.js +10 -10
  75. package/lib/module/utils/base.js +9 -9
  76. package/lib/module/utils/crash.js +141 -0
  77. package/lib/module/utils/platform.js +127 -72
  78. package/lib/module/utils/session.js +23 -4
  79. package/lib/module/utils/view.js +2 -1
  80. package/lib/typescript/commonjs/package.json +1 -0
  81. package/lib/typescript/commonjs/src/NativeRumSdkReactnative.d.ts +49 -0
  82. package/lib/typescript/{src → commonjs/src}/collector/action/index.d.ts +7 -1
  83. package/lib/typescript/commonjs/src/collector/exception/crash.d.ts +28 -0
  84. package/lib/typescript/{src → commonjs/src}/collector/exception/index.d.ts +7 -0
  85. package/lib/typescript/commonjs/src/collector/index.d.ts +6 -0
  86. package/lib/typescript/{src → commonjs/src}/collector/view/pv.d.ts +2 -2
  87. package/lib/typescript/commonjs/src/expoConfigPlugin.d.ts +28 -0
  88. package/lib/typescript/commonjs/src/index.d.ts +6 -0
  89. package/lib/typescript/{src → commonjs/src}/processor/session-processor.d.ts +2 -0
  90. package/lib/typescript/{src → commonjs/src}/reporter/index.d.ts +3 -1
  91. package/lib/typescript/commonjs/src/reporter/monitor-reporter.d.ts +8 -0
  92. package/lib/typescript/commonjs/src/shell.d.ts +57 -0
  93. package/lib/typescript/{src → commonjs/src}/types/client.d.ts +2 -2
  94. package/lib/typescript/commonjs/src/types/crash.d.ts +95 -0
  95. package/lib/typescript/commonjs/src/utils/action.d.ts +63 -0
  96. package/lib/typescript/{src → commonjs/src}/utils/api.d.ts +1 -1
  97. package/lib/typescript/commonjs/src/utils/crash.d.ts +12 -0
  98. package/lib/typescript/commonjs/src/utils/platform.d.ts +22 -0
  99. package/lib/typescript/{src → commonjs/src}/utils/session.d.ts +4 -0
  100. package/lib/typescript/module/src/NativeRumSdkReactnative.d.ts +49 -0
  101. package/lib/typescript/module/src/collector/action/index.d.ts +21 -0
  102. package/lib/typescript/module/src/collector/exception/crash.d.ts +28 -0
  103. package/lib/typescript/module/src/collector/exception/index.d.ts +32 -0
  104. package/lib/typescript/module/src/collector/index.d.ts +6 -0
  105. package/lib/typescript/module/src/collector/resource/api.d.ts +21 -0
  106. package/lib/typescript/module/src/collector/view/perf.d.ts +1 -0
  107. package/lib/typescript/module/src/collector/view/pv.d.ts +16 -0
  108. package/lib/typescript/module/src/expoConfigPlugin.d.ts +28 -0
  109. package/lib/typescript/module/src/index.d.ts +6 -0
  110. package/lib/typescript/module/src/plugin.d.ts +3 -0
  111. package/lib/typescript/module/src/processor/default-processor.d.ts +6 -0
  112. package/lib/typescript/module/src/processor/session-processor.d.ts +11 -0
  113. package/lib/typescript/module/src/reporter/index.d.ts +18 -0
  114. package/lib/typescript/module/src/reporter/monitor-reporter.d.ts +8 -0
  115. package/lib/typescript/module/src/shell.d.ts +57 -0
  116. package/lib/typescript/module/src/types/client.d.ts +27 -0
  117. package/lib/typescript/module/src/types/crash.d.ts +95 -0
  118. package/lib/typescript/module/src/types/index.d.ts +118 -0
  119. package/lib/typescript/module/src/utils/action.d.ts +63 -0
  120. package/lib/typescript/module/src/utils/api.d.ts +59 -0
  121. package/lib/typescript/module/src/utils/base.d.ts +8 -0
  122. package/lib/typescript/module/src/utils/crash.d.ts +12 -0
  123. package/lib/typescript/module/src/utils/platform.d.ts +22 -0
  124. package/lib/typescript/module/src/utils/session.d.ts +41 -0
  125. package/lib/typescript/module/src/utils/url.d.ts +17 -0
  126. package/lib/typescript/module/src/utils/view.d.ts +13 -0
  127. package/package.json +61 -26
  128. package/LICENSE +0 -20
  129. package/lib/module/collector/action/index.js.map +0 -1
  130. package/lib/module/collector/exception/index.js.map +0 -1
  131. package/lib/module/collector/resource/api.js.map +0 -1
  132. package/lib/module/collector/view/perf.js.map +0 -1
  133. package/lib/module/collector/view/pv.js.map +0 -1
  134. package/lib/module/index.js.map +0 -1
  135. package/lib/module/plugin.js.map +0 -1
  136. package/lib/module/processor/default-processor.js.map +0 -1
  137. package/lib/module/processor/session-processor.js.map +0 -1
  138. package/lib/module/reporter/index.js.map +0 -1
  139. package/lib/module/shell.js.map +0 -1
  140. package/lib/module/types/client.js.map +0 -1
  141. package/lib/module/types/index.js.map +0 -1
  142. package/lib/module/utils/api.js.map +0 -1
  143. package/lib/module/utils/base.js.map +0 -1
  144. package/lib/module/utils/platform.js.map +0 -1
  145. package/lib/module/utils/session.js.map +0 -1
  146. package/lib/module/utils/url.js.map +0 -1
  147. package/lib/module/utils/view.js.map +0 -1
  148. package/lib/typescript/src/collector/action/index.d.ts.map +0 -1
  149. package/lib/typescript/src/collector/exception/index.d.ts.map +0 -1
  150. package/lib/typescript/src/collector/resource/api.d.ts.map +0 -1
  151. package/lib/typescript/src/collector/view/perf.d.ts.map +0 -1
  152. package/lib/typescript/src/collector/view/pv.d.ts.map +0 -1
  153. package/lib/typescript/src/index.d.ts +0 -4
  154. package/lib/typescript/src/index.d.ts.map +0 -1
  155. package/lib/typescript/src/plugin.d.ts.map +0 -1
  156. package/lib/typescript/src/processor/default-processor.d.ts.map +0 -1
  157. package/lib/typescript/src/processor/session-processor.d.ts.map +0 -1
  158. package/lib/typescript/src/reporter/index.d.ts.map +0 -1
  159. package/lib/typescript/src/shell.d.ts +0 -26
  160. package/lib/typescript/src/shell.d.ts.map +0 -1
  161. package/lib/typescript/src/types/client.d.ts.map +0 -1
  162. package/lib/typescript/src/types/index.d.ts.map +0 -1
  163. package/lib/typescript/src/utils/api.d.ts.map +0 -1
  164. package/lib/typescript/src/utils/base.d.ts.map +0 -1
  165. package/lib/typescript/src/utils/platform.d.ts +0 -15
  166. package/lib/typescript/src/utils/platform.d.ts.map +0 -1
  167. package/lib/typescript/src/utils/session.d.ts.map +0 -1
  168. package/lib/typescript/src/utils/url.d.ts.map +0 -1
  169. package/lib/typescript/src/utils/view.d.ts.map +0 -1
  170. /package/lib/typescript/{src → commonjs/src}/collector/resource/api.d.ts +0 -0
  171. /package/lib/typescript/{src → commonjs/src}/collector/view/perf.d.ts +0 -0
  172. /package/lib/typescript/{src → commonjs/src}/plugin.d.ts +0 -0
  173. /package/lib/typescript/{src → commonjs/src}/processor/default-processor.d.ts +0 -0
  174. /package/lib/typescript/{src → commonjs/src}/types/index.d.ts +0 -0
  175. /package/lib/typescript/{src → commonjs/src}/utils/base.d.ts +0 -0
  176. /package/lib/typescript/{src → commonjs/src}/utils/url.d.ts +0 -0
  177. /package/lib/typescript/{src → commonjs/src}/utils/view.d.ts +0 -0
  178. /package/lib/typescript/{package.json → module/package.json} +0 -0
@@ -1,87 +1,136 @@
1
1
  "use strict";
2
2
 
3
- import { AppType } from "@arms/rum-core";
4
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
+ import { AppType } from '@arms/rum-core';
4
+ import { Dimensions, Platform } from 'react-native';
5
+ import NativeRumSdkReactnative from "../NativeRumSdkReactnative.js";
6
+ const _pkg = {"version":"0.1.3-beta.0"};
7
+ export const VERSION = _pkg.version;
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
10
 
6
- // declare var __VERSION__: string;
7
- // export const VERSION = __VERSION__;
8
- export const VERSION = 'test';
9
11
  export const appName = 'react-native';
12
+
13
+ /**
14
+ * 从 react-native/package.json 获取 RN 运行时版本号,
15
+ * 用于 os.container_version。
16
+ */
17
+ function getReactNativeVersion() {
18
+ try {
19
+ const pkg = require('react-native/package.json');
20
+ return pkg.version ?? '';
21
+ } catch {
22
+ const info = Platform.constants?.reactNativeVersion;
23
+ if (info) {
24
+ return `${info.major}.${info.minor}.${info.patch}`;
25
+ }
26
+ return '';
27
+ }
28
+ }
29
+
30
+ // region Storage
31
+
10
32
  export function getStorage(key) {
11
- return AsyncStorage.getItem(key);
33
+ return NativeRumSdkReactnative.getItem(key);
12
34
  }
13
35
  export function setStorage(key, data) {
14
- return AsyncStorage.setItem(key, data);
36
+ return NativeRumSdkReactnative.setItem(key, data);
37
+ }
38
+ export function removeStorage(key) {
39
+ return NativeRumSdkReactnative.removeItem(key);
40
+ }
41
+ export function clearStorage() {
42
+ return NativeRumSdkReactnative.clear();
43
+ }
44
+ export function getAllStorageKeys() {
45
+ return NativeRumSdkReactnative.getAllKeys();
46
+ }
47
+
48
+ // endregion
49
+
50
+ // region Device Info
51
+
52
+ /**
53
+ * 调用原生桥采集设备信息。
54
+ * 失败时静默降级到 JS Platform API 填充基础字段。
55
+ */
56
+ async function fetchDeviceInfo() {
57
+ try {
58
+ return await NativeRumSdkReactnative.getDeviceInfo();
59
+ } catch (err) {
60
+ console.warn('[rum] getDeviceInfo failed, falling back to JS defaults', err);
61
+ return {
62
+ os_type: Platform.OS === 'ios' ? 'iOS' : 'Android',
63
+ os_version: String(Platform.Version ?? '')
64
+ };
65
+ }
66
+ }
67
+
68
+ /**
69
+ * 模块级缓存,首次调用 fixAttrs 时懒初始化,避免模块加载时原生桥尚未就绪。
70
+ * null 表示尚未触发采集。
71
+ */
72
+ let _cachedDeviceInfo = null;
73
+
74
+ /**
75
+ * 获取设备信息(懒初始化,仅触发一次原生桥调用)。
76
+ */
77
+ function getDeviceInfo() {
78
+ if (!_cachedDeviceInfo) {
79
+ _cachedDeviceInfo = fetchDeviceInfo();
80
+ }
81
+ return _cachedDeviceInfo;
15
82
  }
16
83
 
17
- // export function getNetType(): Promise<string> {
18
- // return new Promise((resolve) => {
19
- // try {
20
- // sdk.getNetworkType({
21
- // success: function (e) {
22
- // const networkType = e.networkType || e.subtype;
23
- // resolve(networkType ? networkType.toLowerCase() : undefined)
24
- // },
25
- // fail: function (res) {
26
- // resolve(undefined)
27
- // }
28
- // });
29
- // } catch (e) {
30
- // resolve(undefined)
31
- // }
32
- // })
33
- // }
34
-
35
- export const fixAttrs = function (bundle) {
84
+ // endregion
85
+
86
+ /**
87
+ * 将设备 / 系统 / 网络等公共属性注入 bundle。
88
+ * 在 Reporter.request 中被调用;首次调用时懒触发设备信息采集。
89
+ */
90
+ export const fixAttrs = async function (bundle) {
36
91
  if (!bundle) return;
37
- let device = {};
38
- let os = {};
39
- let net = {};
40
- // try {
41
- // device = {
42
- // id: DeviceInfo.getUniqueIdSync(),
43
- // type: DeviceInfo.getDeviceType(),
44
- // brand: DeviceInfo.getBrand(),
45
- // model: DeviceInfo.getModel(),
46
- // name: DeviceInfo.getDeviceNameSync(),
47
- // }
48
- //
49
- // os = {
50
- // type: DeviceInfo.getSystemName(),
51
- // version: DeviceInfo.getSystemVersion(),
52
- // container: appName,
53
- // container_version: DeviceInfo.getVersion(),
54
- // };
55
- //
56
- // net = {
57
- // // model: ,
58
- // // @ts-ignore
59
- // ip: DeviceInfo.getIpAddressSync(),
60
- // }
61
- // } catch (err) {
62
- // console.warn('[rum] react-native-device-info fail', err);
63
- // const info = Platform.constants;
64
- // const rn = info.reactNativeVersion;
65
- // os.type = info.systemName;
66
- // os.version = info.osVersion;
67
- // os.container_version = `${rn.major}.${rn.minor}.${rn.patch}`;
68
- // }
69
- // try {
70
- // const info = Platform.constants;
71
- // const rn = info.reactNativeVersion;
72
- // os.type = info.systemName;
73
- // os.version = info.osVersion;
74
- // os.container = appName;
75
- // os.container_version = `${rn.major}.${rn.minor}.${rn.patch}`;
76
- // } catch (e) {
77
- // //
78
- // }
92
+ const native = await getDeviceInfo();
93
+
94
+ // device.*
95
+ const device = {
96
+ id: native.device_id,
97
+ type: native.device_type,
98
+ brand: native.device_brand,
99
+ model: native.device_model,
100
+ name: native.device_name
101
+ };
102
+
103
+ // os.*
104
+ const rnVersion = getReactNativeVersion();
105
+ const os = {
106
+ type: native.os_type ?? (Platform.OS === 'ios' ? 'iOS' : 'Android'),
107
+ version: native.os_version ?? String(Platform.Version ?? ''),
108
+ container: appName,
109
+ container_version: rnVersion || undefined
110
+ };
111
+
112
+ // viewport:优先使用原生采集的物理像素,兜底 JS Dimensions(逻辑像素)
113
+ let viewport;
114
+ if (native.viewport_width && native.viewport_height) {
115
+ viewport = {
116
+ width: native.viewport_width,
117
+ height: native.viewport_height
118
+ };
119
+ } else {
120
+ try {
121
+ const screen = Dimensions.get('screen');
122
+ viewport = {
123
+ width: Math.round(screen.width),
124
+ height: Math.round(screen.height)
125
+ };
126
+ } catch {
127
+ // 忽略
128
+ }
129
+ }
79
130
  bundle.app.type = AppType.reactnative;
131
+ bundle.app.package = bundle.app.package ?? native.app_package;
132
+ bundle.app.version = bundle.app.version ?? native.app_version;
80
133
  bundle._v = VERSION;
81
- bundle.net = {
82
- ...net,
83
- ...bundle.net
84
- };
85
134
  bundle.device = {
86
135
  ...device,
87
136
  ...bundle.device
@@ -90,6 +139,12 @@ export const fixAttrs = function (bundle) {
90
139
  ...os,
91
140
  ...bundle.os
92
141
  };
142
+ if (viewport) {
143
+ bundle.viewport = {
144
+ ...bundle.viewport,
145
+ ...viewport
146
+ };
147
+ }
93
148
  return bundle;
94
149
  };
95
150
  //# sourceMappingURL=platform.js.map
@@ -6,11 +6,21 @@ import { getCurView } from "./view.js";
6
6
  import { getStorage, setStorage } from "./platform.js";
7
7
 
8
8
  // 存储userID的键名
9
- const USER_ID = '_arms_uid';
9
+ const USER_ID = '_rum_uid';
10
+ // 旧版键名(用于迁移)
11
+ const LEGACY_USER_ID = '_arms_uid';
10
12
  // 存储session
11
- // const RUM_SESSION = '_arms_session';
13
+ // const RUM_SESSION = '_rum_session';
12
14
 
13
15
  export class RumSession {
16
+ /** 平台类型标识 */
17
+ appType = 'reactnative';
18
+
19
+ /** SDK 版本号(延迟导入避免循环依赖) */
20
+ get sdkVersion() {
21
+ return require('./platform').VERSION;
22
+ }
23
+
14
24
  // @ts-ignore
15
25
 
16
26
  // private sessionId = '';
@@ -54,8 +64,8 @@ export class RumSession {
54
64
  let info = {
55
65
  sessionId: sid,
56
66
  sampled: sampled !== '0',
57
- startTime: parseInt(startTime || '') || 0,
58
- lastTime: parseInt(lastTime || '') || 0
67
+ startTime: parseInt(startTime || '', 10) || 0,
68
+ lastTime: parseInt(lastTime || '', 10) || 0
59
69
  };
60
70
  if (!this.checkSession(info)) {
61
71
  info = this.resetSession();
@@ -71,6 +81,15 @@ export class RumSession {
71
81
  }
72
82
  async initUser() {
73
83
  this.userId = await getStorage(USER_ID);
84
+ // 迁移旧版键名 _arms_uid → _rum_uid
85
+ if (!this.userId) {
86
+ const legacyId = await getStorage(LEGACY_USER_ID);
87
+ if (legacyId) {
88
+ this.userId = legacyId;
89
+ await setStorage(USER_ID, this.userId);
90
+ return;
91
+ }
92
+ }
74
93
  if (!this.userId) {
75
94
  this.userId = `uid_${generateSpanId(16, 36)}`;
76
95
  await setStorage(USER_ID, this.userId);
@@ -70,6 +70,7 @@ function triggerNavigateChange(event) {
70
70
  }
71
71
  export function startTrackingViews(nav) {
72
72
  if (!nav || currentNavigationRef) return;
73
+ currentNavigationRef = nav;
73
74
  if (isFunction(nav.events)) {
74
75
  // react-native-navigation
75
76
  nav.events().registerComponentDidAppearListener(triggerNavigateChange);
@@ -77,7 +78,7 @@ export function startTrackingViews(nav) {
77
78
  // @react-native/navigation
78
79
  nav.addListener('state', triggerNavigateChange);
79
80
  }
80
- currentNavigationRef = nav;
81
+ triggerNavigateChange({});
81
82
  }
82
83
  export function stopTrackingViews() {
83
84
  if (!currentNavigationRef) return;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,49 @@
1
+ import type { TurboModule } from 'react-native';
2
+ /**
3
+ * 原生设备信息,对应存储模型中的公共属性:
4
+ * - device.* (id / type / brand / model / name)
5
+ * - os.* (type / version / container / container_version)
6
+ * - app.package
7
+ * - viewport.width / viewport.height
8
+ */
9
+ export interface NativeDeviceInfo {
10
+ device_id?: string;
11
+ device_type?: string;
12
+ device_brand?: string;
13
+ device_model?: string;
14
+ device_name?: string;
15
+ os_type?: string;
16
+ os_version?: string;
17
+ app_package?: string;
18
+ app_version?: string;
19
+ viewport_width?: number;
20
+ viewport_height?: number;
21
+ }
22
+ export interface Spec extends TurboModule {
23
+ getItem(key: string): Promise<string | null>;
24
+ setItem(key: string, value: string): Promise<void>;
25
+ removeItem(key: string): Promise<void>;
26
+ clear(): Promise<void>;
27
+ getAllKeys(): Promise<string[]>;
28
+ /**
29
+ * 采集原生平台设备信息,仅在初始化时调用一次。
30
+ */
31
+ getDeviceInfo(): Promise<NativeDeviceInfo>;
32
+ /** 获取待上报的崩溃报告列表(下次启动时调用) */
33
+ getPendingCrashes(): Promise<string>;
34
+ /** 清除已上报的崩溃文件 */
35
+ clearCrashReports(crashIds: string): Promise<void>;
36
+ /** 清除所有崩溃报告文件(用于清理无 crash_id 的旧版文件) */
37
+ clearAllCrashReports(): Promise<void>;
38
+ /** 清理过期和超限的崩溃文件(maxFiles 上限,maxAgeMs 过期时间) */
39
+ cleanupOldCrashes(maxFiles: number, maxAgeMs: number): Promise<void>;
40
+ /** 查询上次运行是否发生过崩溃 */
41
+ crashedLastRun(): Promise<boolean>;
42
+ /** 更新崩溃上下文快照(session/view 变更时调用) */
43
+ updateCrashContext(context: string): void;
44
+ /** 触发测试崩溃(仅用于开发调试,调用后 App 立即崩溃) */
45
+ triggerTestCrash(crashType: string): void;
46
+ }
47
+ declare const _default: Spec;
48
+ export default _default;
49
+ //# sourceMappingURL=NativeRumSdkReactnative.d.ts.map
@@ -3,12 +3,18 @@ export default class ActionCollector implements ICollector {
3
3
  name: string;
4
4
  private DELAY_TIME;
5
5
  ctx?: IContext;
6
- sendEvent?: ((payload: RumEvent) => void);
6
+ sendEvent?: (payload: RumEvent) => void;
7
7
  events: string[];
8
8
  lastEvent?: RumActionEvent;
9
+ lastActionId?: string;
9
10
  timer: any;
10
11
  setup(ctx: IContext, sendEvent: (payload: RumEvent) => void): void;
11
12
  onEvent: (e: any) => void;
13
+ /**
14
+ * 组装热力图相关的 target 信息(selector/宽高/可交互性/可信度)。
15
+ * 当没有任何字段时返回 undefined,避免上报空对象。
16
+ */
17
+ private buildTarget;
12
18
  sendAction: () => void;
13
19
  destroy(): void;
14
20
  }
@@ -0,0 +1,28 @@
1
+ import type { ICollector, IContext, SendEventFn } from '@arms/rum-core';
2
+ /**
3
+ * 崩溃采集器(Exception 的子类型):
4
+ * 1. 初始化时读取上次运行写入的原生崩溃文件,转换为 RumEvent 通过标准管线上报;
5
+ * 2. 通过 ctx.emitter 订阅上下文变更事件,同步到原生侧
6
+ * (用于下一次启动时崩溃报告携带正确上下文)。
7
+ */
8
+ export default class CrashCollector implements ICollector {
9
+ name: string;
10
+ private ctx?;
11
+ private sendEvent?;
12
+ private initialized;
13
+ /** 已上报待确认(ack)的 crash_id,成功后才删文件 */
14
+ private pendingAckIds;
15
+ setup(ctx: IContext, sendEvent: SendEventFn): void;
16
+ private processPendingCrashes;
17
+ /** 兜底清理:删除过期和超限的崩溃文件,防止存储耗尽 */
18
+ private cleanupOldCrashes;
19
+ private onCrashContextChange;
20
+ /**
21
+ * reporter 上报确认回调:
22
+ * - 成功:删除对应 crash_id 的崩溃文件(确保上报成功后才删,不丢数据);
23
+ * - 失败:保留文件,下次启动重试,仅从内存待确认集合中移除。
24
+ */
25
+ private onCrashReportAck;
26
+ destroy(): void;
27
+ }
28
+ //# sourceMappingURL=crash.d.ts.map
@@ -3,9 +3,16 @@ export default class ExceptionCollector implements ICollector {
3
3
  name: string;
4
4
  ctx?: IContext;
5
5
  sendEvent?: (payload: RumEvent) => void;
6
+ private installed;
7
+ /** fatal 去重保护:防止连续 fatal error 重复上报 */
8
+ private handlingFatal;
9
+ /** 防止 errorHandle 内部 console.error 形成循环 */
10
+ private inErrorHandle;
6
11
  private origin;
7
12
  setup(ctx: IContext, sendEvent: (payload: RumEvent) => void): void;
8
13
  hackOrigin(): void;
14
+ /** JSC 引擎 Promise rejection 兜底方案 */
15
+ private setupJSCPromiseRejection;
9
16
  onError: (e: Error | string, isFatal?: boolean) => void;
10
17
  onUnhandled: (_id: string, error: unknown) => void;
11
18
  errorHandle: (error: any, source?: string) => void;
@@ -0,0 +1,6 @@
1
+ export { default as PvCollector } from './view/pv';
2
+ export { default as ExceptionCollector } from './exception/index';
3
+ export { default as CrashCollector } from './exception/crash';
4
+ export { default as ApiCollector } from './resource/api';
5
+ export { default as ActionCollector } from './action/index';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { ICollector, IContext, RumEvent } from '@arms/rum-core';
2
- import { IPage } from "../../types/client";
3
- import { Route } from "../../types";
2
+ import { IPage } from '../../types/client';
3
+ import { Route } from '../../types';
4
4
  export default class PvCollector implements ICollector {
5
5
  name: string;
6
6
  ctx?: IContext;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Expo config plugin for @arms/rum-reactnative.
3
+ *
4
+ * 在 app.config 中声明后,将 SDK 配置写入 `expoConfig.extra.rumSdk`,运行时可通过
5
+ * `Constants.expoConfig?.extra?.rumSdk` 读取,避免在 JS 入口硬编码 endpoint。
6
+ *
7
+ * app.config.ts 示例:
8
+ * plugins: [['@arms/rum-reactnative', { endpoint: '...', env: 'prod' }]]
9
+ *
10
+ * 仅做配置透传,不注入原生构建设置(podspec / gradle 已由 autolinking 处理)。
11
+ * 零运行时依赖,非 Expo 用户安装本包不会拉入 @expo/* 。
12
+ */
13
+ /** 本插件触碰到的 expo config 切片,故意放宽以避免对 @expo/config-types 的硬依赖。 */
14
+ export interface RumExpoConfig {
15
+ [key: string]: unknown;
16
+ extra?: Record<string, unknown>;
17
+ }
18
+ export interface RumSdkPluginProps {
19
+ /** ARMS 上报地址,可在控制台创建应用后获取 */
20
+ endpoint?: string;
21
+ /** 环境,默认 'prod' */
22
+ env?: 'prod' | 'gray' | 'pre' | 'daily' | 'local';
23
+ /** 应用版本号 */
24
+ version?: string;
25
+ }
26
+ declare const withRumSdk: (config: RumExpoConfig, props?: RumSdkPluginProps) => RumExpoConfig;
27
+ export default withRumSdk;
28
+ //# sourceMappingURL=expoConfigPlugin.d.ts.map
@@ -0,0 +1,6 @@
1
+ import armsRum, { ArmsRum } from './shell';
2
+ export { logger, callMonitored } from '@arms/rum-core';
3
+ export type { ISelfMonitorConfig } from '@arms/rum-core';
4
+ export { ArmsRum };
5
+ export default armsRum;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -2,8 +2,10 @@ import { IContext, IProcessor } from '@arms/rum-core';
2
2
  export default class SessionProcessor implements IProcessor {
3
3
  name: string;
4
4
  ctx?: IContext;
5
+ private lastSessionId;
5
6
  setup(ctx: IContext): void;
6
7
  update: (e?: Event) => void;
7
8
  process(ctx: IContext): import("@arms/rum-core").RumEvent;
9
+ private syncCrashContext;
8
10
  }
9
11
  //# sourceMappingURL=session-processor.d.ts.map
@@ -8,7 +8,9 @@ declare class RNReporter extends Reporter implements IReporter {
8
8
  constructor();
9
9
  init(ctx: IContext): void;
10
10
  onAppStateChanged: (nextAppState: string) => void;
11
- request(ctx: IContext, bundle: RumEventBundle): void;
11
+ request(ctx: IContext, bundle: RumEventBundle): Promise<void>;
12
+ /** 通过共享 emitter 通知崩溃采集器上报结果(成功则删文件,失败保留重试) */
13
+ private ackCrashes;
12
14
  catchHandle: (err: any) => void;
13
15
  destroy(): void;
14
16
  }
@@ -0,0 +1,8 @@
1
+ import { IMonitorReporter, MonitorEventBundle } from '@arms/rum-core';
2
+ export declare class RNMonitorReporter implements IMonitorReporter {
3
+ private endpoint;
4
+ constructor(endpoint: string);
5
+ send(data: MonitorEventBundle[]): void;
6
+ private buildMonitorEndpoint;
7
+ }
8
+ //# sourceMappingURL=monitor-reporter.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { Shell } from '@arms/rum-core';
2
+ import * as collectors from './collector';
3
+ import { IRNConfig } from './types/client';
4
+ import { NavigationContainerRef } from './types';
5
+ declare const builtInCollectors: readonly (typeof collectors.PvCollector | typeof collectors.ExceptionCollector | typeof collectors.CrashCollector | typeof collectors.ApiCollector | typeof collectors.ActionCollector)[];
6
+ type CollectorName = (typeof builtInCollectors)[number]['prototype']['name'];
7
+ type CollectorMap = {
8
+ [K in CollectorName]: InstanceType<Extract<(typeof builtInCollectors)[number], {
9
+ prototype: {
10
+ name: K;
11
+ };
12
+ }>>;
13
+ };
14
+ /**
15
+ * 对外导出 shell 层, 所有 shell 层模型的 API 设计约定:
16
+ * 1. API 命名空间按照 variables / functions / events 来组织
17
+ * 2. 事件(events)的命名格式为:on[Will|Did]VerbNoun?,参考 https://code.visualstudio.com/api/references/vscode-api#events
18
+ * 3. 基于 Disposable 模式,对于事件的绑定、快捷键的绑定函数,返回值则是解绑函数
19
+ */
20
+ export declare class ArmsRum extends Shell {
21
+ version: string;
22
+ /**
23
+ * 初始化
24
+ */
25
+ init(config: IRNConfig): this;
26
+ /**
27
+ * set config
28
+ */
29
+ setConfig<T extends keyof IRNConfig>(key: T, value: IRNConfig[T]): void;
30
+ setConfig(value: IRNConfig): void;
31
+ /**
32
+ * 开启路由变化监听,自动采集 PV 数据
33
+ *
34
+ * 必须在 NavigationContainer 的 `onReady` 回调中调用,以确保
35
+ * navigationRef 已正确初始化。
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * <NavigationContainer
40
+ * ref={navigationRef}
41
+ * onReady={() => {
42
+ * ArmsRum.startTrackingViews(navigationRef);
43
+ * }}
44
+ * >
45
+ * ...
46
+ * </NavigationContainer>
47
+ * ```
48
+ *
49
+ * @param navigationRef - NavigationContainer 的 ref 引用
50
+ */
51
+ startTrackingViews(navigationRef: NavigationContainerRef | any): void;
52
+ stopTrackingViews(): void;
53
+ getCollector<T extends CollectorName>(name: T): CollectorMap[T] | undefined;
54
+ }
55
+ declare const _default: ArmsRum;
56
+ export default _default;
57
+ //# sourceMappingURL=shell.d.ts.map
@@ -1,5 +1,5 @@
1
- import { IConfiguration, ITracingOption } from "@arms/rum-core";
2
- import { IApiBaseAttr } from "../utils/api";
1
+ import { IConfiguration, ITracingOption } from '@arms/rum-core';
2
+ import { IApiBaseAttr } from '../utils/api';
3
3
  export interface IPage {
4
4
  id: string;
5
5
  path?: string;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * 崩溃相关类型定义
3
+ */
4
+ /** 崩溃上下文同步事件名 */
5
+ export declare const CRASH_CONTEXT_EVENT = "crash_context_change";
6
+ /** 崩溃上报确认事件名(reporter -> crash collector,用于 ack 后删除文件) */
7
+ export declare const CRASH_REPORT_ACK_EVENT = "crash_report_ack";
8
+ /**
9
+ * 挂在崩溃 RumEvent 上的瞬态字段名,携带 crash_id。
10
+ * reporter 上报前提取用于 ack、并在序列化前剥离,不会发送到后端。
11
+ */
12
+ export declare const CRASH_ID_FIELD = "__rum_crash_id";
13
+ /** 崩溃上报确认事件负载 */
14
+ export interface CrashReportAck {
15
+ /** 本次上报包含的 crash_id 列表 */
16
+ crashIds: string[];
17
+ /** 上报是否成功(HTTP 2xx) */
18
+ success: boolean;
19
+ }
20
+ /**
21
+ * 崩溃上下文快照(session / view 变更时同步到原生侧)。
22
+ */
23
+ export interface CrashContextSnapshot {
24
+ session_id?: string;
25
+ view_id?: string;
26
+ view_name?: string;
27
+ user_id?: string;
28
+ }
29
+ /**
30
+ * 原生崩溃栈帧数据结构。
31
+ */
32
+ export interface NativeCrashFrame {
33
+ library?: string;
34
+ symbol?: string;
35
+ address?: string;
36
+ /** 模块加载基址(Android NDK 提供,供后端结合 build_id 符号化) */
37
+ image_addr?: string;
38
+ offset?: string;
39
+ line?: number;
40
+ /** 截断标记帧:true 表示此帧为双侧截断的中间标记,非实际栈帧 */
41
+ truncated?: boolean;
42
+ /** 被省略的帧数(-1 表示未知总数,NDK 场景) */
43
+ omitted_count?: number;
44
+ }
45
+ /**
46
+ * 原生崩溃数据结构(与原生侧 RumCrashReporter / CrashContextManager 写入的 JSON 对齐)。
47
+ * 仅声明 JS 层会用到的字段,未列出的字段会通过 snapshots 透传给后端。
48
+ */
49
+ export interface NativeCrashData {
50
+ /** crash_id 可选,兼容旧版 NDK 崩溃文件(无 crash_id 字段) */
51
+ crash_id?: string;
52
+ timestamp?: number;
53
+ signal?: {
54
+ name?: string;
55
+ /** NDK 写入为数字(si_code),Java 侧可能为字符串 */
56
+ code?: string | number;
57
+ fault_address?: string;
58
+ /** NDK 信号编号 */
59
+ number?: number;
60
+ };
61
+ exception?: {
62
+ type?: string;
63
+ class_name?: string;
64
+ message?: string;
65
+ };
66
+ /**
67
+ * 顶层 frames(NDK 崩溃格式)。
68
+ * NDK 崩溃 JSON 的 frames 在顶层,不在 crashed_thread 内。
69
+ */
70
+ frames?: NativeCrashFrame[] | string[];
71
+ crashed_thread?: {
72
+ id?: number | string;
73
+ /** frames 兼容新版对象格式和旧版字符串格式 */
74
+ frames?: NativeCrashFrame[] | string[];
75
+ };
76
+ /** NDK 崩溃进程 ID */
77
+ pid?: number;
78
+ /** NDK 崩溃线程 ID */
79
+ tid?: number;
80
+ /** NDK 崩溃架构(arm64/arm/x86_64/x86) */
81
+ arch?: string;
82
+ binary_images?: unknown[];
83
+ device?: Record<string, unknown>;
84
+ registers?: Record<string, unknown>;
85
+ app?: Record<string, unknown>;
86
+ context?: {
87
+ session_id?: string;
88
+ view_id?: string;
89
+ view_name?: string;
90
+ user_id?: string;
91
+ };
92
+ /** 崩溃机制信息(iOS normalizeKSCrashReport / Android getPendingCrashes 写入) */
93
+ mechanism?: Record<string, unknown>;
94
+ }
95
+ //# sourceMappingURL=crash.d.ts.map