@arms/rum-reactnative 0.0.2-bate.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/LICENSE +20 -0
- package/README.md +37 -0
- package/RumSdkReactnative.podspec +21 -0
- package/android/build.gradle +77 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +23 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +33 -0
- package/ios/RumSdkReactnative.h +5 -0
- package/ios/RumSdkReactnative.mm +18 -0
- package/lib/module/collector/action/index.js +68 -0
- package/lib/module/collector/action/index.js.map +1 -0
- package/lib/module/collector/exception/index.js +135 -0
- package/lib/module/collector/exception/index.js.map +1 -0
- package/lib/module/collector/resource/api.js +281 -0
- package/lib/module/collector/resource/api.js.map +1 -0
- package/lib/module/collector/view/perf.js +79 -0
- package/lib/module/collector/view/perf.js.map +1 -0
- package/lib/module/collector/view/pv.js +72 -0
- package/lib/module/collector/view/pv.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/plugin.js +39 -0
- package/lib/module/plugin.js.map +1 -0
- package/lib/module/processor/default-processor.js +22 -0
- package/lib/module/processor/default-processor.js.map +1 -0
- package/lib/module/processor/session-processor.js +20 -0
- package/lib/module/processor/session-processor.js.map +1 -0
- package/lib/module/reporter/index.js +56 -0
- package/lib/module/reporter/index.js.map +1 -0
- package/lib/module/shell.js +63 -0
- package/lib/module/shell.js.map +1 -0
- package/lib/module/types/client.js +4 -0
- package/lib/module/types/client.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/api.js +75 -0
- package/lib/module/utils/api.js.map +1 -0
- package/lib/module/utils/base.js +90 -0
- package/lib/module/utils/base.js.map +1 -0
- package/lib/module/utils/platform.js +95 -0
- package/lib/module/utils/platform.js.map +1 -0
- package/lib/module/utils/session.js +135 -0
- package/lib/module/utils/session.js.map +1 -0
- package/lib/module/utils/url.js +54 -0
- package/lib/module/utils/url.js.map +1 -0
- package/lib/module/utils/view.js +87 -0
- package/lib/module/utils/view.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/collector/action/index.d.ts +15 -0
- package/lib/typescript/src/collector/action/index.d.ts.map +1 -0
- package/lib/typescript/src/collector/exception/index.d.ts +25 -0
- package/lib/typescript/src/collector/exception/index.d.ts.map +1 -0
- package/lib/typescript/src/collector/resource/api.d.ts +21 -0
- package/lib/typescript/src/collector/resource/api.d.ts.map +1 -0
- package/lib/typescript/src/collector/view/perf.d.ts +1 -0
- package/lib/typescript/src/collector/view/perf.d.ts.map +1 -0
- package/lib/typescript/src/collector/view/pv.d.ts +16 -0
- package/lib/typescript/src/collector/view/pv.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/plugin.d.ts +3 -0
- package/lib/typescript/src/plugin.d.ts.map +1 -0
- package/lib/typescript/src/processor/default-processor.d.ts +6 -0
- package/lib/typescript/src/processor/default-processor.d.ts.map +1 -0
- package/lib/typescript/src/processor/session-processor.d.ts +9 -0
- package/lib/typescript/src/processor/session-processor.d.ts.map +1 -0
- package/lib/typescript/src/reporter/index.d.ts +16 -0
- package/lib/typescript/src/reporter/index.d.ts.map +1 -0
- package/lib/typescript/src/shell.d.ts +29 -0
- package/lib/typescript/src/shell.d.ts.map +1 -0
- package/lib/typescript/src/types/client.d.ts +27 -0
- package/lib/typescript/src/types/client.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +118 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/api.d.ts +59 -0
- package/lib/typescript/src/utils/api.d.ts.map +1 -0
- package/lib/typescript/src/utils/base.d.ts +8 -0
- package/lib/typescript/src/utils/base.d.ts.map +1 -0
- package/lib/typescript/src/utils/platform.d.ts +15 -0
- package/lib/typescript/src/utils/platform.d.ts.map +1 -0
- package/lib/typescript/src/utils/session.d.ts +37 -0
- package/lib/typescript/src/utils/session.d.ts.map +1 -0
- package/lib/typescript/src/utils/url.d.ts +17 -0
- package/lib/typescript/src/utils/url.d.ts.map +1 -0
- package/lib/typescript/src/utils/view.d.ts +13 -0
- package/lib/typescript/src/utils/view.d.ts.map +1 -0
- package/package.json +158 -0
- package/src/collector/action/index.ts +67 -0
- package/src/collector/exception/index.ts +158 -0
- package/src/collector/resource/api.ts +379 -0
- package/src/collector/view/perf.ts +77 -0
- package/src/collector/view/pv.ts +73 -0
- package/src/index.ts +4 -0
- package/src/plugin.ts +41 -0
- package/src/processor/default-processor.ts +22 -0
- package/src/processor/session-processor.ts +23 -0
- package/src/reporter/index.ts +67 -0
- package/src/shell.ts +81 -0
- package/src/types/client.ts +32 -0
- package/src/types/index.ts +159 -0
- package/src/utils/api.ts +119 -0
- package/src/utils/base.ts +92 -0
- package/src/utils/platform.ts +107 -0
- package/src/utils/session.ts +168 -0
- package/src/utils/url.ts +53 -0
- package/src/utils/view.ts +93 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { find, generateGUID, generateSpanId, generateTraceId, isString, interceptFunction, restoreFunction, isFunction, makeTracingHeaders, matchList, parseTracingOptions, performDraw, RumEventType, ResourceStatus, urlMatch } 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) {
|
|
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 traceOption = find(allowedUrls, traceOption => matchList([traceOption.match], apiAttr.url || ''));
|
|
36
|
+
if (!traceOption) return;
|
|
37
|
+
let pTypes = traceOption.propagatorTypes;
|
|
38
|
+
if (pTypes.length === 0) {
|
|
39
|
+
pTypes = propagatorTypes;
|
|
40
|
+
}
|
|
41
|
+
// skywalking
|
|
42
|
+
let isSw8 = false;
|
|
43
|
+
if (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 self = this;
|
|
77
|
+
interceptFunction(oldXHRProto, 'open', function (method, url, async, user, password) {
|
|
78
|
+
const filters = self.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 = self.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
|
+
self.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
|
+
} = self.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
|
+
//
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
self.sendAPI(apiAttr, entry);
|
|
148
|
+
});
|
|
149
|
+
this.addEventListener('error', () => {
|
|
150
|
+
this.apiAttr && (this.apiAttr.success = ResourceStatus.Failed);
|
|
151
|
+
});
|
|
152
|
+
}, true);
|
|
153
|
+
}
|
|
154
|
+
hackFetch() {
|
|
155
|
+
const self = this;
|
|
156
|
+
const originFetch = this.originFetch = globalThis.fetch;
|
|
157
|
+
const filters = this.ctx.getConfig().filters || {};
|
|
158
|
+
globalThis.fetch = function (input, init = {}) {
|
|
159
|
+
const isReq = input instanceof Request;
|
|
160
|
+
const urlStr = isReq ? input.url : isString(input) ? input : input.toString();
|
|
161
|
+
let method = init.method;
|
|
162
|
+
let headers = init.headers;
|
|
163
|
+
if (isReq) {
|
|
164
|
+
!method && (method = input.method);
|
|
165
|
+
!headers && (headers = input.headers);
|
|
166
|
+
}
|
|
167
|
+
method = method ? method.toUpperCase() : 'GET';
|
|
168
|
+
if (!headers) {
|
|
169
|
+
init.headers = headers = new Headers();
|
|
170
|
+
}
|
|
171
|
+
if (urlMatch(urlStr, filters.resource) || method === 'HEAD' || init?.mode === 'no-cors' || urlStr.length > 8182) {
|
|
172
|
+
return originFetch.call(global, input, init);
|
|
173
|
+
}
|
|
174
|
+
const baseRumEvent = self.ctx.session.getBaseEvent();
|
|
175
|
+
let apiAttr = {
|
|
176
|
+
...baseRumEvent,
|
|
177
|
+
url: urlStr,
|
|
178
|
+
type: ApiType.FETCH,
|
|
179
|
+
method
|
|
180
|
+
};
|
|
181
|
+
let apiResp;
|
|
182
|
+
let apiError;
|
|
183
|
+
self.injectTracing(apiAttr, tracingHeaders => {
|
|
184
|
+
Object.keys(tracingHeaders).forEach(key => {
|
|
185
|
+
if (!headers) return;
|
|
186
|
+
if (headers instanceof Headers) {
|
|
187
|
+
tracingHeaders[key] && headers.set(key, tracingHeaders[key]);
|
|
188
|
+
} else {
|
|
189
|
+
// @ts-ignore
|
|
190
|
+
headers[key] = tracingHeaders[key];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
async function fetchFinally() {
|
|
195
|
+
const {
|
|
196
|
+
evaluateApi
|
|
197
|
+
} = self.ctx.getConfig();
|
|
198
|
+
const entry = {
|
|
199
|
+
name: apiAttr.url,
|
|
200
|
+
entryType: ApiType.FETCH,
|
|
201
|
+
duration: getCurrentTime() - apiAttr.timestamp
|
|
202
|
+
};
|
|
203
|
+
if (isFunction(evaluateApi)) {
|
|
204
|
+
try {
|
|
205
|
+
const attrs = await evaluateApi?.({
|
|
206
|
+
url: input,
|
|
207
|
+
...init
|
|
208
|
+
}, apiResp, apiError);
|
|
209
|
+
apiAttr = {
|
|
210
|
+
...apiAttr,
|
|
211
|
+
...reviseApiAttr(attrs)
|
|
212
|
+
};
|
|
213
|
+
} catch (e) {
|
|
214
|
+
//
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
self.sendAPI(apiAttr, entry);
|
|
218
|
+
}
|
|
219
|
+
return originFetch.call(globalThis, input, init).then(response => {
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
if (response || isFunction(response.clone)) {
|
|
222
|
+
apiResp = response.clone();
|
|
223
|
+
const {
|
|
224
|
+
status,
|
|
225
|
+
statusText
|
|
226
|
+
} = apiResp;
|
|
227
|
+
apiAttr.status_code = status;
|
|
228
|
+
apiAttr.message = statusText;
|
|
229
|
+
fetchFinally().then();
|
|
230
|
+
}
|
|
231
|
+
return response;
|
|
232
|
+
}).catch(error => {
|
|
233
|
+
apiError = error;
|
|
234
|
+
apiAttr.message = String(error);
|
|
235
|
+
apiAttr.success = ResourceStatus.Failed;
|
|
236
|
+
fetchFinally().then();
|
|
237
|
+
throw error;
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
sendAPI(apiAttr, entry) {
|
|
242
|
+
const {
|
|
243
|
+
parseResourceName
|
|
244
|
+
} = this.ctx.getConfig();
|
|
245
|
+
const {
|
|
246
|
+
url,
|
|
247
|
+
status_code,
|
|
248
|
+
view
|
|
249
|
+
} = apiAttr;
|
|
250
|
+
const success = getResourceSuccessByCode(status_code);
|
|
251
|
+
const measures = {
|
|
252
|
+
duration: entry.duration
|
|
253
|
+
};
|
|
254
|
+
const event = {
|
|
255
|
+
event_type: RumEventType.RESOURCE,
|
|
256
|
+
url,
|
|
257
|
+
name: getResourceName(url || '', parseResourceName),
|
|
258
|
+
success,
|
|
259
|
+
type: entry.initiatorType || entry.entryType,
|
|
260
|
+
...apiAttr,
|
|
261
|
+
timing_data: JSON.stringify(entry),
|
|
262
|
+
// Measure
|
|
263
|
+
...measures,
|
|
264
|
+
view
|
|
265
|
+
};
|
|
266
|
+
this.sendEvent?.(event);
|
|
267
|
+
}
|
|
268
|
+
destroy() {
|
|
269
|
+
this.sendEvent = () => {};
|
|
270
|
+
// 恢复XHR
|
|
271
|
+
const oldXHRProto = XMLHttpRequest.prototype;
|
|
272
|
+
restoreFunction(oldXHRProto, 'open');
|
|
273
|
+
restoreFunction(oldXHRProto, 'setRequestHeader');
|
|
274
|
+
restoreFunction(oldXHRProto, 'send');
|
|
275
|
+
// 恢复 fetch
|
|
276
|
+
if (this.originFetch) {
|
|
277
|
+
globalThis.fetch = this.originFetch;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["find","generateGUID","generateSpanId","generateTraceId","isString","interceptFunction","restoreFunction","isFunction","makeTracingHeaders","matchList","parseTracingOptions","performDraw","RumEventType","ResourceStatus","urlMatch","getCurrentTime","ApiType","reviseApiAttr","getResourceName","getResourceSuccessByCode","ApiCollector","name","setup","ctx","sendEvent","collectors","getConfig","api","hackXhr","injectTracing","apiAttr","inject","tracing","pid","version","enable","sample","propagatorTypes","allowedUrls","tracestate","baggage","traceOption","match","url","pTypes","length","isSw8","indexOf","session","traceId","spanId","sampled","uid","getUserId","sid","getSessionId","traceContext","undefined","baggageContext","tracingHeaders","appId","appVersion","viewName","view","trace_id","trace_data","JSON","stringify","headers","oldXHRProto","XMLHttpRequest","prototype","self","method","async","user","password","filters","urlStr","String","methodStr","toUpperCase","resource","apiCache","type","XHR","baseRumEvent","getBaseEvent","header","value","body","data","Object","keys","forEach","key","setRequestHeader","addEventListener","status","statusText","response","evaluateApi","status_code","message","entry","entryType","duration","timestamp","error","success","Failed","Error","attrs","e","sendAPI","hackFetch","originFetch","globalThis","fetch","input","init","isReq","Request","toString","Headers","mode","call","global","FETCH","apiResp","apiError","set","fetchFinally","then","clone","catch","parseResourceName","measures","event","event_type","RESOURCE","initiatorType","timing_data","destroy"],"sourceRoot":"../../../../src","sources":["collector/resource/api.ts"],"mappings":";;AAAA,SACEA,IAAI,EACJC,YAAY,EACZC,cAAc,EACdC,eAAe,EAGfC,QAAQ,EACRC,iBAAiB,EACjBC,eAAe,EACfC,UAAU,EAEVC,kBAAkB,EAClBC,SAAS,EACTC,mBAAmB,EACnBC,WAAW,EAEXC,YAAY,EAEZC,cAAc,EAEdC,QAAQ,QAGH,gBAAgB;AACvB,SAASC,cAAc,QAAQ,qBAAkB;AAEjD,SACEC,OAAO,EAGPC,aAAa,EACbC,eAAe,EACfC,wBAAwB,QACnB,oBAAiB;AAUxB,eAAe,MAAMC,YAAY,CAAuB;EACtDC,IAAI,GAAG,eAAe;EAMtBC,KAAKA,CAACC,GAAa,EAAEC,SAAsC,EAAE;IAC3D,MAAMC,UAAU,GAAGF,GAAG,CAACG,SAAS,CAAC,CAAC,CAACD,UAAU,IAAI,CAAC,CAAC;IACnD,IAAI,CAACA,UAAU,CAACE,GAAG,EAAE;MACnB;IACF;IACA,IAAI,CAACH,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACD,GAAG,GAAGA,GAAG;IACd;IACA,IAAI,CAACK,OAAO,CAAC,CAAC;IACd;EACF;EAEAC,aAAaA,CACXC,OAAiB,EACjBC,MAAiD,EACjD;IACA,MAAM;MACJC,OAAO,GAAG,KAAK;MACfC,GAAG;MACHC,OAAO,GAAG;IACZ,CAAC,GAAI,IAAI,CAACX,GAAG,CAAcG,SAAS,CAAC,CAAC;IACtC,MAAM;MACJS,MAAM;MACNC,MAAM;MACNC,eAAe;MACfC,WAAW;MACXC,UAAU;MACVC,OAAO,GAAG;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E/H,YAAY,CAACgI,QAAQ;MACjCjG,GAAG;MACHtB,IAAI,EAAEH,eAAe,CAACyB,GAAG,IAAI,EAAE,EAAE6F,iBAAiB,CAAC;MACnD3B,OAAO;MACPzB,IAAI,EAAEoB,KAAK,CAACqC,aAAa,IAAIrC,KAAK,CAACC,SAAS;MAC5C,GAAG3E,OAAO;MACVgH,WAAW,EAAE5E,IAAI,CAACC,SAAS,CAACqC,KAAK,CAAC;MAClC;MACA,GAAGiC,QAAQ;MACX1E;IACF,CAAC;IAED,IAAI,CAACvC,SAAS,GAAGkH,KAAK,CAAC;EACzB;EAEAK,OAAOA,CAAA,EAAG;IACR,IAAI,CAACvH,SAAS,GAAG,MAAM,CAAC,CAAC;IACzB;IACA,MAAM6C,WAAW,GAAGC,cAAc,CAACC,SAAS;IAC5CjE,eAAe,CAAC+D,WAAW,EAAE,MAAM,CAAC;IACpC/D,eAAe,CAAC+D,WAAW,EAAE,kBAAkB,CAAC;IAChD/D,eAAe,CAAC+D,WAAW,EAAE,MAAM,CAAC;IACpC;IACA,IAAI,IAAI,CAAC+C,WAAW,EAAE;MACpBC,UAAU,CAACC,KAAK,GAAG,IAAI,CAACF,WAAkB;IAC5C;EACF;AACF","ignoreList":[]}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["collector/view/perf.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { isFunction, RumEventType } from '@arms/rum-core';
|
|
4
|
+
import { addNavigateListener, removeNavigateListener } from "../../utils/view.js";
|
|
5
|
+
export default class PvCollector {
|
|
6
|
+
name = 'pv-collector';
|
|
7
|
+
pageMap = {};
|
|
8
|
+
setup(ctx, sendEvent) {
|
|
9
|
+
this.ctx = ctx;
|
|
10
|
+
this.sendEvent = sendEvent;
|
|
11
|
+
addNavigateListener(this.onChange);
|
|
12
|
+
}
|
|
13
|
+
onChange = route => {
|
|
14
|
+
// {"name":"index","path":"/","key":"index-SB2hXmOGNdpiLskG5sXwj"}
|
|
15
|
+
// {"name":"__root","key":"__root-jPbNqG7-HaM-OUx_FcCUw"}
|
|
16
|
+
const {
|
|
17
|
+
key,
|
|
18
|
+
name,
|
|
19
|
+
path,
|
|
20
|
+
params
|
|
21
|
+
} = route;
|
|
22
|
+
const page = {
|
|
23
|
+
name,
|
|
24
|
+
path,
|
|
25
|
+
id: key,
|
|
26
|
+
params
|
|
27
|
+
};
|
|
28
|
+
if (name === "__root" || !('path' in page)) return;
|
|
29
|
+
this.sendPv(page);
|
|
30
|
+
};
|
|
31
|
+
sendPv = page => {
|
|
32
|
+
const prevPage = this.prevPage;
|
|
33
|
+
const ctx = this.ctx;
|
|
34
|
+
if (page.id === prevPage?.id) {
|
|
35
|
+
// 路由没有发生变化,不发送
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
page.name = this.getViewName(page.path, page);
|
|
39
|
+
if (prevPage && prevPage.id in this.pageMap) {
|
|
40
|
+
delete this.pageMap[prevPage.id];
|
|
41
|
+
ctx.removeView(prevPage.id);
|
|
42
|
+
}
|
|
43
|
+
this.prevPage = page;
|
|
44
|
+
ctx.addView(page);
|
|
45
|
+
|
|
46
|
+
// 路由回退情况下已经上报
|
|
47
|
+
if (page.id in this.pageMap) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.pageMap[page.id] = page;
|
|
51
|
+
this.sendEvent?.({
|
|
52
|
+
event_type: RumEventType.VIEW,
|
|
53
|
+
type: 'pv',
|
|
54
|
+
loading_type: 'initial_load',
|
|
55
|
+
...page
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
getViewName(url, page) {
|
|
59
|
+
let {
|
|
60
|
+
parseViewName
|
|
61
|
+
} = this.ctx?.getConfig();
|
|
62
|
+
let name = page.name;
|
|
63
|
+
if (parseViewName && isFunction(parseViewName)) {
|
|
64
|
+
name = parseViewName(url, page) || name;
|
|
65
|
+
}
|
|
66
|
+
return name;
|
|
67
|
+
}
|
|
68
|
+
destroy() {
|
|
69
|
+
removeNavigateListener(this.onChange);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=pv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isFunction","RumEventType","addNavigateListener","removeNavigateListener","PvCollector","name","pageMap","setup","ctx","sendEvent","onChange","route","key","path","params","page","id","sendPv","prevPage","getViewName","removeView","addView","event_type","VIEW","type","loading_type","url","parseViewName","getConfig","destroy"],"sourceRoot":"../../../../src","sources":["collector/view/pv.ts"],"mappings":";;AAAA,SAA+BA,UAAU,EAAuBC,YAAY,QAAsB,gBAAgB;AAElH,SAASC,mBAAmB,EAAEC,sBAAsB,QAAQ,qBAAkB;AAG9E,eAAe,MAAMC,WAAW,CAAuB;EACrDC,IAAI,GAAG,cAAc;EAMbC,OAAO,GAA6B,CAAC,CAAC;EAE9CC,KAAKA,CAACC,GAAa,EAAEC,SAAsC,EAAE;IAC3D,IAAI,CAACD,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,SAAS,GAAGA,SAAS;IAC1BP,mBAAmB,CAAC,IAAI,CAACQ,QAAQ,CAAC;EACpC;EAEAA,QAAQ,GAAIC,KAAiB,IAAK;IAChC;IACA;IACA,MAAM;MAACC,GAAG;MAAEP,IAAI;MAAEQ,IAAI;MAAEC;IAAM,CAAC,GAAGH,KAAK;IACvC,MAAMI,IAAW,GAAG;MAACV,IAAI;MAAEQ,IAAI;MAAEG,EAAE,EAAEJ,GAAG;MAAEE;IAAM,CAAC;IACjD,IAAIT,IAAI,KAAK,QAAQ,IAAI,EAAE,MAAM,IAAIU,IAAI,CAAC,EAAE;IAC5C,IAAI,CAACE,MAAM,CAACF,IAAI,CAAC;EACnB,CAAC;EAEDE,MAAM,GAAIF,IAAW,IAAK;IACxB,MAAMG,QAAQ,GAAG,IAAI,CAACA,QAAQ;IAC9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ACvC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["armsRum","ArmsRum"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,OAAOA,OAAO,IAAIC,OAAO,QAAQ,YAAS;AAE1C,SAASA,OAAO;AAChB,eAAeD,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
if (!config.pid) {
|
|
29
|
+
config.pid = `react-native@${VERSION}`;
|
|
30
|
+
}
|
|
31
|
+
if (!config.endpoint) {
|
|
32
|
+
config.endpoint = `http://127.0.0.1/?version=${VERSION}`;
|
|
33
|
+
}
|
|
34
|
+
initRum(config);
|
|
35
|
+
});
|
|
36
|
+
RumSdkModule?.getConfig?.();
|
|
37
|
+
}
|
|
38
|
+
export default armsRum;
|
|
39
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","NativeEventEmitter","isString","VERSION","armsRum","RumSdkModule","initRum","config","init","beforeReport","bundle","sendEvent","JSON","stringify","eventEmitter","addListener","parse","e","console","warn","pid","endpoint","getConfig"],"sourceRoot":"../../src","sources":["plugin.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;AAChE,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,OAAO,QAAQ,qBAAkB;AAC1C,OAAOC,OAAO,MAAM,YAAS;AAE7B,MAAMC,YAAY,GAAGL,aAAa,CAACK,YAAY;AAE/C,SAASC,OAAOA,CAACC,MAAiB,EAAE;EAClCH,OAAO,CAACI,IAAI,CAAC;IACX,GAAGD,MAAM;IACTE,YAAYA,CAACC,MAAM,EAAO;MACxBL,YAAY,CAACM,SAAS,CAACC,IAAI,CAACC,SAAS,CAACH,MAAM,CAAC,CAAC;MAC9C,OAAO,IAAI;IACb;EACF,CAAC,CAAC;AACJ;AAEA,IAAIL,YAAY,EAAE;EAChB,MAAMS,YAAY,GAAG,IAAIb,kBAAkB,CAACI,YAAY,CAAC;EACzDS,YAAY,CAACC,WAAW,CAAC,gBAAgB,EAAGR,MAAiB,IAAK;IAChE,IAAIL,QAAQ,CAACK,MAAM,CAAC,EAAE;MACpB,IAAI;QACFA,MAAM,GAAGK,IAAI,CAACI,KAAK,CAACT,MAAM,CAAC;MAC7B,CAAC,CAAC,OAAOU,CAAC,EAAE;QACVC,OAAO,CAACC,IAAI,CAAC,iBAAiB,EAAEF,CAAC,CAAC;QAClC;MACF;IACF;IACA,IAAI,CAACV,MAAM,CAACa,GAAG,EAAE;MACfb,MAAM,CAACa,GAAG,GAAG,gBAAgBjB,OAAO,EAAE;IACxC;IACA,IAAI,CAACI,MAAM,CAACc,QAAQ,EAAE;MACpBd,MAAM,CAACc,QAAQ,GAAG,6BAA6BlB,OAAO,EAAE;IAC1D;IACAG,OAAO,CAACC,MAAM,CAAC;EACjB,CAAC,CAAC;EACFF,YAAY,EAAEiB,SAAS,GAAG,CAAC;AAC7B;AAEA,eAAelB,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getCurrentTime","getCurView","DefaultProcessor","name","process","ctx","event","getRumEvent","view","session_id","session","getSessionId","event_id","getEventId","rumEvent","timestamp"],"sourceRoot":"../../../src","sources":["processor/default-processor.ts"],"mappings":";;AACA,SAASA,cAAc,QAAQ,kBAAe;AAC9C,SAASC,UAAU,QAAQ,kBAAe;AAE1C,eAAe,MAAMC,gBAAgB,CAAuB;EAC1DC,IAAI,GAAG,mBAAmB;EAE1BC,OAAOA,CAACC,GAAa,EAAE;IACrB,MAAMC,KAAK,GAAGD,GAAG,CAACE,WAAW,CAAC,CAAC;IAC/B,MAAMC,IAAI,GAAGP,UAAU,CAACI,GAAG,CAAc;IACzC,MAAMI,UAAU,GAAGJ,GAAG,CAACK,OAAO,CAACC,YAAY,CAAC,CAAC;IAC7C,MAAMC,QAAQ,GAAGP,GAAG,CAACK,OAAO,CAACG,UAAU,CAAC,CAAC;IACzC,MAAMC,QAAkB,GAAG;MACzBC,SAAS,EAAEf,cAAc,CAAC,CAAC;MAC3BS,UAAU;MACVG,QAAQ;MACRJ,IAAI;MACJ,GAAGF;IACL,CAAC;IACD,OAAOQ,QAAQ;EACjB;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { debounce, ONE_SECOND } from '@arms/rum-core';
|
|
4
|
+
export default class SessionProcessor {
|
|
5
|
+
name = 'session-processor';
|
|
6
|
+
setup(ctx) {
|
|
7
|
+
this.ctx = ctx;
|
|
8
|
+
this.update = debounce(this.update, ONE_SECOND);
|
|
9
|
+
// sdk.onTouchStart(this.update)
|
|
10
|
+
}
|
|
11
|
+
update = e => {
|
|
12
|
+
if (e && !e.isTrusted) return;
|
|
13
|
+
this.ctx?.session.updateSession();
|
|
14
|
+
};
|
|
15
|
+
process(ctx) {
|
|
16
|
+
this.update();
|
|
17
|
+
return ctx.getRumEvent();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=session-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["debounce","ONE_SECOND","SessionProcessor","name","setup","ctx","update","e","isTrusted","session","updateSession","process","getRumEvent"],"sourceRoot":"../../../src","sources":["processor/session-processor.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAwBC,UAAU,QAAQ,gBAAgB;AAE3E,eAAe,MAAMC,gBAAgB,CAAuB;EAC1DC,IAAI,GAAG,mBAAmB;EAI1BC,KAAKA,CAACC,GAAa,EAAE;IACnB,IAAI,CAACA,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,MAAM,GAAGN,QAAQ,CAAC,IAAI,CAACM,MAAM,EAAEL,UAAU,CAAC;IAC/C;EACF;EAEAK,MAAM,GAAIC,CAAS,IAAK;IACtB,IAAIA,CAAC,IAAI,CAACA,CAAC,CAACC,SAAS,EAAE;IACvB,IAAI,CAACH,GAAG,EAAEI,OAAO,CAACC,aAAa,CAAC,CAAC;EACnC,CAAC;EAEDC,OAAOA,CAACN,GAAa,EAAE;IACrB,IAAI,CAACC,MAAM,CAAC,CAAC;IACb,OAAOD,GAAG,CAACO,WAAW,CAAC,CAAC;EAC1B;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Reporter } from '@arms/rum-core';
|
|
4
|
+
import { fixAttrs } from "../utils/platform.js";
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { AppState } from 'react-native';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* rn-app reporter
|
|
10
|
+
*/
|
|
11
|
+
class RNReporter extends Reporter {
|
|
12
|
+
name = 'rn-reporter';
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
// 离开之前 flushEventQueue
|
|
16
|
+
try {
|
|
17
|
+
this.appStateListener = AppState.addEventListener('change', this.onAppStateChanged);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
//
|
|
20
|
+
console.info(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
init(ctx) {
|
|
24
|
+
this.ctx = ctx;
|
|
25
|
+
}
|
|
26
|
+
onAppStateChanged(nextAppState) {
|
|
27
|
+
if (nextAppState === 'background') {
|
|
28
|
+
// 执行后台操作:暂停动画、保存数据、停止网络请求等
|
|
29
|
+
this.flushEventQueue();
|
|
30
|
+
}
|
|
31
|
+
// else if (nextAppState === 'active') {
|
|
32
|
+
// console.warn('RUM:应用回到前台');
|
|
33
|
+
// }
|
|
34
|
+
}
|
|
35
|
+
request(ctx, bundle) {
|
|
36
|
+
const batchedEvents = fixAttrs(bundle);
|
|
37
|
+
const config = ctx.getConfig();
|
|
38
|
+
fetch(config.endpoint, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'text/plain'
|
|
42
|
+
},
|
|
43
|
+
body: JSON.stringify(batchedEvents)
|
|
44
|
+
}).then(_res => {
|
|
45
|
+
//
|
|
46
|
+
}).catch(this.catchHandle);
|
|
47
|
+
}
|
|
48
|
+
catchHandle = err => {
|
|
49
|
+
console.warn('[rum] sendRequest fail', err);
|
|
50
|
+
};
|
|
51
|
+
destroy() {
|
|
52
|
+
this.appStateListener?.remove();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default RNReporter;
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Reporter","fixAttrs","AppState","RNReporter","name","constructor","appStateListener","addEventListener","onAppStateChanged","error","console","info","init","ctx","nextAppState","flushEventQueue","request","bundle","batchedEvents","config","getConfig","fetch","endpoint","method","headers","body","JSON","stringify","then","_res","catch","catchHandle","err","warn","destroy","remove"],"sourceRoot":"../../../src","sources":["reporter/index.ts"],"mappings":";;AAAA,SAGEA,QAAQ,QAEH,gBAAgB;AACvB,SAASC,QAAQ,QAAQ,sBAAmB;AAC5C;AACA,SAASC,QAAQ,QAAiC,cAAc;;AAEhE;AACA;AACA;AACA,MAAMC,UAAU,SAASH,QAAQ,CAAsB;EACrDI,IAAI,GAAG,aAAa;EAIpBC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,CAAC;IACP;IACA,IAAI;MACF,IAAI,CAACC,gBAAgB,GAAGJ,QAAQ,CAACK,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAACC,iBAAiB,CAAC;IACrF,CAAC,CAAC,OAAOC,KAAK,EAAE;MACd;MACAC,OAAO,CAACC,IAAI,CAACF,KAAK,CAAC;IACrB;EACF;EAEAG,IAAIA,CAACC,GAAa,EAAE;IAClB,IAAI,CAACA,GAAG,GAAGA,GAAG;EAChB;EAEAL,iBAAiBA,CAACM,YAAoB,EAAE;IACtC,IAAIA,YAAY,KAAK,YAAY,EAAE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