@arms/rum-reactnative 0.1.3-beta.5 → 0.1.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +31 -0
- package/docs/ReactNative SDK/351/205/215/347/275/256/345/217/202/350/200/203.md" +25 -0
- package/docs/SDK /347/211/210/346/234/254/350/257/264/346/230/216.md" +14 -0
- package/ios/RumAppStateRecorder.h +69 -0
- package/ios/RumAppStateRecorder.mm +547 -0
- package/ios/RumCrashReporter.h +32 -0
- package/ios/RumCrashReporter.mm +97 -11
- package/ios/RumSdkReactnative.mm +81 -1
- package/lib/commonjs/NativeRumSdkReactnative.js +1 -54
- package/lib/commonjs/collector/action/index.js +1 -108
- package/lib/commonjs/collector/exception/crash.js +1 -148
- package/lib/commonjs/collector/exception/index.js +1 -238
- package/lib/commonjs/collector/exception/oom.js +1 -0
- package/lib/commonjs/collector/index.js +1 -42
- package/lib/commonjs/collector/resource/api.js +1 -292
- package/lib/commonjs/collector/view/perf.js +1 -79
- package/lib/commonjs/collector/view/pv.js +1 -88
- package/lib/commonjs/expoConfigPlugin.js +1 -37
- package/lib/commonjs/index.js +1 -29
- package/lib/commonjs/plugin.js +1 -47
- package/lib/commonjs/processor/default-processor.js +1 -27
- package/lib/commonjs/processor/session-processor.js +1 -47
- package/lib/commonjs/reporter/index.js +1 -148
- package/lib/commonjs/reporter/monitor-reporter.js +1 -43
- package/lib/commonjs/shell.js +1 -91
- package/lib/commonjs/types/client.js +1 -6
- package/lib/commonjs/types/crash.js +1 -37
- package/lib/commonjs/types/index.js +1 -2
- package/lib/commonjs/types/oom.js +1 -0
- package/lib/commonjs/utils/action.js +1 -305
- package/lib/commonjs/utils/api.js +1 -84
- package/lib/commonjs/utils/base.js +1 -95
- package/lib/commonjs/utils/crash.js +1 -149
- package/lib/commonjs/utils/platform.js +1 -162
- package/lib/commonjs/utils/session.js +1 -158
- package/lib/commonjs/utils/url.js +1 -59
- package/lib/commonjs/utils/view.js +1 -93
- package/lib/module/NativeRumSdkReactnative.js +1 -51
- package/lib/module/collector/action/index.js +1 -103
- package/lib/module/collector/exception/crash.js +1 -143
- package/lib/module/collector/exception/index.js +1 -233
- package/lib/module/collector/exception/oom.js +1 -0
- package/lib/module/collector/index.js +1 -8
- package/lib/module/collector/resource/api.js +1 -287
- package/lib/module/collector/view/perf.js +1 -79
- package/lib/module/collector/view/pv.js +1 -83
- package/lib/module/expoConfigPlugin.js +1 -33
- package/lib/module/index.js +1 -7
- package/lib/module/plugin.js +1 -42
- package/lib/module/processor/default-processor.js +1 -22
- package/lib/module/processor/session-processor.js +1 -42
- package/lib/module/reporter/index.js +1 -144
- package/lib/module/reporter/monitor-reporter.js +1 -38
- package/lib/module/shell.js +1 -84
- package/lib/module/types/client.js +1 -4
- package/lib/module/types/crash.js +1 -33
- package/lib/module/types/index.js +1 -2
- package/lib/module/types/oom.js +1 -0
- package/lib/module/utils/action.js +1 -299
- package/lib/module/utils/api.js +1 -76
- package/lib/module/utils/base.js +1 -90
- package/lib/module/utils/crash.js +1 -144
- package/lib/module/utils/platform.js +1 -150
- package/lib/module/utils/session.js +1 -154
- package/lib/module/utils/url.js +1 -54
- package/lib/module/utils/view.js +1 -88
- package/lib/typescript/commonjs/src/NativeRumSdkReactnative.d.ts +10 -0
- package/lib/typescript/commonjs/src/collector/exception/oom.d.ts +34 -0
- package/lib/typescript/commonjs/src/collector/index.d.ts +1 -0
- package/lib/typescript/commonjs/src/shell.d.ts +1 -1
- package/lib/typescript/commonjs/src/types/client.d.ts +27 -0
- package/lib/typescript/commonjs/src/types/oom.d.ts +58 -0
- package/lib/typescript/commonjs/src/utils/crash.d.ts +13 -0
- package/lib/typescript/module/src/NativeRumSdkReactnative.d.ts +10 -0
- package/lib/typescript/module/src/collector/exception/oom.d.ts +34 -0
- package/lib/typescript/module/src/collector/index.d.ts +1 -0
- package/lib/typescript/module/src/shell.d.ts +1 -1
- package/lib/typescript/module/src/types/client.d.ts +27 -0
- package/lib/typescript/module/src/types/oom.d.ts +58 -0
- package/lib/typescript/module/src/utils/crash.d.ts +13 -0
- package/package.json +1 -2
- package/src/NativeRumSdkReactnative.ts +18 -0
|
@@ -1,287 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { find, generateGUID, generateSpanId, generateTraceId, isString, interceptFunction, restoreFunction, isFunction, makeTracingHeaders, matchList, parseTracingOptions, performDraw, RumEventType, ResourceStatus, urlMatch, logger } from '@arms/rum-core';
|
|
4
|
-
import { getCurrentTime } from "../../utils/base.js";
|
|
5
|
-
import { ApiType, reviseApiAttr, getResourceName, getResourceSuccessByCode } from "../../utils/api.js";
|
|
6
|
-
export default class ApiCollector {
|
|
7
|
-
name = 'api-collector';
|
|
8
|
-
setup(ctx, sendEvent) {
|
|
9
|
-
const collectors = ctx.getConfig().collectors || {};
|
|
10
|
-
if (collectors.api === false) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
this.sendEvent = sendEvent;
|
|
14
|
-
this.ctx = ctx;
|
|
15
|
-
// this.perfObserver();
|
|
16
|
-
this.hackXhr();
|
|
17
|
-
// this.hackFetch();
|
|
18
|
-
}
|
|
19
|
-
injectTracing(apiAttr, inject) {
|
|
20
|
-
const {
|
|
21
|
-
tracing = false,
|
|
22
|
-
pid,
|
|
23
|
-
version = '1.0.0'
|
|
24
|
-
} = this.ctx.getConfig();
|
|
25
|
-
const {
|
|
26
|
-
enable,
|
|
27
|
-
sample,
|
|
28
|
-
propagatorTypes,
|
|
29
|
-
allowedUrls,
|
|
30
|
-
tracestate,
|
|
31
|
-
baggage = false
|
|
32
|
-
} = parseTracingOptions(tracing);
|
|
33
|
-
if (!enable) return;
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
const resolvedTraceOption = find(allowedUrls, item => matchList([item.match], apiAttr.url || ''));
|
|
36
|
-
if (!resolvedTraceOption) return;
|
|
37
|
-
let pTypes = resolvedTraceOption.propagatorTypes;
|
|
38
|
-
if (pTypes && pTypes.length === 0) {
|
|
39
|
-
pTypes = propagatorTypes;
|
|
40
|
-
}
|
|
41
|
-
// skywalking
|
|
42
|
-
let isSw8 = false;
|
|
43
|
-
if (pTypes && pTypes.indexOf('sw8') > -1) {
|
|
44
|
-
pTypes = ['sw8'];
|
|
45
|
-
isSw8 = true;
|
|
46
|
-
}
|
|
47
|
-
const session = this.ctx.session;
|
|
48
|
-
const traceId = isSw8 ? generateGUID() : generateTraceId();
|
|
49
|
-
const spanId = isSw8 ? generateGUID() : generateSpanId();
|
|
50
|
-
const sampled = performDraw(sample);
|
|
51
|
-
const uid = session.getUserId();
|
|
52
|
-
const sid = session.getSessionId();
|
|
53
|
-
const traceContext = tracestate ? `rum=v2&browser&${pid}&${sid}&${uid}` : undefined;
|
|
54
|
-
const baggageContext = baggage ? `rum=v2,appType=browser,pid=${pid},sid=${sid},uid=${uid}` : undefined;
|
|
55
|
-
const tracingHeaders = makeTracingHeaders(traceId, spanId, sampled, pTypes || [], {
|
|
56
|
-
tracestate: traceContext,
|
|
57
|
-
baggage: baggageContext,
|
|
58
|
-
appId: pid,
|
|
59
|
-
appVersion: version,
|
|
60
|
-
viewName: apiAttr.view?.name
|
|
61
|
-
// host: location.host
|
|
62
|
-
});
|
|
63
|
-
if (sampled) {
|
|
64
|
-
apiAttr.trace_id = traceId;
|
|
65
|
-
apiAttr.trace_data = JSON.stringify({
|
|
66
|
-
spanId,
|
|
67
|
-
sample,
|
|
68
|
-
sampled,
|
|
69
|
-
headers: tracingHeaders
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
inject(tracingHeaders);
|
|
73
|
-
}
|
|
74
|
-
hackXhr() {
|
|
75
|
-
const oldXHRProto = XMLHttpRequest.prototype;
|
|
76
|
-
const that = this;
|
|
77
|
-
interceptFunction(oldXHRProto, 'open', function (method, url, async, user, password) {
|
|
78
|
-
const filters = that.ctx.getConfig().filters || {};
|
|
79
|
-
const urlStr = String(url);
|
|
80
|
-
const methodStr = method.toUpperCase();
|
|
81
|
-
// chrome 对 URL 的最大长度为 8182 个字符
|
|
82
|
-
if (urlMatch(urlStr, filters.resource) || methodStr === 'HEAD' || urlStr.length > 8182) return;
|
|
83
|
-
this.apiCache = {
|
|
84
|
-
type: ApiType.XHR,
|
|
85
|
-
method,
|
|
86
|
-
url,
|
|
87
|
-
async,
|
|
88
|
-
user,
|
|
89
|
-
password,
|
|
90
|
-
headers: {}
|
|
91
|
-
};
|
|
92
|
-
const baseRumEvent = that.ctx.session.getBaseEvent();
|
|
93
|
-
this.apiAttr = {
|
|
94
|
-
...baseRumEvent,
|
|
95
|
-
url: urlStr,
|
|
96
|
-
method: methodStr
|
|
97
|
-
};
|
|
98
|
-
}, true);
|
|
99
|
-
interceptFunction(oldXHRProto, 'setRequestHeader', function (header, value) {
|
|
100
|
-
if (!this.apiCache) return;
|
|
101
|
-
this.apiCache.headers = {
|
|
102
|
-
...this.apiCache.headers,
|
|
103
|
-
[header]: value
|
|
104
|
-
};
|
|
105
|
-
}, true);
|
|
106
|
-
interceptFunction(oldXHRProto, 'send', function (body) {
|
|
107
|
-
if (!this.apiAttr || !this.apiCache) return;
|
|
108
|
-
let apiAttr = this.apiAttr;
|
|
109
|
-
this.apiCache.data = body;
|
|
110
|
-
that.injectTracing(this.apiAttr, tracingHeaders => {
|
|
111
|
-
Object.keys(tracingHeaders).forEach(key => {
|
|
112
|
-
tracingHeaders[key] && this.setRequestHeader(key, tracingHeaders[key]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
this.addEventListener('loadend', async () => {
|
|
116
|
-
const {
|
|
117
|
-
status,
|
|
118
|
-
statusText,
|
|
119
|
-
response
|
|
120
|
-
} = this;
|
|
121
|
-
const {
|
|
122
|
-
evaluateApi
|
|
123
|
-
} = that.ctx.getConfig();
|
|
124
|
-
if (!this.apiAttr) return;
|
|
125
|
-
apiAttr.status_code = status;
|
|
126
|
-
apiAttr.message = statusText;
|
|
127
|
-
const entry = {
|
|
128
|
-
name: this.apiAttr.url,
|
|
129
|
-
entryType: ApiType.XHR,
|
|
130
|
-
duration: getCurrentTime() - apiAttr.timestamp
|
|
131
|
-
};
|
|
132
|
-
if (isFunction(evaluateApi)) {
|
|
133
|
-
try {
|
|
134
|
-
let error;
|
|
135
|
-
if (apiAttr.success === ResourceStatus.Failed) {
|
|
136
|
-
error = new Error(ApiType.XHR + ' error');
|
|
137
|
-
}
|
|
138
|
-
const attrs = await evaluateApi?.(this.apiCache, response, error, this);
|
|
139
|
-
this.apiAttr = apiAttr = {
|
|
140
|
-
...apiAttr,
|
|
141
|
-
...reviseApiAttr(attrs)
|
|
142
|
-
};
|
|
143
|
-
} catch (e) {
|
|
144
|
-
logger.warn('api-collector', 'evaluateApi failed for XHR', e);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
that.sendAPI(apiAttr, entry);
|
|
148
|
-
});
|
|
149
|
-
this.addEventListener('error', () => {
|
|
150
|
-
this.apiAttr && (this.apiAttr.success = ResourceStatus.Failed);
|
|
151
|
-
});
|
|
152
|
-
this.addEventListener('abort', () => {
|
|
153
|
-
if (this.apiAttr) {
|
|
154
|
-
this.apiAttr.success = ResourceStatus.Failed;
|
|
155
|
-
this.apiAttr.message = 'abort';
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}, true);
|
|
159
|
-
}
|
|
160
|
-
hackFetch() {
|
|
161
|
-
const that = this;
|
|
162
|
-
const originFetch = this.originFetch = globalThis.fetch;
|
|
163
|
-
const filters = this.ctx.getConfig().filters || {};
|
|
164
|
-
globalThis.fetch = function (input, init = {}) {
|
|
165
|
-
const isReq = input instanceof Request;
|
|
166
|
-
const urlStr = isReq ? input.url : isString(input) ? input : input.toString();
|
|
167
|
-
let method = init.method;
|
|
168
|
-
let headers = init.headers;
|
|
169
|
-
if (isReq) {
|
|
170
|
-
!method && (method = input.method);
|
|
171
|
-
!headers && (headers = input.headers);
|
|
172
|
-
}
|
|
173
|
-
method = method ? method.toUpperCase() : 'GET';
|
|
174
|
-
if (!headers) {
|
|
175
|
-
init.headers = headers = new Headers();
|
|
176
|
-
}
|
|
177
|
-
if (urlMatch(urlStr, filters.resource) || method === 'HEAD' || init?.mode === 'no-cors' || urlStr.length > 8182) {
|
|
178
|
-
return originFetch.call(global, input, init);
|
|
179
|
-
}
|
|
180
|
-
const baseRumEvent = that.ctx.session.getBaseEvent();
|
|
181
|
-
let apiAttr = {
|
|
182
|
-
...baseRumEvent,
|
|
183
|
-
url: urlStr,
|
|
184
|
-
type: ApiType.FETCH,
|
|
185
|
-
method
|
|
186
|
-
};
|
|
187
|
-
let apiResp;
|
|
188
|
-
let apiError;
|
|
189
|
-
that.injectTracing(apiAttr, tracingHeaders => {
|
|
190
|
-
Object.keys(tracingHeaders).forEach(key => {
|
|
191
|
-
if (!headers) return;
|
|
192
|
-
if (headers instanceof Headers) {
|
|
193
|
-
tracingHeaders[key] && headers.set(key, tracingHeaders[key]);
|
|
194
|
-
} else {
|
|
195
|
-
// @ts-ignore
|
|
196
|
-
headers[key] = tracingHeaders[key];
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
async function fetchFinally() {
|
|
201
|
-
const {
|
|
202
|
-
evaluateApi
|
|
203
|
-
} = that.ctx.getConfig();
|
|
204
|
-
const entry = {
|
|
205
|
-
name: apiAttr.url,
|
|
206
|
-
entryType: ApiType.FETCH,
|
|
207
|
-
duration: getCurrentTime() - apiAttr.timestamp
|
|
208
|
-
};
|
|
209
|
-
if (isFunction(evaluateApi)) {
|
|
210
|
-
try {
|
|
211
|
-
const attrs = await evaluateApi?.({
|
|
212
|
-
url: input,
|
|
213
|
-
...init
|
|
214
|
-
}, apiResp, apiError);
|
|
215
|
-
apiAttr = {
|
|
216
|
-
...apiAttr,
|
|
217
|
-
...reviseApiAttr(attrs)
|
|
218
|
-
};
|
|
219
|
-
} catch (e) {
|
|
220
|
-
logger.warn('api-collector', 'evaluateApi failed for fetch', e);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
that.sendAPI(apiAttr, entry);
|
|
224
|
-
}
|
|
225
|
-
return originFetch.call(globalThis, input, init).then(response => {
|
|
226
|
-
// @ts-ignore
|
|
227
|
-
if (response || isFunction(response.clone)) {
|
|
228
|
-
apiResp = response.clone();
|
|
229
|
-
const {
|
|
230
|
-
status,
|
|
231
|
-
statusText
|
|
232
|
-
} = apiResp;
|
|
233
|
-
apiAttr.status_code = status;
|
|
234
|
-
apiAttr.message = statusText;
|
|
235
|
-
fetchFinally().then();
|
|
236
|
-
}
|
|
237
|
-
return response;
|
|
238
|
-
}).catch(error => {
|
|
239
|
-
apiError = error;
|
|
240
|
-
apiAttr.message = String(error);
|
|
241
|
-
apiAttr.success = ResourceStatus.Failed;
|
|
242
|
-
fetchFinally().then();
|
|
243
|
-
throw error;
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
sendAPI(apiAttr, entry) {
|
|
248
|
-
const {
|
|
249
|
-
parseResourceName
|
|
250
|
-
} = this.ctx.getConfig();
|
|
251
|
-
const {
|
|
252
|
-
url,
|
|
253
|
-
status_code,
|
|
254
|
-
view
|
|
255
|
-
} = apiAttr;
|
|
256
|
-
const success = getResourceSuccessByCode(status_code);
|
|
257
|
-
const measures = {
|
|
258
|
-
duration: entry.duration
|
|
259
|
-
};
|
|
260
|
-
const event = {
|
|
261
|
-
event_type: RumEventType.RESOURCE,
|
|
262
|
-
url,
|
|
263
|
-
name: getResourceName(url || '', parseResourceName),
|
|
264
|
-
success,
|
|
265
|
-
type: entry.initiatorType || entry.entryType,
|
|
266
|
-
...apiAttr,
|
|
267
|
-
timing_data: JSON.stringify(entry),
|
|
268
|
-
// Measure
|
|
269
|
-
...measures,
|
|
270
|
-
view
|
|
271
|
-
};
|
|
272
|
-
this.sendEvent?.(event);
|
|
273
|
-
}
|
|
274
|
-
destroy() {
|
|
275
|
-
this.sendEvent = () => {};
|
|
276
|
-
// 恢复XHR
|
|
277
|
-
const oldXHRProto = XMLHttpRequest.prototype;
|
|
278
|
-
restoreFunction(oldXHRProto, 'open');
|
|
279
|
-
restoreFunction(oldXHRProto, 'setRequestHeader');
|
|
280
|
-
restoreFunction(oldXHRProto, 'send');
|
|
281
|
-
// 恢复 fetch
|
|
282
|
-
if (this.originFetch) {
|
|
283
|
-
globalThis.fetch = this.originFetch;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
//# sourceMappingURL=api.js.map
|
|
1
|
+
"use strict";import{find,generateGUID,generateSpanId,generateTraceId,isString,interceptFunction,restoreFunction,isFunction,makeTracingHeaders,matchList,parseTracingOptions,performDraw,RumEventType,ResourceStatus,urlMatch,logger}from"@arms/rum-core";import{getCurrentTime}from"../../utils/base.js";import{ApiType,reviseApiAttr,getResourceName,getResourceSuccessByCode}from"../../utils/api.js";export default class ApiCollector{name="api-collector";setup(e,t){!1!==(e.getConfig().collectors||{}).api&&(this.sendEvent=t,this.ctx=e,this.hackXhr())}injectTracing(e,t){const{tracing:s=!1,pid:i,version:r="1.0.0"}=this.ctx.getConfig(),{enable:a,sample:n,propagatorTypes:c,allowedUrls:o,tracestate:p,baggage:u=!1}=parseTracingOptions(s);if(!a)return;const h=find(o,t=>matchList([t.match],e.url||""));if(!h)return;let d=h.propagatorTypes;d&&0===d.length&&(d=c);let g=!1;d&&d.indexOf("sw8")>-1&&(d=["sw8"],g=!0);const l=this.ctx.session,m=g?generateGUID():generateTraceId(),f=g?generateGUID():generateSpanId(),y=performDraw(n),T=l.getUserId(),A=l.getSessionId(),v=makeTracingHeaders(m,f,y,d||[],{tracestate:p?`rum=v2&browser&${i}&${A}&${T}`:void 0,baggage:u?`rum=v2,appType=browser,pid=${i},sid=${A},uid=${T}`:void 0,appId:i,appVersion:r,viewName:e.view?.name});y&&(e.trace_id=m,e.trace_data=JSON.stringify({spanId:f,sample:n,sampled:y,headers:v})),t(v)}hackXhr(){const e=XMLHttpRequest.prototype,t=this;interceptFunction(e,"open",function(e,s,i,r,a){const n=t.ctx.getConfig().filters||{},c=String(s),o=e.toUpperCase();if(urlMatch(c,n.resource)||"HEAD"===o||c.length>8182)return;this.apiCache={type:ApiType.XHR,method:e,url:s,async:i,user:r,password:a,headers:{}};const p=t.ctx.session.getBaseEvent();this.apiAttr={...p,url:c,method:o}},!0),interceptFunction(e,"setRequestHeader",function(e,t){this.apiCache&&(this.apiCache.headers={...this.apiCache.headers,[e]:t})},!0),interceptFunction(e,"send",function(e){if(!this.apiAttr||!this.apiCache)return;let s=this.apiAttr;this.apiCache.data=e,t.injectTracing(this.apiAttr,e=>{Object.keys(e).forEach(t=>{e[t]&&this.setRequestHeader(t,e[t])})}),this.addEventListener("loadend",async()=>{const{status:e,statusText:i,response:r}=this,{evaluateApi:a}=t.ctx.getConfig();if(!this.apiAttr)return;s.status_code=e,s.message=i;const n={name:this.apiAttr.url,entryType:ApiType.XHR,duration:getCurrentTime()-s.timestamp};if(isFunction(a))try{let e;s.success===ResourceStatus.Failed&&(e=new Error(ApiType.XHR+" error"));const t=await(a?.(this.apiCache,r,e,this));this.apiAttr=s={...s,...reviseApiAttr(t)}}catch(e){logger.warn("api-collector","evaluateApi failed for XHR",e)}t.sendAPI(s,n)}),this.addEventListener("error",()=>{this.apiAttr&&(this.apiAttr.success=ResourceStatus.Failed)}),this.addEventListener("abort",()=>{this.apiAttr&&(this.apiAttr.success=ResourceStatus.Failed,this.apiAttr.message="abort")})},!0)}hackFetch(){const e=this,t=this.originFetch=globalThis.fetch,s=this.ctx.getConfig().filters||{};globalThis.fetch=function(i,r={}){const a=i instanceof Request,n=a?i.url:isString(i)?i:i.toString();let c=r.method,o=r.headers;if(a&&(!c&&(c=i.method),!o&&(o=i.headers)),c=c?c.toUpperCase():"GET",o||(r.headers=o=new Headers),urlMatch(n,s.resource)||"HEAD"===c||"no-cors"===r?.mode||n.length>8182)return t.call(global,i,r);let p,u,h={...e.ctx.session.getBaseEvent(),url:n,type:ApiType.FETCH,method:c};async function d(){const{evaluateApi:t}=e.ctx.getConfig(),s={name:h.url,entryType:ApiType.FETCH,duration:getCurrentTime()-h.timestamp};if(isFunction(t))try{const e=await(t?.({url:i,...r},p,u));h={...h,...reviseApiAttr(e)}}catch(e){logger.warn("api-collector","evaluateApi failed for fetch",e)}e.sendAPI(h,s)}return e.injectTracing(h,e=>{Object.keys(e).forEach(t=>{o&&(o instanceof Headers?e[t]&&o.set(t,e[t]):o[t]=e[t])})}),t.call(globalThis,i,r).then(e=>{if(e||isFunction(e.clone)){p=e.clone();const{status:t,statusText:s}=p;h.status_code=t,h.message=s,d().then()}return e}).catch(e=>{throw u=e,h.message=String(e),h.success=ResourceStatus.Failed,d().then(),e})}}sendAPI(e,t){const{parseResourceName:s}=this.ctx.getConfig(),{url:i,status_code:r,view:a}=e,n=getResourceSuccessByCode(r),c={duration:t.duration},o={event_type:RumEventType.RESOURCE,url:i,name:getResourceName(i||"",s),success:n,type:t.initiatorType||t.entryType,...e,timing_data:JSON.stringify(t),...c,view:a};this.sendEvent?.(o)}destroy(){this.sendEvent=()=>{};const e=XMLHttpRequest.prototype;restoreFunction(e,"open"),restoreFunction(e,"setRequestHeader"),restoreFunction(e,"send"),this.originFetch&&(globalThis.fetch=this.originFetch)}}
|
|
@@ -1,79 +1 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
"use strict";
|
|
@@ -1,83 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { isFunction, RumEventType } from '@arms/rum-core';
|
|
4
|
-
import { addNavigateListener, removeNavigateListener } from "../../utils/view.js";
|
|
5
|
-
import { CRASH_CONTEXT_EVENT } from "../../types/crash.js";
|
|
6
|
-
export default class PvCollector {
|
|
7
|
-
name = 'pv-collector';
|
|
8
|
-
pageMap = {};
|
|
9
|
-
setup(ctx, sendEvent) {
|
|
10
|
-
this.ctx = ctx;
|
|
11
|
-
this.sendEvent = sendEvent;
|
|
12
|
-
addNavigateListener(this.onChange);
|
|
13
|
-
}
|
|
14
|
-
onChange = route => {
|
|
15
|
-
// {"name":"index","path":"/","key":"index-SB2hXmOGNdpiLskG5sXwj"}
|
|
16
|
-
// {"name":"__root","key":"__root-jPbNqG7-HaM-OUx_FcCUw"}
|
|
17
|
-
const {
|
|
18
|
-
key,
|
|
19
|
-
name,
|
|
20
|
-
path,
|
|
21
|
-
params
|
|
22
|
-
} = route;
|
|
23
|
-
const page = {
|
|
24
|
-
name,
|
|
25
|
-
path,
|
|
26
|
-
id: key,
|
|
27
|
-
params
|
|
28
|
-
};
|
|
29
|
-
if (name === '__root') return;
|
|
30
|
-
this.sendPv(page);
|
|
31
|
-
};
|
|
32
|
-
sendPv = page => {
|
|
33
|
-
const prevPage = this.prevPage;
|
|
34
|
-
const ctx = this.ctx;
|
|
35
|
-
if (page.id === prevPage?.id) {
|
|
36
|
-
// 路由没有发生变化,不发送
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
page.name = this.getViewName(page.path || page.name || '', page);
|
|
40
|
-
if (prevPage && prevPage.id in this.pageMap) {
|
|
41
|
-
delete this.pageMap[prevPage.id];
|
|
42
|
-
ctx.removeView(prevPage.id);
|
|
43
|
-
}
|
|
44
|
-
this.prevPage = page;
|
|
45
|
-
ctx.addView(page);
|
|
46
|
-
|
|
47
|
-
// 路由回退情况下已经上报
|
|
48
|
-
if (page.id in this.pageMap) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.pageMap[page.id] = page;
|
|
52
|
-
this.sendEvent?.({
|
|
53
|
-
event_type: RumEventType.VIEW,
|
|
54
|
-
type: 'pv',
|
|
55
|
-
loading_type: 'initial_load',
|
|
56
|
-
...page
|
|
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
|
-
});
|
|
68
|
-
};
|
|
69
|
-
getViewName(url, page) {
|
|
70
|
-
let {
|
|
71
|
-
parseViewName
|
|
72
|
-
} = this.ctx?.getConfig();
|
|
73
|
-
let name = page.name;
|
|
74
|
-
if (parseViewName && isFunction(parseViewName)) {
|
|
75
|
-
name = parseViewName(url, page) || name;
|
|
76
|
-
}
|
|
77
|
-
return name;
|
|
78
|
-
}
|
|
79
|
-
destroy() {
|
|
80
|
-
removeNavigateListener(this.onChange);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=pv.js.map
|
|
1
|
+
"use strict";import{isFunction,RumEventType}from"@arms/rum-core";import{addNavigateListener,removeNavigateListener}from"../../utils/view.js";import{CRASH_CONTEXT_EVENT}from"../../types/crash.js";export default class PvCollector{name="pv-collector";pageMap={};setup(e,t){this.ctx=e,this.sendEvent=t,addNavigateListener(this.onChange)}onChange=e=>{const{key:t,name:i,path:s,params:a}=e,n={name:i,path:s,id:t,params:a};"__root"!==i&&this.sendPv(n)};sendPv=e=>{const t=this.prevPage,i=this.ctx;if(e.id===t?.id)return;if(e.name=this.getViewName(e.path||e.name||"",e),t&&t.id in this.pageMap&&(delete this.pageMap[t.id],i.removeView(t.id)),this.prevPage=e,i.addView(e),e.id in this.pageMap)return;this.pageMap[e.id]=e,this.sendEvent?.({event_type:RumEventType.VIEW,type:"pv",loading_type:"initial_load",...e});const s=i.session?.getSessionId?.()||"",a=i.session?.getUserId?.()||"";i.emitter.emit(CRASH_CONTEXT_EVENT,{session_id:s,user_id:a,view_id:e.id,view_name:e.name})};getViewName(e,t){let{parseViewName:i}=this.ctx?.getConfig(),s=t.name;return i&&isFunction(i)&&(s=i(e,t)||s),s}destroy(){removeNavigateListener(this.onChange)}}
|
|
@@ -1,33 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";const withRumSdk=(t,e)=>{const n={...t.extra??{}};return n.rumSdk={endpoint:e?.endpoint,env:e?.env??"prod",version:e?.version},{...t,extra:n}};export default withRumSdk;
|
package/lib/module/index.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import armsRum, { ArmsRum } from "./shell.js";
|
|
4
|
-
export { logger, callMonitored } from '@arms/rum-core';
|
|
5
|
-
export { ArmsRum };
|
|
6
|
-
export default armsRum;
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";import armsRum,{ArmsRum}from"./shell.js";export{logger,callMonitored}from"@arms/rum-core";export{ArmsRum};export default armsRum;
|
package/lib/module/plugin.js
CHANGED
|
@@ -1,42 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
4
|
-
import { isString } from '@arms/rum-core';
|
|
5
|
-
import { VERSION } from "./utils/platform.js";
|
|
6
|
-
import armsRum from "./shell.js";
|
|
7
|
-
const RumSdkModule = NativeModules.RumSdkModule;
|
|
8
|
-
function initRum(config) {
|
|
9
|
-
armsRum.init({
|
|
10
|
-
...config,
|
|
11
|
-
beforeReport(bundle) {
|
|
12
|
-
RumSdkModule.sendEvent(JSON.stringify(bundle));
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (RumSdkModule) {
|
|
18
|
-
const eventEmitter = new NativeEventEmitter(RumSdkModule);
|
|
19
|
-
eventEmitter.addListener('rumNativeEvent', config => {
|
|
20
|
-
if (isString(config)) {
|
|
21
|
-
try {
|
|
22
|
-
config = JSON.parse(config);
|
|
23
|
-
} catch (e) {
|
|
24
|
-
console.warn('getConfig error', e);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// pid 为可选配置,未提供时使用默认值(格式:react-native@{VERSION})
|
|
29
|
-
// 这确保了即使未在ARMS控制台创建应用,SDK也能正常初始化和上报
|
|
30
|
-
if (!config.pid) {
|
|
31
|
-
config.pid = `react-native@${VERSION}`;
|
|
32
|
-
}
|
|
33
|
-
// endpoint 为必填配置,未提供时使用本地回环地址作为兜底
|
|
34
|
-
if (!config.endpoint) {
|
|
35
|
-
config.endpoint = `http://127.0.0.1/?version=${VERSION}`;
|
|
36
|
-
}
|
|
37
|
-
initRum(config);
|
|
38
|
-
});
|
|
39
|
-
RumSdkModule?.getConfig?.();
|
|
40
|
-
}
|
|
41
|
-
export default armsRum;
|
|
42
|
-
//# sourceMappingURL=plugin.js.map
|
|
1
|
+
"use strict";import{NativeModules,NativeEventEmitter}from"react-native";import{isString}from"@arms/rum-core";import{VERSION}from"./utils/platform.js";import armsRum from"./shell.js";const RumSdkModule=NativeModules.RumSdkModule;function initRum(t){armsRum.init({...t,beforeReport:t=>(RumSdkModule.sendEvent(JSON.stringify(t)),null)})}if(RumSdkModule){new NativeEventEmitter(RumSdkModule).addListener("rumNativeEvent",t=>{if(isString(t))try{t=JSON.parse(t)}catch(t){return void console.warn("getConfig error",t)}t.pid||(t.pid=`react-native@${VERSION}`),t.endpoint||(t.endpoint=`http://127.0.0.1/?version=${VERSION}`),initRum(t)}),RumSdkModule?.getConfig?.()}export default armsRum;
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { getCurrentTime } from "../utils/base.js";
|
|
4
|
-
import { getCurView } from "../utils/view.js";
|
|
5
|
-
export default class DefaultProcessor {
|
|
6
|
-
name = 'default-processor';
|
|
7
|
-
process(ctx) {
|
|
8
|
-
const event = ctx.getRumEvent();
|
|
9
|
-
const view = getCurView(ctx);
|
|
10
|
-
const session_id = ctx.session.getSessionId();
|
|
11
|
-
const event_id = ctx.session.getEventId();
|
|
12
|
-
const rumEvent = {
|
|
13
|
-
timestamp: getCurrentTime(),
|
|
14
|
-
session_id,
|
|
15
|
-
event_id,
|
|
16
|
-
view,
|
|
17
|
-
...event
|
|
18
|
-
};
|
|
19
|
-
return rumEvent;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=default-processor.js.map
|
|
1
|
+
"use strict";import{getCurrentTime}from"../utils/base.js";import{getCurView}from"../utils/view.js";export default class DefaultProcessor{name="default-processor";process(e){const s=e.getRumEvent(),t=getCurView(e),r=e.session.getSessionId(),i=e.session.getEventId();return{timestamp:getCurrentTime(),session_id:r,event_id:i,view:t,...s}}}
|
|
@@ -1,42 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
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";
|
|
6
|
-
export default class SessionProcessor {
|
|
7
|
-
name = 'session-processor';
|
|
8
|
-
lastSessionId = '';
|
|
9
|
-
setup(ctx) {
|
|
10
|
-
this.ctx = ctx;
|
|
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);
|
|
17
|
-
// sdk.onTouchStart(this.update)
|
|
18
|
-
}
|
|
19
|
-
update = e => {
|
|
20
|
-
if (e && !e.isTrusted) return;
|
|
21
|
-
this.ctx?.session.updateSession();
|
|
22
|
-
this.syncCrashContext();
|
|
23
|
-
};
|
|
24
|
-
process(ctx) {
|
|
25
|
-
this.update();
|
|
26
|
-
return ctx.getRumEvent();
|
|
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
|
-
}
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=session-processor.js.map
|
|
1
|
+
"use strict";import{debounce,ONE_SECOND}from"@arms/rum-core";import{CRASH_CONTEXT_EVENT}from"../types/crash.js";import{getCurView}from"../utils/view.js";export default class SessionProcessor{name="session-processor";lastSessionId="";setup(s){this.ctx=s,this.update=debounce(this.update,ONE_SECOND),setTimeout(()=>this.syncCrashContext(),0)}update=s=>{s&&!s.isTrusted||(this.ctx?.session.updateSession(),this.syncCrashContext())};process(s){return this.update(),s.getRumEvent()}syncCrashContext(){if(!this.ctx)return;const s=this.ctx.session.getSessionId();if(s===this.lastSessionId)return;this.lastSessionId=s;const t=getCurView(this.ctx);this.ctx.emitter.emit(CRASH_CONTEXT_EVENT,{session_id:s,user_id:this.ctx.session.getUserId(),view_id:t?.id||"",view_name:t?.name||""})}}
|