@arms/rum-reactnative 0.1.3-beta.5 → 0.1.4-beta.2
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 +9 -2
- package/android/build.gradle +12 -1
- package/android/gradle.properties +3 -1
- package/android/src/main/AndroidManifest.xml +4 -1
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +67 -14
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +9 -2
- 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" +20 -0
- package/docs//346/216/245/345/205/245ReactNative/345/272/224/347/224/250.md +2 -1
- 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.h +11 -1
- package/ios/RumSdkReactnative.mm +115 -29
- 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,292 +1 @@
|
|
|
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 that = this;
|
|
81
|
-
(0, _rumCore.interceptFunction)(oldXHRProto, 'open', function (method, url, async, user, password) {
|
|
82
|
-
const filters = that.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 = that.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
|
-
that.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
|
-
} = that.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
|
-
that.sendAPI(apiAttr, entry);
|
|
152
|
-
});
|
|
153
|
-
this.addEventListener('error', () => {
|
|
154
|
-
this.apiAttr && (this.apiAttr.success = _rumCore.ResourceStatus.Failed);
|
|
155
|
-
});
|
|
156
|
-
this.addEventListener('abort', () => {
|
|
157
|
-
if (this.apiAttr) {
|
|
158
|
-
this.apiAttr.success = _rumCore.ResourceStatus.Failed;
|
|
159
|
-
this.apiAttr.message = 'abort';
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}, true);
|
|
163
|
-
}
|
|
164
|
-
hackFetch() {
|
|
165
|
-
const that = this;
|
|
166
|
-
const originFetch = this.originFetch = globalThis.fetch;
|
|
167
|
-
const filters = this.ctx.getConfig().filters || {};
|
|
168
|
-
globalThis.fetch = function (input, init = {}) {
|
|
169
|
-
const isReq = input instanceof Request;
|
|
170
|
-
const urlStr = isReq ? input.url : (0, _rumCore.isString)(input) ? input : input.toString();
|
|
171
|
-
let method = init.method;
|
|
172
|
-
let headers = init.headers;
|
|
173
|
-
if (isReq) {
|
|
174
|
-
!method && (method = input.method);
|
|
175
|
-
!headers && (headers = input.headers);
|
|
176
|
-
}
|
|
177
|
-
method = method ? method.toUpperCase() : 'GET';
|
|
178
|
-
if (!headers) {
|
|
179
|
-
init.headers = headers = new Headers();
|
|
180
|
-
}
|
|
181
|
-
if ((0, _rumCore.urlMatch)(urlStr, filters.resource) || method === 'HEAD' || init?.mode === 'no-cors' || urlStr.length > 8182) {
|
|
182
|
-
return originFetch.call(global, input, init);
|
|
183
|
-
}
|
|
184
|
-
const baseRumEvent = that.ctx.session.getBaseEvent();
|
|
185
|
-
let apiAttr = {
|
|
186
|
-
...baseRumEvent,
|
|
187
|
-
url: urlStr,
|
|
188
|
-
type: _api.ApiType.FETCH,
|
|
189
|
-
method
|
|
190
|
-
};
|
|
191
|
-
let apiResp;
|
|
192
|
-
let apiError;
|
|
193
|
-
that.injectTracing(apiAttr, tracingHeaders => {
|
|
194
|
-
Object.keys(tracingHeaders).forEach(key => {
|
|
195
|
-
if (!headers) return;
|
|
196
|
-
if (headers instanceof Headers) {
|
|
197
|
-
tracingHeaders[key] && headers.set(key, tracingHeaders[key]);
|
|
198
|
-
} else {
|
|
199
|
-
// @ts-ignore
|
|
200
|
-
headers[key] = tracingHeaders[key];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
async function fetchFinally() {
|
|
205
|
-
const {
|
|
206
|
-
evaluateApi
|
|
207
|
-
} = that.ctx.getConfig();
|
|
208
|
-
const entry = {
|
|
209
|
-
name: apiAttr.url,
|
|
210
|
-
entryType: _api.ApiType.FETCH,
|
|
211
|
-
duration: (0, _base.getCurrentTime)() - apiAttr.timestamp
|
|
212
|
-
};
|
|
213
|
-
if ((0, _rumCore.isFunction)(evaluateApi)) {
|
|
214
|
-
try {
|
|
215
|
-
const attrs = await evaluateApi?.({
|
|
216
|
-
url: input,
|
|
217
|
-
...init
|
|
218
|
-
}, apiResp, apiError);
|
|
219
|
-
apiAttr = {
|
|
220
|
-
...apiAttr,
|
|
221
|
-
...(0, _api.reviseApiAttr)(attrs)
|
|
222
|
-
};
|
|
223
|
-
} catch (e) {
|
|
224
|
-
_rumCore.logger.warn('api-collector', 'evaluateApi failed for fetch', e);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
that.sendAPI(apiAttr, entry);
|
|
228
|
-
}
|
|
229
|
-
return originFetch.call(globalThis, input, init).then(response => {
|
|
230
|
-
// @ts-ignore
|
|
231
|
-
if (response || (0, _rumCore.isFunction)(response.clone)) {
|
|
232
|
-
apiResp = response.clone();
|
|
233
|
-
const {
|
|
234
|
-
status,
|
|
235
|
-
statusText
|
|
236
|
-
} = apiResp;
|
|
237
|
-
apiAttr.status_code = status;
|
|
238
|
-
apiAttr.message = statusText;
|
|
239
|
-
fetchFinally().then();
|
|
240
|
-
}
|
|
241
|
-
return response;
|
|
242
|
-
}).catch(error => {
|
|
243
|
-
apiError = error;
|
|
244
|
-
apiAttr.message = String(error);
|
|
245
|
-
apiAttr.success = _rumCore.ResourceStatus.Failed;
|
|
246
|
-
fetchFinally().then();
|
|
247
|
-
throw error;
|
|
248
|
-
});
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
sendAPI(apiAttr, entry) {
|
|
252
|
-
const {
|
|
253
|
-
parseResourceName
|
|
254
|
-
} = this.ctx.getConfig();
|
|
255
|
-
const {
|
|
256
|
-
url,
|
|
257
|
-
status_code,
|
|
258
|
-
view
|
|
259
|
-
} = apiAttr;
|
|
260
|
-
const success = (0, _api.getResourceSuccessByCode)(status_code);
|
|
261
|
-
const measures = {
|
|
262
|
-
duration: entry.duration
|
|
263
|
-
};
|
|
264
|
-
const event = {
|
|
265
|
-
event_type: _rumCore.RumEventType.RESOURCE,
|
|
266
|
-
url,
|
|
267
|
-
name: (0, _api.getResourceName)(url || '', parseResourceName),
|
|
268
|
-
success,
|
|
269
|
-
type: entry.initiatorType || entry.entryType,
|
|
270
|
-
...apiAttr,
|
|
271
|
-
timing_data: JSON.stringify(entry),
|
|
272
|
-
// Measure
|
|
273
|
-
...measures,
|
|
274
|
-
view
|
|
275
|
-
};
|
|
276
|
-
this.sendEvent?.(event);
|
|
277
|
-
}
|
|
278
|
-
destroy() {
|
|
279
|
-
this.sendEvent = () => {};
|
|
280
|
-
// 恢复XHR
|
|
281
|
-
const oldXHRProto = XMLHttpRequest.prototype;
|
|
282
|
-
(0, _rumCore.restoreFunction)(oldXHRProto, 'open');
|
|
283
|
-
(0, _rumCore.restoreFunction)(oldXHRProto, 'setRequestHeader');
|
|
284
|
-
(0, _rumCore.restoreFunction)(oldXHRProto, 'send');
|
|
285
|
-
// 恢复 fetch
|
|
286
|
-
if (this.originFetch) {
|
|
287
|
-
globalThis.fetch = this.originFetch;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
exports.default = ApiCollector;
|
|
292
|
-
//# sourceMappingURL=api.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_api=require("../../utils/api");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:r=!1,pid:s,version:i="1.0.0"}=this.ctx.getConfig(),{enable:a,sample:o,propagatorTypes:n,allowedUrls:c,tracestate:u,baggage:p=!1}=(0,_rumCore.parseTracingOptions)(r);if(!a)return;const h=(0,_rumCore.find)(c,t=>(0,_rumCore.matchList)([t.match],e.url||""));if(!h)return;let l=h.propagatorTypes;l&&0===l.length&&(l=n);let d=!1;l&&l.indexOf("sw8")>-1&&(l=["sw8"],d=!0);const g=this.ctx.session,m=d?(0,_rumCore.generateGUID)():(0,_rumCore.generateTraceId)(),C=d?(0,_rumCore.generateGUID)():(0,_rumCore.generateSpanId)(),_=(0,_rumCore.performDraw)(o),f=g.getUserId(),y=g.getSessionId(),A=u?`rum=v2&browser&${s}&${y}&${f}`:void 0,T=p?`rum=v2,appType=browser,pid=${s},sid=${y},uid=${f}`:void 0,v=(0,_rumCore.makeTracingHeaders)(m,C,_,l||[],{tracestate:A,baggage:T,appId:s,appVersion:i,viewName:e.view?.name});_&&(e.trace_id=m,e.trace_data=JSON.stringify({spanId:C,sample:o,sampled:_,headers:v})),t(v)}hackXhr(){const e=XMLHttpRequest.prototype,t=this;(0,_rumCore.interceptFunction)(e,"open",function(e,r,s,i,a){const o=t.ctx.getConfig().filters||{},n=String(r),c=e.toUpperCase();if((0,_rumCore.urlMatch)(n,o.resource)||"HEAD"===c||n.length>8182)return;this.apiCache={type:_api.ApiType.XHR,method:e,url:r,async:s,user:i,password:a,headers:{}};const u=t.ctx.session.getBaseEvent();this.apiAttr={...u,url:n,method:c}},!0),(0,_rumCore.interceptFunction)(e,"setRequestHeader",function(e,t){this.apiCache&&(this.apiCache.headers={...this.apiCache.headers,[e]:t})},!0),(0,_rumCore.interceptFunction)(e,"send",function(e){if(!this.apiAttr||!this.apiCache)return;let r=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:s,response:i}=this,{evaluateApi:a}=t.ctx.getConfig();if(!this.apiAttr)return;r.status_code=e,r.message=s;const o={name:this.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-r.timestamp};if((0,_rumCore.isFunction)(a))try{let e;r.success===_rumCore.ResourceStatus.Failed&&(e=new Error(_api.ApiType.XHR+" error"));const t=await(a?.(this.apiCache,i,e,this));this.apiAttr=r={...r,...(0,_api.reviseApiAttr)(t)}}catch(e){_rumCore.logger.warn("api-collector","evaluateApi failed for XHR",e)}t.sendAPI(r,o)}),this.addEventListener("error",()=>{this.apiAttr&&(this.apiAttr.success=_rumCore.ResourceStatus.Failed)}),this.addEventListener("abort",()=>{this.apiAttr&&(this.apiAttr.success=_rumCore.ResourceStatus.Failed,this.apiAttr.message="abort")})},!0)}hackFetch(){const e=this,t=this.originFetch=globalThis.fetch,r=this.ctx.getConfig().filters||{};globalThis.fetch=function(s,i={}){const a=s instanceof Request,o=a?s.url:(0,_rumCore.isString)(s)?s:s.toString();let n=i.method,c=i.headers;if(a&&(!n&&(n=s.method),!c&&(c=s.headers)),n=n?n.toUpperCase():"GET",c||(i.headers=c=new Headers),(0,_rumCore.urlMatch)(o,r.resource)||"HEAD"===n||"no-cors"===i?.mode||o.length>8182)return t.call(global,s,i);let u,p,h={...e.ctx.session.getBaseEvent(),url:o,type:_api.ApiType.FETCH,method:n};async function l(){const{evaluateApi:t}=e.ctx.getConfig(),r={name:h.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-h.timestamp};if((0,_rumCore.isFunction)(t))try{const e=await(t?.({url:s,...i},u,p));h={...h,...(0,_api.reviseApiAttr)(e)}}catch(e){_rumCore.logger.warn("api-collector","evaluateApi failed for fetch",e)}e.sendAPI(h,r)}return e.injectTracing(h,e=>{Object.keys(e).forEach(t=>{c&&(c instanceof Headers?e[t]&&c.set(t,e[t]):c[t]=e[t])})}),t.call(globalThis,s,i).then(e=>{if(e||(0,_rumCore.isFunction)(e.clone)){u=e.clone();const{status:t,statusText:r}=u;h.status_code=t,h.message=r,l().then()}return e}).catch(e=>{throw p=e,h.message=String(e),h.success=_rumCore.ResourceStatus.Failed,l().then(),e})}}sendAPI(e,t){const{parseResourceName:r}=this.ctx.getConfig(),{url:s,status_code:i,view:a}=e,o=(0,_api.getResourceSuccessByCode)(i),n={duration:t.duration},c={event_type:_rumCore.RumEventType.RESOURCE,url:s,name:(0,_api.getResourceName)(s||"",r),success:o,type:t.initiatorType||t.entryType,...e,timing_data:JSON.stringify(t),...n,view:a};this.sendEvent?.(c)}destroy(){this.sendEvent=()=>{};const e=XMLHttpRequest.prototype;(0,_rumCore.restoreFunction)(e,"open"),(0,_rumCore.restoreFunction)(e,"setRequestHeader"),(0,_rumCore.restoreFunction)(e,"send"),this.originFetch&&(globalThis.fetch=this.originFetch)}}exports.default=ApiCollector;
|
|
@@ -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,88 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _rumCore=require("@arms/rum-core"),_view=require("../../utils/view"),_crash=require("../../types/crash");class PvCollector{name="pv-collector";pageMap={};setup(e,t){this.ctx=e,this.sendEvent=t,(0,_view.addNavigateListener)(this.onChange)}onChange=e=>{const{key:t,name:i,path:s,params:a}=e,r={name:i,path:s,id:t,params:a};"__root"!==i&&this.sendPv(r)};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:_rumCore.RumEventType.VIEW,type:"pv",loading_type:"initial_load",...e});const s=i.session?.getSessionId?.()||"",a=i.session?.getUserId?.()||"";i.emitter.emit(_crash.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&&(0,_rumCore.isFunction)(i)&&(s=i(e,t)||s),s}destroy(){(0,_view.removeNavigateListener)(this.onChange)}}exports.default=PvCollector;
|
|
@@ -1,37 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const withRumSdk=(e,t)=>{const r={...e.extra??{}};return r.rumSdk={endpoint:t?.endpoint,env:t?.env??"prod",version:t?.version},{...e,extra:r}};var _default=exports.default=withRumSdk;
|
package/lib/commonjs/index.js
CHANGED
|
@@ -1,29 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ArmsRum",{enumerable:!0,get:function(){return _shell.ArmsRum}}),Object.defineProperty(exports,"callMonitored",{enumerable:!0,get:function(){return _rumCore.callMonitored}}),exports.default=void 0,Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return _rumCore.logger}});var _shell=_interopRequireWildcard(require("./shell")),_rumCore=require("@arms/rum-core");function _interopRequireWildcard(e,r){if("function"==typeof WeakMap)var t=new WeakMap,o=new WeakMap;return(_interopRequireWildcard=function(e,r){if(!r&&e&&e.__esModule)return e;var n,u,l={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return l;if(n=r?o:t){if(n.has(e))return n.get(e);n.set(e,l)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((u=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(u.get||u.set)?n(l,r,u):l[r]=e[r]);return l})(e,r)}var _default=exports.default=_shell.default;
|
package/lib/commonjs/plugin.js
CHANGED
|
@@ -1,47 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _reactNative=require("react-native"),_rumCore=require("@arms/rum-core"),_platform=require("./utils/platform"),_shell=_interopRequireDefault(require("./shell"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const RumSdkModule=_reactNative.NativeModules.RumSdkModule;function initRum(e){_shell.default.init({...e,beforeReport:e=>(RumSdkModule.sendEvent(JSON.stringify(e)),null)})}if(RumSdkModule){new _reactNative.NativeEventEmitter(RumSdkModule).addListener("rumNativeEvent",e=>{if((0,_rumCore.isString)(e))try{e=JSON.parse(e)}catch(e){return void console.warn("getConfig error",e)}e.pid||(e.pid=`react-native@${_platform.VERSION}`),e.endpoint||(e.endpoint=`http://127.0.0.1/?version=${_platform.VERSION}`),initRum(e)}),RumSdkModule?.getConfig?.()}var _default=exports.default=_shell.default;
|
|
@@ -1,27 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _base=require("../utils/base"),_view=require("../utils/view");class DefaultProcessor{name="default-processor";process(e){const s=e.getRumEvent(),t=(0,_view.getCurView)(e),r=e.session.getSessionId(),i=e.session.getEventId();return{timestamp:(0,_base.getCurrentTime)(),session_id:r,event_id:i,view:t,...s}}}exports.default=DefaultProcessor;
|
|
@@ -1,47 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _rumCore=require("@arms/rum-core"),_crash=require("../types/crash"),_view=require("../utils/view");class SessionProcessor{name="session-processor";lastSessionId="";setup(s){this.ctx=s,this.update=(0,_rumCore.debounce)(this.update,_rumCore.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 e=(0,_view.getCurView)(this.ctx);this.ctx.emitter.emit(_crash.CRASH_CONTEXT_EVENT,{session_id:s,user_id:this.ctx.session.getUserId(),view_id:e?.id||"",view_name:e?.name||""})}}exports.default=SessionProcessor;
|