@arms/rum-reactnative 0.1.2 → 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 +79 -1
- 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 +11 -0
- package/lib/module/expoConfigPlugin.js +33 -0
- package/lib/module/index.js +1 -0
- 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 +11 -7
- package/lib/module/types/crash.js +33 -0
- package/lib/module/utils/action.js +299 -0
- package/lib/module/utils/crash.js +141 -0
- package/lib/module/utils/platform.js +124 -72
- package/lib/module/utils/session.js +23 -4
- 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 +6 -0
- 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/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/{src → commonjs/src}/shell.d.ts +11 -0
- 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/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 +51 -28
- 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.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}/collector/view/pv.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/client.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/types/index.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/api.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
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _rumCore = require("@arms/rum-core");
|
|
8
|
+
var _base = require("../../utils/base");
|
|
9
|
+
var _api = require("../../utils/api");
|
|
10
|
+
class ApiCollector {
|
|
11
|
+
name = 'api-collector';
|
|
12
|
+
setup(ctx, sendEvent) {
|
|
13
|
+
const collectors = ctx.getConfig().collectors || {};
|
|
14
|
+
if (collectors.api === false) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.sendEvent = sendEvent;
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
// this.perfObserver();
|
|
20
|
+
this.hackXhr();
|
|
21
|
+
// this.hackFetch();
|
|
22
|
+
}
|
|
23
|
+
injectTracing(apiAttr, inject) {
|
|
24
|
+
const {
|
|
25
|
+
tracing = false,
|
|
26
|
+
pid,
|
|
27
|
+
version = '1.0.0'
|
|
28
|
+
} = this.ctx.getConfig();
|
|
29
|
+
const {
|
|
30
|
+
enable,
|
|
31
|
+
sample,
|
|
32
|
+
propagatorTypes,
|
|
33
|
+
allowedUrls,
|
|
34
|
+
tracestate,
|
|
35
|
+
baggage = false
|
|
36
|
+
} = (0, _rumCore.parseTracingOptions)(tracing);
|
|
37
|
+
if (!enable) return;
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const resolvedTraceOption = (0, _rumCore.find)(allowedUrls, item => (0, _rumCore.matchList)([item.match], apiAttr.url || ''));
|
|
40
|
+
if (!resolvedTraceOption) return;
|
|
41
|
+
let pTypes = resolvedTraceOption.propagatorTypes;
|
|
42
|
+
if (pTypes && pTypes.length === 0) {
|
|
43
|
+
pTypes = propagatorTypes;
|
|
44
|
+
}
|
|
45
|
+
// skywalking
|
|
46
|
+
let isSw8 = false;
|
|
47
|
+
if (pTypes && pTypes.indexOf('sw8') > -1) {
|
|
48
|
+
pTypes = ['sw8'];
|
|
49
|
+
isSw8 = true;
|
|
50
|
+
}
|
|
51
|
+
const session = this.ctx.session;
|
|
52
|
+
const traceId = isSw8 ? (0, _rumCore.generateGUID)() : (0, _rumCore.generateTraceId)();
|
|
53
|
+
const spanId = isSw8 ? (0, _rumCore.generateGUID)() : (0, _rumCore.generateSpanId)();
|
|
54
|
+
const sampled = (0, _rumCore.performDraw)(sample);
|
|
55
|
+
const uid = session.getUserId();
|
|
56
|
+
const sid = session.getSessionId();
|
|
57
|
+
const traceContext = tracestate ? `rum=v2&browser&${pid}&${sid}&${uid}` : undefined;
|
|
58
|
+
const baggageContext = baggage ? `rum=v2,appType=browser,pid=${pid},sid=${sid},uid=${uid}` : undefined;
|
|
59
|
+
const tracingHeaders = (0, _rumCore.makeTracingHeaders)(traceId, spanId, sampled, pTypes || [], {
|
|
60
|
+
tracestate: traceContext,
|
|
61
|
+
baggage: baggageContext,
|
|
62
|
+
appId: pid,
|
|
63
|
+
appVersion: version,
|
|
64
|
+
viewName: apiAttr.view?.name
|
|
65
|
+
// host: location.host
|
|
66
|
+
});
|
|
67
|
+
if (sampled) {
|
|
68
|
+
apiAttr.trace_id = traceId;
|
|
69
|
+
apiAttr.trace_data = JSON.stringify({
|
|
70
|
+
spanId,
|
|
71
|
+
sample,
|
|
72
|
+
sampled,
|
|
73
|
+
headers: tracingHeaders
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
inject(tracingHeaders);
|
|
77
|
+
}
|
|
78
|
+
hackXhr() {
|
|
79
|
+
const oldXHRProto = XMLHttpRequest.prototype;
|
|
80
|
+
const self = this;
|
|
81
|
+
(0, _rumCore.interceptFunction)(oldXHRProto, 'open', function (method, url, async, user, password) {
|
|
82
|
+
const filters = self.ctx.getConfig().filters || {};
|
|
83
|
+
const urlStr = String(url);
|
|
84
|
+
const methodStr = method.toUpperCase();
|
|
85
|
+
// chrome 对 URL 的最大长度为 8182 个字符
|
|
86
|
+
if ((0, _rumCore.urlMatch)(urlStr, filters.resource) || methodStr === 'HEAD' || urlStr.length > 8182) return;
|
|
87
|
+
this.apiCache = {
|
|
88
|
+
type: _api.ApiType.XHR,
|
|
89
|
+
method,
|
|
90
|
+
url,
|
|
91
|
+
async,
|
|
92
|
+
user,
|
|
93
|
+
password,
|
|
94
|
+
headers: {}
|
|
95
|
+
};
|
|
96
|
+
const baseRumEvent = self.ctx.session.getBaseEvent();
|
|
97
|
+
this.apiAttr = {
|
|
98
|
+
...baseRumEvent,
|
|
99
|
+
url: urlStr,
|
|
100
|
+
method: methodStr
|
|
101
|
+
};
|
|
102
|
+
}, true);
|
|
103
|
+
(0, _rumCore.interceptFunction)(oldXHRProto, 'setRequestHeader', function (header, value) {
|
|
104
|
+
if (!this.apiCache) return;
|
|
105
|
+
this.apiCache.headers = {
|
|
106
|
+
...this.apiCache.headers,
|
|
107
|
+
[header]: value
|
|
108
|
+
};
|
|
109
|
+
}, true);
|
|
110
|
+
(0, _rumCore.interceptFunction)(oldXHRProto, 'send', function (body) {
|
|
111
|
+
if (!this.apiAttr || !this.apiCache) return;
|
|
112
|
+
let apiAttr = this.apiAttr;
|
|
113
|
+
this.apiCache.data = body;
|
|
114
|
+
self.injectTracing(this.apiAttr, tracingHeaders => {
|
|
115
|
+
Object.keys(tracingHeaders).forEach(key => {
|
|
116
|
+
tracingHeaders[key] && this.setRequestHeader(key, tracingHeaders[key]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
this.addEventListener('loadend', async () => {
|
|
120
|
+
const {
|
|
121
|
+
status,
|
|
122
|
+
statusText,
|
|
123
|
+
response
|
|
124
|
+
} = this;
|
|
125
|
+
const {
|
|
126
|
+
evaluateApi
|
|
127
|
+
} = self.ctx.getConfig();
|
|
128
|
+
if (!this.apiAttr) return;
|
|
129
|
+
apiAttr.status_code = status;
|
|
130
|
+
apiAttr.message = statusText;
|
|
131
|
+
const entry = {
|
|
132
|
+
name: this.apiAttr.url,
|
|
133
|
+
entryType: _api.ApiType.XHR,
|
|
134
|
+
duration: (0, _base.getCurrentTime)() - apiAttr.timestamp
|
|
135
|
+
};
|
|
136
|
+
if ((0, _rumCore.isFunction)(evaluateApi)) {
|
|
137
|
+
try {
|
|
138
|
+
let error;
|
|
139
|
+
if (apiAttr.success === _rumCore.ResourceStatus.Failed) {
|
|
140
|
+
error = new Error(_api.ApiType.XHR + ' error');
|
|
141
|
+
}
|
|
142
|
+
const attrs = await evaluateApi?.(this.apiCache, response, error, this);
|
|
143
|
+
this.apiAttr = apiAttr = {
|
|
144
|
+
...apiAttr,
|
|
145
|
+
...(0, _api.reviseApiAttr)(attrs)
|
|
146
|
+
};
|
|
147
|
+
} catch (e) {
|
|
148
|
+
_rumCore.logger.warn('api-collector', 'evaluateApi failed for XHR', e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
self.sendAPI(apiAttr, entry);
|
|
152
|
+
});
|
|
153
|
+
this.addEventListener('error', () => {
|
|
154
|
+
this.apiAttr && (this.apiAttr.success = _rumCore.ResourceStatus.Failed);
|
|
155
|
+
});
|
|
156
|
+
}, true);
|
|
157
|
+
}
|
|
158
|
+
hackFetch() {
|
|
159
|
+
const self = this;
|
|
160
|
+
const originFetch = this.originFetch = globalThis.fetch;
|
|
161
|
+
const filters = this.ctx.getConfig().filters || {};
|
|
162
|
+
globalThis.fetch = function (input, init = {}) {
|
|
163
|
+
const isReq = input instanceof Request;
|
|
164
|
+
const urlStr = isReq ? input.url : (0, _rumCore.isString)(input) ? input : input.toString();
|
|
165
|
+
let method = init.method;
|
|
166
|
+
let headers = init.headers;
|
|
167
|
+
if (isReq) {
|
|
168
|
+
!method && (method = input.method);
|
|
169
|
+
!headers && (headers = input.headers);
|
|
170
|
+
}
|
|
171
|
+
method = method ? method.toUpperCase() : 'GET';
|
|
172
|
+
if (!headers) {
|
|
173
|
+
init.headers = headers = new Headers();
|
|
174
|
+
}
|
|
175
|
+
if ((0, _rumCore.urlMatch)(urlStr, filters.resource) || method === 'HEAD' || init?.mode === 'no-cors' || urlStr.length > 8182) {
|
|
176
|
+
return originFetch.call(global, input, init);
|
|
177
|
+
}
|
|
178
|
+
const baseRumEvent = self.ctx.session.getBaseEvent();
|
|
179
|
+
let apiAttr = {
|
|
180
|
+
...baseRumEvent,
|
|
181
|
+
url: urlStr,
|
|
182
|
+
type: _api.ApiType.FETCH,
|
|
183
|
+
method
|
|
184
|
+
};
|
|
185
|
+
let apiResp;
|
|
186
|
+
let apiError;
|
|
187
|
+
self.injectTracing(apiAttr, tracingHeaders => {
|
|
188
|
+
Object.keys(tracingHeaders).forEach(key => {
|
|
189
|
+
if (!headers) return;
|
|
190
|
+
if (headers instanceof Headers) {
|
|
191
|
+
tracingHeaders[key] && headers.set(key, tracingHeaders[key]);
|
|
192
|
+
} else {
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
headers[key] = tracingHeaders[key];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
async function fetchFinally() {
|
|
199
|
+
const {
|
|
200
|
+
evaluateApi
|
|
201
|
+
} = self.ctx.getConfig();
|
|
202
|
+
const entry = {
|
|
203
|
+
name: apiAttr.url,
|
|
204
|
+
entryType: _api.ApiType.FETCH,
|
|
205
|
+
duration: (0, _base.getCurrentTime)() - apiAttr.timestamp
|
|
206
|
+
};
|
|
207
|
+
if ((0, _rumCore.isFunction)(evaluateApi)) {
|
|
208
|
+
try {
|
|
209
|
+
const attrs = await evaluateApi?.({
|
|
210
|
+
url: input,
|
|
211
|
+
...init
|
|
212
|
+
}, apiResp, apiError);
|
|
213
|
+
apiAttr = {
|
|
214
|
+
...apiAttr,
|
|
215
|
+
...(0, _api.reviseApiAttr)(attrs)
|
|
216
|
+
};
|
|
217
|
+
} catch (e) {
|
|
218
|
+
_rumCore.logger.warn('api-collector', 'evaluateApi failed for fetch', e);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
self.sendAPI(apiAttr, entry);
|
|
222
|
+
}
|
|
223
|
+
return originFetch.call(globalThis, input, init).then(response => {
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
if (response || (0, _rumCore.isFunction)(response.clone)) {
|
|
226
|
+
apiResp = response.clone();
|
|
227
|
+
const {
|
|
228
|
+
status,
|
|
229
|
+
statusText
|
|
230
|
+
} = apiResp;
|
|
231
|
+
apiAttr.status_code = status;
|
|
232
|
+
apiAttr.message = statusText;
|
|
233
|
+
fetchFinally().then();
|
|
234
|
+
}
|
|
235
|
+
return response;
|
|
236
|
+
}).catch(error => {
|
|
237
|
+
apiError = error;
|
|
238
|
+
apiAttr.message = String(error);
|
|
239
|
+
apiAttr.success = _rumCore.ResourceStatus.Failed;
|
|
240
|
+
fetchFinally().then();
|
|
241
|
+
throw error;
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
sendAPI(apiAttr, entry) {
|
|
246
|
+
const {
|
|
247
|
+
parseResourceName
|
|
248
|
+
} = this.ctx.getConfig();
|
|
249
|
+
const {
|
|
250
|
+
url,
|
|
251
|
+
status_code,
|
|
252
|
+
view
|
|
253
|
+
} = apiAttr;
|
|
254
|
+
const success = (0, _api.getResourceSuccessByCode)(status_code);
|
|
255
|
+
const measures = {
|
|
256
|
+
duration: entry.duration
|
|
257
|
+
};
|
|
258
|
+
const event = {
|
|
259
|
+
event_type: _rumCore.RumEventType.RESOURCE,
|
|
260
|
+
url,
|
|
261
|
+
name: (0, _api.getResourceName)(url || '', parseResourceName),
|
|
262
|
+
success,
|
|
263
|
+
type: entry.initiatorType || entry.entryType,
|
|
264
|
+
...apiAttr,
|
|
265
|
+
timing_data: JSON.stringify(entry),
|
|
266
|
+
// Measure
|
|
267
|
+
...measures,
|
|
268
|
+
view
|
|
269
|
+
};
|
|
270
|
+
this.sendEvent?.(event);
|
|
271
|
+
}
|
|
272
|
+
destroy() {
|
|
273
|
+
this.sendEvent = () => {};
|
|
274
|
+
// 恢复XHR
|
|
275
|
+
const oldXHRProto = XMLHttpRequest.prototype;
|
|
276
|
+
(0, _rumCore.restoreFunction)(oldXHRProto, 'open');
|
|
277
|
+
(0, _rumCore.restoreFunction)(oldXHRProto, 'setRequestHeader');
|
|
278
|
+
(0, _rumCore.restoreFunction)(oldXHRProto, 'send');
|
|
279
|
+
// 恢复 fetch
|
|
280
|
+
if (this.originFetch) {
|
|
281
|
+
globalThis.fetch = this.originFetch;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.default = ApiCollector;
|
|
286
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// import { ICollector, IContext, isArray, RumEvent } from '@arms/rum-core';
|
|
2
|
+
// import { getPerformance } from "../../utils/platform";
|
|
3
|
+
// import { getCurView } from "../../utils/view";
|
|
4
|
+
//
|
|
5
|
+
//
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
// export default class PerfCollector implements ICollector {
|
|
9
|
+
// name = 'perf-collector';
|
|
10
|
+
// ctx: IContext;
|
|
11
|
+
// sendEvent: (payload: RumEvent) => void;
|
|
12
|
+
// perfObserver: any;
|
|
13
|
+
//
|
|
14
|
+
// setup(ctx: IContext, sendEvent: (payload: RumEvent) => void) {
|
|
15
|
+
// const {collectors = {}} = ctx.getConfig();
|
|
16
|
+
// if (collectors.perf === false) {
|
|
17
|
+
// return;
|
|
18
|
+
// }
|
|
19
|
+
// this.ctx = ctx;
|
|
20
|
+
// this.sendEvent = sendEvent;
|
|
21
|
+
// const performance = getPerformance();
|
|
22
|
+
// if (!performance || !performance.createObserver) return;
|
|
23
|
+
// this.perfObserver = performance.createObserver(this.observerHandler)
|
|
24
|
+
// this.perfObserver.observe({entryTypes: ['launch', 'navigation', 'render', 'paint', 'resource']});
|
|
25
|
+
// }
|
|
26
|
+
//
|
|
27
|
+
// observerHandler = (ev) => {
|
|
28
|
+
// const entries = isArray(ev) ? ev : ev.getEntries();
|
|
29
|
+
// const perfData = {
|
|
30
|
+
// view: getCurView(this.ctx)
|
|
31
|
+
// };
|
|
32
|
+
// if (Array.isArray(entries) && entries.length > 0) {
|
|
33
|
+
// for (let i = 0; i < entries.length; i++) {
|
|
34
|
+
// const item = entries[i];
|
|
35
|
+
// if (typeof item.duration === 'number') {
|
|
36
|
+
// switch (item.name) {
|
|
37
|
+
// case 'appLaunch':
|
|
38
|
+
// case 'app-click':
|
|
39
|
+
// perfData['launch'] = item.duration;
|
|
40
|
+
// break;
|
|
41
|
+
// case 'firstPaint':
|
|
42
|
+
// // case 'first-paint':
|
|
43
|
+
// perfData['first-paint'] = item.duration;
|
|
44
|
+
// break;
|
|
45
|
+
// case 'firstRender':
|
|
46
|
+
// perfData['first_render'] = item.duration;
|
|
47
|
+
// break;
|
|
48
|
+
// case 'firstContentfulPaint':
|
|
49
|
+
// // case 'first-contentful-paint':
|
|
50
|
+
// perfData['first_contentful_paint'] = item.duration;
|
|
51
|
+
// break;
|
|
52
|
+
// case 'largestContentfulPaint':
|
|
53
|
+
// // case 'largest-contentful-paint':
|
|
54
|
+
// perfData['largest_contentful_paint'] = item.duration;
|
|
55
|
+
// break;
|
|
56
|
+
// case 'resourceTiming':
|
|
57
|
+
// case 'resource-timing':
|
|
58
|
+
// perfData['timing_data'] = JSON.stringify(item);
|
|
59
|
+
// break;
|
|
60
|
+
// default:
|
|
61
|
+
// break;
|
|
62
|
+
// }
|
|
63
|
+
// }
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
//
|
|
67
|
+
// if (!Object.keys(perfData).length) return;
|
|
68
|
+
// // TODO 处理性能数据
|
|
69
|
+
// // console.warn('perf-collector: ', perfData);
|
|
70
|
+
// };
|
|
71
|
+
//
|
|
72
|
+
// destroy() {
|
|
73
|
+
// if (this.perfObserver) {
|
|
74
|
+
// this.perfObserver.disconnect();
|
|
75
|
+
// }
|
|
76
|
+
// }
|
|
77
|
+
// }
|
|
78
|
+
"use strict";
|
|
79
|
+
//# sourceMappingURL=perf.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _rumCore = require("@arms/rum-core");
|
|
8
|
+
var _view = require("../../utils/view");
|
|
9
|
+
var _crash = require("../../types/crash");
|
|
10
|
+
class PvCollector {
|
|
11
|
+
name = 'pv-collector';
|
|
12
|
+
pageMap = {};
|
|
13
|
+
setup(ctx, sendEvent) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
this.sendEvent = sendEvent;
|
|
16
|
+
(0, _view.addNavigateListener)(this.onChange);
|
|
17
|
+
}
|
|
18
|
+
onChange = route => {
|
|
19
|
+
// {"name":"index","path":"/","key":"index-SB2hXmOGNdpiLskG5sXwj"}
|
|
20
|
+
// {"name":"__root","key":"__root-jPbNqG7-HaM-OUx_FcCUw"}
|
|
21
|
+
const {
|
|
22
|
+
key,
|
|
23
|
+
name,
|
|
24
|
+
path,
|
|
25
|
+
params
|
|
26
|
+
} = route;
|
|
27
|
+
const page = {
|
|
28
|
+
name,
|
|
29
|
+
path,
|
|
30
|
+
id: key,
|
|
31
|
+
params
|
|
32
|
+
};
|
|
33
|
+
if (name === '__root') return;
|
|
34
|
+
this.sendPv(page);
|
|
35
|
+
};
|
|
36
|
+
sendPv = page => {
|
|
37
|
+
const prevPage = this.prevPage;
|
|
38
|
+
const ctx = this.ctx;
|
|
39
|
+
if (page.id === prevPage?.id) {
|
|
40
|
+
// 路由没有发生变化,不发送
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
page.name = this.getViewName(page.path || page.name || '', page);
|
|
44
|
+
if (prevPage && prevPage.id in this.pageMap) {
|
|
45
|
+
delete this.pageMap[prevPage.id];
|
|
46
|
+
ctx.removeView(prevPage.id);
|
|
47
|
+
}
|
|
48
|
+
this.prevPage = page;
|
|
49
|
+
ctx.addView(page);
|
|
50
|
+
|
|
51
|
+
// 路由回退情况下已经上报
|
|
52
|
+
if (page.id in this.pageMap) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.pageMap[page.id] = page;
|
|
56
|
+
this.sendEvent?.({
|
|
57
|
+
event_type: _rumCore.RumEventType.VIEW,
|
|
58
|
+
type: 'pv',
|
|
59
|
+
loading_type: 'initial_load',
|
|
60
|
+
...page
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// 同步当前 view 上下文到原生侧(崩溃报告关联用)
|
|
64
|
+
const sessionId = ctx.session?.getSessionId?.() || '';
|
|
65
|
+
const userId = ctx.session?.getUserId?.() || '';
|
|
66
|
+
ctx.emitter.emit(_crash.CRASH_CONTEXT_EVENT, {
|
|
67
|
+
session_id: sessionId,
|
|
68
|
+
user_id: userId,
|
|
69
|
+
view_id: page.id,
|
|
70
|
+
view_name: page.name
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
getViewName(url, page) {
|
|
74
|
+
let {
|
|
75
|
+
parseViewName
|
|
76
|
+
} = this.ctx?.getConfig();
|
|
77
|
+
let name = page.name;
|
|
78
|
+
if (parseViewName && (0, _rumCore.isFunction)(parseViewName)) {
|
|
79
|
+
name = parseViewName(url, page) || name;
|
|
80
|
+
}
|
|
81
|
+
return name;
|
|
82
|
+
}
|
|
83
|
+
destroy() {
|
|
84
|
+
(0, _view.removeNavigateListener)(this.onChange);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.default = PvCollector;
|
|
88
|
+
//# sourceMappingURL=pv.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Expo config plugin for @arms/rum-reactnative.
|
|
9
|
+
*
|
|
10
|
+
* 在 app.config 中声明后,将 SDK 配置写入 `expoConfig.extra.rumSdk`,运行时可通过
|
|
11
|
+
* `Constants.expoConfig?.extra?.rumSdk` 读取,避免在 JS 入口硬编码 endpoint。
|
|
12
|
+
*
|
|
13
|
+
* app.config.ts 示例:
|
|
14
|
+
* plugins: [['@arms/rum-reactnative', { endpoint: '...', env: 'prod' }]]
|
|
15
|
+
*
|
|
16
|
+
* 仅做配置透传,不注入原生构建设置(podspec / gradle 已由 autolinking 处理)。
|
|
17
|
+
* 零运行时依赖,非 Expo 用户安装本包不会拉入 @expo/* 。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** 本插件触碰到的 expo config 切片,故意放宽以避免对 @expo/config-types 的硬依赖。 */
|
|
21
|
+
|
|
22
|
+
const withRumSdk = (config, props) => {
|
|
23
|
+
const extra = {
|
|
24
|
+
...(config.extra ?? {})
|
|
25
|
+
};
|
|
26
|
+
extra.rumSdk = {
|
|
27
|
+
endpoint: props?.endpoint,
|
|
28
|
+
env: props?.env ?? 'prod',
|
|
29
|
+
version: props?.version
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
...config,
|
|
33
|
+
extra
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
var _default = exports.default = withRumSdk;
|
|
37
|
+
//# sourceMappingURL=expoConfigPlugin.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ArmsRum", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _shell.ArmsRum;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "callMonitored", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _rumCore.callMonitored;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports.default = void 0;
|
|
19
|
+
Object.defineProperty(exports, "logger", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _rumCore.logger;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var _shell = _interopRequireWildcard(require("./shell"));
|
|
26
|
+
var _rumCore = require("@arms/rum-core");
|
|
27
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
28
|
+
var _default = exports.default = _shell.default;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _rumCore = require("@arms/rum-core");
|
|
9
|
+
var _platform = require("./utils/platform");
|
|
10
|
+
var _shell = _interopRequireDefault(require("./shell"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const RumSdkModule = _reactNative.NativeModules.RumSdkModule;
|
|
13
|
+
function initRum(config) {
|
|
14
|
+
_shell.default.init({
|
|
15
|
+
...config,
|
|
16
|
+
beforeReport(bundle) {
|
|
17
|
+
RumSdkModule.sendEvent(JSON.stringify(bundle));
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (RumSdkModule) {
|
|
23
|
+
const eventEmitter = new _reactNative.NativeEventEmitter(RumSdkModule);
|
|
24
|
+
eventEmitter.addListener('rumNativeEvent', config => {
|
|
25
|
+
if ((0, _rumCore.isString)(config)) {
|
|
26
|
+
try {
|
|
27
|
+
config = JSON.parse(config);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.warn('getConfig error', e);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// pid 为可选配置,未提供时使用默认值(格式:react-native@{VERSION})
|
|
34
|
+
// 这确保了即使未在ARMS控制台创建应用,SDK也能正常初始化和上报
|
|
35
|
+
if (!config.pid) {
|
|
36
|
+
config.pid = `react-native@${_platform.VERSION}`;
|
|
37
|
+
}
|
|
38
|
+
// endpoint 为必填配置,未提供时使用本地回环地址作为兜底
|
|
39
|
+
if (!config.endpoint) {
|
|
40
|
+
config.endpoint = `http://127.0.0.1/?version=${_platform.VERSION}`;
|
|
41
|
+
}
|
|
42
|
+
initRum(config);
|
|
43
|
+
});
|
|
44
|
+
RumSdkModule?.getConfig?.();
|
|
45
|
+
}
|
|
46
|
+
var _default = exports.default = _shell.default;
|
|
47
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _base = require("../utils/base");
|
|
8
|
+
var _view = require("../utils/view");
|
|
9
|
+
class DefaultProcessor {
|
|
10
|
+
name = 'default-processor';
|
|
11
|
+
process(ctx) {
|
|
12
|
+
const event = ctx.getRumEvent();
|
|
13
|
+
const view = (0, _view.getCurView)(ctx);
|
|
14
|
+
const session_id = ctx.session.getSessionId();
|
|
15
|
+
const event_id = ctx.session.getEventId();
|
|
16
|
+
const rumEvent = {
|
|
17
|
+
timestamp: (0, _base.getCurrentTime)(),
|
|
18
|
+
session_id,
|
|
19
|
+
event_id,
|
|
20
|
+
view,
|
|
21
|
+
...event
|
|
22
|
+
};
|
|
23
|
+
return rumEvent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = DefaultProcessor;
|
|
27
|
+
//# sourceMappingURL=default-processor.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _rumCore = require("@arms/rum-core");
|
|
8
|
+
var _crash = require("../types/crash");
|
|
9
|
+
var _view = require("../utils/view");
|
|
10
|
+
class SessionProcessor {
|
|
11
|
+
name = 'session-processor';
|
|
12
|
+
lastSessionId = '';
|
|
13
|
+
setup(ctx) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
this.update = (0, _rumCore.debounce)(this.update, _rumCore.ONE_SECOND);
|
|
16
|
+
// 延迟到下一个事件循环执行,确保 collectors 已完成 setup 并注册了
|
|
17
|
+
// CRASH_CONTEXT_EVENT 监听器(rum-core 中 processors.setup() 先于
|
|
18
|
+
// collectors.setup() 执行)。消除 session 创建后 1 秒内的 context
|
|
19
|
+
// 同步窗口,同时避免 emit 事件因无监听器而被丢弃
|
|
20
|
+
setTimeout(() => this.syncCrashContext(), 0);
|
|
21
|
+
// sdk.onTouchStart(this.update)
|
|
22
|
+
}
|
|
23
|
+
update = e => {
|
|
24
|
+
if (e && !e.isTrusted) return;
|
|
25
|
+
this.ctx?.session.updateSession();
|
|
26
|
+
this.syncCrashContext();
|
|
27
|
+
};
|
|
28
|
+
process(ctx) {
|
|
29
|
+
this.update();
|
|
30
|
+
return ctx.getRumEvent();
|
|
31
|
+
}
|
|
32
|
+
syncCrashContext() {
|
|
33
|
+
if (!this.ctx) return;
|
|
34
|
+
const sessionId = this.ctx.session.getSessionId();
|
|
35
|
+
if (sessionId === this.lastSessionId) return;
|
|
36
|
+
this.lastSessionId = sessionId;
|
|
37
|
+
const view = (0, _view.getCurView)(this.ctx);
|
|
38
|
+
this.ctx.emitter.emit(_crash.CRASH_CONTEXT_EVENT, {
|
|
39
|
+
session_id: sessionId,
|
|
40
|
+
user_id: this.ctx.session.getUserId(),
|
|
41
|
+
view_id: view?.id || '',
|
|
42
|
+
view_name: view?.name || ''
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = SessionProcessor;
|
|
47
|
+
//# sourceMappingURL=session-processor.js.map
|