@oneteme/inspect-ng-collector 1.3.3 → 1.3.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 +55 -68
- package/fesm2022/oneteme-inspect-ng-collector.mjs +613 -220
- package/fesm2022/oneteme-inspect-ng-collector.mjs.map +1 -1
- package/lib/configuration.d.ts +114 -79
- package/lib/event-bus.d.ts +6 -5
- package/lib/event-trace-scheduled-dispatcher.service.d.ts +14 -0
- package/lib/local-request.monitor.d.ts +2 -2
- package/lib/log.monitor.d.ts +1 -0
- package/lib/rest-request.monitor.d.ts +1 -1
- package/lib/session-manager.service.d.ts +8 -7
- package/lib/trace.model.d.ts +49 -16
- package/lib/traceable-stage.decorator.d.ts +0 -4
- package/package.json +1 -1
- package/lib/event-trace-debugger.d.ts +0 -25
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, Inject, Injectable, APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
|
|
2
|
+
import { VERSION, InjectionToken, Inject, Injectable, APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
|
|
3
3
|
import { HttpResponse, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
4
4
|
import { finalize, interval, startWith, tap as tap$1 } from 'rxjs';
|
|
5
5
|
import { tap } from 'rxjs/operators';
|
|
6
6
|
import { NavigationStart, NavigationEnd, NavigationCancel, Router } from '@angular/router';
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
(function (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var TraceType;
|
|
9
|
+
(function (TraceType) {
|
|
10
|
+
TraceType[TraceType["MAIN_SES"] = 1] = "MAIN_SES";
|
|
11
|
+
TraceType[TraceType["HTTP_REQ"] = 10] = "HTTP_REQ";
|
|
12
|
+
TraceType[TraceType["LCL_RQT"] = 99] = "LCL_RQT";
|
|
13
|
+
})(TraceType || (TraceType = {}));
|
|
14
|
+
var Mask;
|
|
15
|
+
(function (Mask) {
|
|
16
|
+
Mask[Mask["LOCAL"] = 1] = "LOCAL";
|
|
17
|
+
Mask[Mask["REST"] = 4] = "REST";
|
|
18
|
+
Mask[Mask["EVENT"] = 1024] = "EVENT";
|
|
19
|
+
})(Mask || (Mask = {}));
|
|
13
20
|
const TRACE_TYPE_LOG = '00';
|
|
14
21
|
const TRACE_TYPE_RESOURCE_USAGE = '01';
|
|
15
22
|
const TRACE_TYPE_COLLECTOR_CONFIGURATION = '02';
|
|
16
23
|
const TRACE_TYPE_SESSION_MASK_UPDATE = '03';
|
|
24
|
+
const TRACE_TYPE_EXCEPTION = '05';
|
|
17
25
|
const TRACE_TYPE_MAIN_SESSION = '10';
|
|
18
26
|
const TRACE_TYPE_MAIN_SESSION_CALLBACK = '11';
|
|
19
27
|
const TRACE_TYPE_LOCAL_REQUEST = '110';
|
|
@@ -21,52 +29,15 @@ const TRACE_TYPE_LOCAL_REQUEST_CALLBACK = '111';
|
|
|
21
29
|
const TRACE_TYPE_REST_REQUEST = '120';
|
|
22
30
|
const TRACE_TYPE_REST_REQUEST_CALLBACK = '121';
|
|
23
31
|
const TRACE_TYPE_HTTP_REQUEST_STAGE = '220';
|
|
24
|
-
const
|
|
32
|
+
const TRACE_TYPE_SESSION_EVENT = '06';
|
|
33
|
+
const TRACE_TYPE_ADDITIONAL_VALUES = '400';
|
|
25
34
|
function dateNow() {
|
|
26
35
|
return Date.now() / 1_000;
|
|
27
36
|
}
|
|
28
37
|
|
|
29
|
-
const eventTarget = new EventTarget();
|
|
30
|
-
const TRACE = 'trace', EXPORT = 'export', SHUTDOWN = 'shutdown', RELOAD = 'reload';
|
|
31
|
-
const WIN = window;
|
|
32
|
-
function dispatchReport(message, error) {
|
|
33
|
-
dispatchLog("REPORT", `${message} ${error && JSON.stringify(error)}`);
|
|
34
|
-
}
|
|
35
|
-
function dispatchLog(level, message, sessionId) {
|
|
36
|
-
dispatchTraces({
|
|
37
|
-
"@type": TRACE_TYPE_LOG,
|
|
38
|
-
level: level,
|
|
39
|
-
message: message,
|
|
40
|
-
instant: dateNow(),
|
|
41
|
-
sessionId: sessionId
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function dispatchTraces(...traces) {
|
|
45
|
-
eventTarget.dispatchEvent(new CustomEvent(TRACE, { detail: { traces } }));
|
|
46
|
-
}
|
|
47
|
-
function dispatchExport() {
|
|
48
|
-
eventTarget.dispatchEvent(new CustomEvent(EXPORT));
|
|
49
|
-
}
|
|
50
|
-
function dispatchReload() {
|
|
51
|
-
eventTarget.dispatchEvent(new CustomEvent(RELOAD));
|
|
52
|
-
}
|
|
53
|
-
function dispatchShutown() {
|
|
54
|
-
eventTarget.dispatchEvent(new CustomEvent(SHUTDOWN));
|
|
55
|
-
}
|
|
56
|
-
function addTraceListener(fn) {
|
|
57
|
-
eventTarget.addEventListener(TRACE, fn);
|
|
58
|
-
}
|
|
59
|
-
function addExportListener(fn) {
|
|
60
|
-
eventTarget.addEventListener(EXPORT, fn);
|
|
61
|
-
}
|
|
62
|
-
function addReloadListener(fn) {
|
|
63
|
-
eventTarget.addEventListener(RELOAD, fn);
|
|
64
|
-
}
|
|
65
|
-
function addShutdownListener(fn) {
|
|
66
|
-
eventTarget.addEventListener(SHUTDOWN, fn);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
38
|
const HOST_PATERN = /https?:\/\/[\w\-.]+(:\d{2,5})?\/?/;
|
|
39
|
+
const DEFAULT_QUEUE_CAPACITY = 1000;
|
|
40
|
+
const DEFAULT_INTERVAL = 60_000;
|
|
70
41
|
function getOrCall(o) {
|
|
71
42
|
return typeof o === "function" ? o() : o;
|
|
72
43
|
}
|
|
@@ -100,69 +71,107 @@ function require$1(v, name) {
|
|
|
100
71
|
throw new Error(`${name} property is required`);
|
|
101
72
|
}
|
|
102
73
|
function adaptedConfig(conf) {
|
|
74
|
+
const collector = conf.collector ?? {};
|
|
75
|
+
const application = collector.application;
|
|
76
|
+
const remote = collector.tracing?.remote;
|
|
77
|
+
const pathExcludes = getOrCall(collector.monitoring?.httpRoute?.excludes?.path);
|
|
78
|
+
const { token: _token, ...publicRemote } = remote ?? {};
|
|
103
79
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
80
|
+
collector: {
|
|
81
|
+
...collector,
|
|
82
|
+
additionalProperties: collector.additionalProperties?.(),
|
|
83
|
+
application: application ? {
|
|
84
|
+
...application,
|
|
85
|
+
name: getOrCall(application.name),
|
|
86
|
+
namespace: getOrCall(application.namespace),
|
|
87
|
+
version: getOrCall(application.version),
|
|
88
|
+
env: getOrCall(application.env),
|
|
89
|
+
user: getOrCall(application.user),
|
|
90
|
+
branche: getOrCall(application.branche),
|
|
91
|
+
hash: getOrCall(application.hash)
|
|
92
|
+
} : undefined,
|
|
93
|
+
scheduling: {
|
|
94
|
+
...collector.scheduling,
|
|
95
|
+
interval: (collector.scheduling?.interval ?? DEFAULT_INTERVAL) / 1000,
|
|
96
|
+
queueCapacity: collector.scheduling?.queueCapacity ?? DEFAULT_QUEUE_CAPACITY
|
|
97
|
+
},
|
|
98
|
+
monitoring: {
|
|
99
|
+
...collector.monitoring,
|
|
100
|
+
...(collector.monitoring?.httpRoute ? {
|
|
101
|
+
httpRoute: {
|
|
102
|
+
...collector.monitoring.httpRoute,
|
|
103
|
+
excludes: {
|
|
104
|
+
...collector.monitoring.httpRoute.excludes,
|
|
105
|
+
...(pathExcludes ? { path: pathExcludes.map(regex => regex.source) } : {})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} : {})
|
|
109
|
+
},
|
|
110
|
+
tracing: {
|
|
111
|
+
...collector.tracing,
|
|
112
|
+
remote: {
|
|
113
|
+
...publicRemote,
|
|
114
|
+
'@type': TRACE_TYPE_COLLECTOR_CONFIGURATION,
|
|
115
|
+
retentionMaxAge: {
|
|
116
|
+
audit: (remote?.retentionMaxAge?.audit ?? 7) * 60 * 60 * 24,
|
|
117
|
+
diagnostics: (remote?.retentionMaxAge?.diagnostics ?? 10) * 60 * 60 * 24
|
|
118
|
+
}
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
|
-
},
|
|
123
|
-
tracing: {
|
|
124
|
-
...conf.tracing,
|
|
125
|
-
remote: {
|
|
126
|
-
...conf.tracing?.remote,
|
|
127
|
-
'@type': TRACE_TYPE_COLLECTOR_CONFIGURATION,
|
|
128
|
-
retentionMaxAge: (conf.tracing?.remote?.retentionMaxAge ?? 10) * 60 * 60 * 24
|
|
129
|
-
}
|
|
130
121
|
}
|
|
131
122
|
};
|
|
132
123
|
}
|
|
133
124
|
function validateAndGetConfig(conf, instanceId) {
|
|
134
|
-
const
|
|
125
|
+
const collector = conf.collector;
|
|
126
|
+
const application = collector?.application;
|
|
127
|
+
const remote = collector?.tracing?.remote;
|
|
128
|
+
const host = matchRegex(getOrCall(remote?.host), "host", HOST_PATERN, "http://localhost");
|
|
135
129
|
return {
|
|
136
|
-
user:
|
|
137
|
-
queueCapacity: requirePostitiveValue(getOrCall(
|
|
138
|
-
interval: requirePostitiveValue(getOrCall(
|
|
139
|
-
instanceApi: new URL('
|
|
140
|
-
sessionApi: new URL(`
|
|
141
|
-
exclude: getOrCall(
|
|
142
|
-
hostExcludes:
|
|
143
|
-
debugMode: !!
|
|
144
|
-
analytics: !!
|
|
145
|
-
resources: !!
|
|
146
|
-
storage: !!
|
|
147
|
-
|
|
130
|
+
user: getOrCall(application?.user),
|
|
131
|
+
queueCapacity: requirePostitiveValue(getOrCall(collector?.scheduling?.queueCapacity), "queueCapacity", DEFAULT_QUEUE_CAPACITY),
|
|
132
|
+
interval: requirePostitiveValue(getOrCall(collector?.scheduling?.interval), "interval", DEFAULT_INTERVAL),
|
|
133
|
+
instanceApi: new URL('v5/trace/instance', host).href,
|
|
134
|
+
sessionApi: new URL(`v5/trace/instance/${instanceId}/session`, host).href,
|
|
135
|
+
exclude: getOrCall(collector?.monitoring?.httpRoute?.excludes?.path) || [],
|
|
136
|
+
hostExcludes: collector?.monitoring?.httpRequest?.excludes?.host || [],
|
|
137
|
+
debugMode: !!collector?.debugMode,
|
|
138
|
+
analytics: !!collector?.monitoring?.analytics?.enabled,
|
|
139
|
+
resources: !!collector?.monitoring?.resources?.enabled,
|
|
140
|
+
storage: !!collector?.monitoring?.storage?.enabled,
|
|
141
|
+
logger: !!collector?.monitoring?.logger?.enabled,
|
|
142
|
+
reporter: !!collector?.monitoring?.reporter?.enabled,
|
|
143
|
+
namespaceHeader: "basic " + btoa(`${require$1(getOrCall(application?.namespace), 'configuration.collector.application.namespace')}:${getOrCall(remote?.token) ?? ""}`),
|
|
144
|
+
enabled: !!collector?.enabled
|
|
148
145
|
};
|
|
149
146
|
}
|
|
150
147
|
function createInstance(conf, instanceId) {
|
|
148
|
+
const collector = conf.collector;
|
|
149
|
+
const application = collector?.application;
|
|
150
|
+
const branche = getOrCall(application?.branche);
|
|
151
|
+
const hash = getOrCall(application?.hash);
|
|
151
152
|
return {
|
|
152
153
|
id: instanceId,
|
|
153
154
|
instant: dateNow(),
|
|
154
|
-
name: require$1(getOrCall(
|
|
155
|
-
version: getOrCall(
|
|
155
|
+
name: require$1(getOrCall(application?.name), 'configuration.collector.application.name'),
|
|
156
|
+
version: getOrCall(application?.version),
|
|
156
157
|
address: getClientID(), //server side
|
|
157
|
-
env: require$1(getOrCall(
|
|
158
|
+
env: require$1(getOrCall(application?.env), 'configuration.collector.application.env'),
|
|
158
159
|
os: detectOs(),
|
|
159
160
|
re: detectBrowser(),
|
|
160
161
|
user: undefined, // cannot get user
|
|
161
162
|
type: "CLIENT",
|
|
162
|
-
collector: "inspect-ng-collector-1.3.
|
|
163
|
-
resource: { maxHeap: (('memory' in performance) && performance.memory.jsHeapSizeLimit / (1024 * 1024)) || undefined
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
collector: "inspect-ng-collector-1.3.4",
|
|
164
|
+
resource: { maxHeap: (('memory' in performance) && performance.memory.jsHeapSizeLimit / (1024 * 1024)) || undefined,
|
|
165
|
+
availableProcessors: navigator.hardwareConcurrency },
|
|
166
|
+
additionalProperties: {
|
|
167
|
+
...collector?.additionalProperties?.(),
|
|
168
|
+
...(branche !== undefined ? { branche } : {}),
|
|
169
|
+
...(hash !== undefined ? { hash } : {}),
|
|
170
|
+
'user.locale': navigator.language + '~' + Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
171
|
+
'angular.version': VERSION.full
|
|
172
|
+
},
|
|
173
|
+
configuration: adaptedConfig(conf),
|
|
174
|
+
namespace: require$1(getOrCall(application?.namespace), 'configuration.collector.application.namespace'),
|
|
166
175
|
};
|
|
167
176
|
}
|
|
168
177
|
function getClientID() {
|
|
@@ -222,10 +231,132 @@ function refreshConfig(id, tech) {
|
|
|
222
231
|
tech.sessionApi = tech.sessionApi.replace(uuidRegex, id);
|
|
223
232
|
return id;
|
|
224
233
|
}
|
|
234
|
+
function createException(error, traceId, traceType, parseStack = false) {
|
|
235
|
+
try {
|
|
236
|
+
const isError = error instanceof Error;
|
|
237
|
+
let message;
|
|
238
|
+
if (typeof error === "string") {
|
|
239
|
+
message = error;
|
|
240
|
+
}
|
|
241
|
+
else if (isError) {
|
|
242
|
+
message = error.message;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
message = JSON.stringify(error);
|
|
246
|
+
}
|
|
247
|
+
if (isError) {
|
|
248
|
+
return {
|
|
249
|
+
'@type': TRACE_TYPE_EXCEPTION,
|
|
250
|
+
type: isError ? error.name : undefined,
|
|
251
|
+
message,
|
|
252
|
+
stackTraceRows: parseStack ? parseStackTrace(error.stack) : undefined,
|
|
253
|
+
traceId,
|
|
254
|
+
traceType,
|
|
255
|
+
offset: dateNow()
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return {
|
|
260
|
+
'@type': TRACE_TYPE_EXCEPTION,
|
|
261
|
+
type: isError ? error.name : undefined,
|
|
262
|
+
message,
|
|
263
|
+
stackTraceRows: parseStack ? parseStackTrace(undefined) : undefined,
|
|
264
|
+
traceId,
|
|
265
|
+
traceType,
|
|
266
|
+
offset: dateNow()
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
dispatchReport("createException", e);
|
|
272
|
+
}
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
function parseStackTrace(stack) {
|
|
276
|
+
try {
|
|
277
|
+
if (!stack) {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
const rows = stack.split('\n').slice(1).flatMap(line => {
|
|
281
|
+
const match = /^at\s+(?:(.*?)\s+\()?(.+):(\d+):(\d+)\)?$/.exec(line.trim());
|
|
282
|
+
if (!match) {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
return [{
|
|
286
|
+
className: match[2],
|
|
287
|
+
methodName: match[1] || undefined,
|
|
288
|
+
lineNumber: Number(match[3])
|
|
289
|
+
}];
|
|
290
|
+
});
|
|
291
|
+
return rows.length > 0 ? rows : undefined;
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
dispatchReport("parseStackTrace", e);
|
|
295
|
+
}
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const eventTarget = new EventTarget();
|
|
300
|
+
const TRACE = 'trace', EXPORT = 'export', SHUTDOWN = 'shutdown', RELOAD = 'reload';
|
|
301
|
+
let reporterEnabled = false;
|
|
302
|
+
const WIN = globalThis;
|
|
303
|
+
WIN["event-bus"] = eventTarget;
|
|
304
|
+
function configureReporter(enabled) {
|
|
305
|
+
reporterEnabled = enabled;
|
|
306
|
+
}
|
|
307
|
+
function dispatchReport(message, error) {
|
|
308
|
+
if (!reporterEnabled) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
dispatchTraces({
|
|
312
|
+
"@type": TRACE_TYPE_LOG,
|
|
313
|
+
instant: dateNow(),
|
|
314
|
+
message: `${message} ${error && JSON.stringify(error)}`,
|
|
315
|
+
stackTraceRows: parseStackTrace(error.stack ? error.stack : undefined),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function dispatchLog(type, value, sessionId) {
|
|
319
|
+
dispatchTraces({
|
|
320
|
+
"@type": TRACE_TYPE_SESSION_EVENT,
|
|
321
|
+
type: type,
|
|
322
|
+
value: value,
|
|
323
|
+
instant: dateNow(),
|
|
324
|
+
//location: null,
|
|
325
|
+
sessionId: sessionId
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function dispatchTraces(...traces) {
|
|
329
|
+
eventTarget.dispatchEvent(new CustomEvent(TRACE, { detail: { traces } }));
|
|
330
|
+
}
|
|
331
|
+
function dispatchExport() {
|
|
332
|
+
eventTarget.dispatchEvent(new CustomEvent(EXPORT));
|
|
333
|
+
}
|
|
334
|
+
function dispatchReload() {
|
|
335
|
+
eventTarget.dispatchEvent(new CustomEvent(RELOAD));
|
|
336
|
+
}
|
|
337
|
+
function dispatchShutown() {
|
|
338
|
+
eventTarget.dispatchEvent(new CustomEvent(SHUTDOWN));
|
|
339
|
+
}
|
|
340
|
+
function addTraceListener(fn) {
|
|
341
|
+
eventTarget.addEventListener(TRACE, fn);
|
|
342
|
+
return () => eventTarget.removeEventListener(TRACE, fn);
|
|
343
|
+
}
|
|
344
|
+
function addExportListener(fn) {
|
|
345
|
+
eventTarget.addEventListener(EXPORT, fn);
|
|
346
|
+
}
|
|
347
|
+
function addReloadListener(fn) {
|
|
348
|
+
eventTarget.addEventListener(RELOAD, fn);
|
|
349
|
+
return () => eventTarget.removeEventListener(RELOAD, fn);
|
|
350
|
+
}
|
|
351
|
+
function addShutdownListener(fn) {
|
|
352
|
+
eventTarget.addEventListener(SHUTDOWN, fn);
|
|
353
|
+
return () => eventTarget.removeEventListener(SHUTDOWN, fn);
|
|
354
|
+
}
|
|
225
355
|
|
|
226
356
|
class SessionManager {
|
|
227
357
|
constructor(_techConfig) {
|
|
228
358
|
this._techConfig = _techConfig;
|
|
359
|
+
this.validatedSessions = new WeakSet();
|
|
229
360
|
}
|
|
230
361
|
static get instance() {
|
|
231
362
|
return SessionManager._instance;
|
|
@@ -244,14 +375,17 @@ class SessionManager {
|
|
|
244
375
|
user: getOrCall(this._techConfig.user),
|
|
245
376
|
start: now,
|
|
246
377
|
location: url,
|
|
247
|
-
|
|
378
|
+
eventMask: 0,
|
|
379
|
+
status: 200,
|
|
248
380
|
};
|
|
249
381
|
this.currentSessionCallBack = {
|
|
250
382
|
'@type': TRACE_TYPE_MAIN_SESSION_CALLBACK,
|
|
251
383
|
id: id,
|
|
252
|
-
|
|
384
|
+
eventMask: 0,
|
|
385
|
+
status: 200
|
|
253
386
|
};
|
|
254
387
|
}
|
|
388
|
+
return this.currentSession;
|
|
255
389
|
}
|
|
256
390
|
endSession(end) {
|
|
257
391
|
this.getCurrentSessionCallBack(call => {
|
|
@@ -260,16 +394,33 @@ class SessionManager {
|
|
|
260
394
|
});
|
|
261
395
|
this.currentSessionCallBack = undefined;
|
|
262
396
|
}
|
|
263
|
-
|
|
264
|
-
|
|
397
|
+
validateSession(update = true, timeout = Number.NaN) {
|
|
398
|
+
const s = this.currentSession;
|
|
399
|
+
if (Number.isNaN(timeout)) {
|
|
400
|
+
this.updateSession(s, false);
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
setTimeout(() => this.updateSession(s, true), 0);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
updateSession(session, update = true) {
|
|
407
|
+
if (session) {
|
|
408
|
+
if (this.validatedSessions.has(session))
|
|
409
|
+
return;
|
|
410
|
+
this.validatedSessions.add(session);
|
|
265
411
|
if (update) {
|
|
266
|
-
|
|
267
|
-
|
|
412
|
+
session.name = document.title;
|
|
413
|
+
session.location = document.URL;
|
|
268
414
|
}
|
|
269
|
-
|
|
270
|
-
|
|
415
|
+
else {
|
|
416
|
+
session.name = '<startup>';
|
|
417
|
+
}
|
|
418
|
+
if (!this._techConfig.exclude?.some((e) => e.test(session?.location))) {
|
|
419
|
+
dispatchTraces(session);
|
|
420
|
+
}
|
|
421
|
+
if (session === this.currentSession) {
|
|
422
|
+
this.currentSession = undefined;
|
|
271
423
|
}
|
|
272
|
-
this.currentSession = undefined;
|
|
273
424
|
}
|
|
274
425
|
else {
|
|
275
426
|
dispatchReport('updateSession', 'no active session');
|
|
@@ -285,28 +436,27 @@ class SessionManager {
|
|
|
285
436
|
currentSessionID() {
|
|
286
437
|
return this.getCurrentSessionCallBack(s => s.id);
|
|
287
438
|
}
|
|
288
|
-
|
|
439
|
+
markSessionFailed() {
|
|
440
|
+
return this.getCurrentSessionCallBack(s => {
|
|
441
|
+
s.status = 400;
|
|
442
|
+
return s.id;
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
traceSessionMaskUpdate(mask) {
|
|
289
446
|
const req = this.getCurrentSessionCallBack(s => {
|
|
290
|
-
if ((s.
|
|
291
|
-
s.
|
|
447
|
+
if ((s.eventMask & mask) !== mask) {
|
|
448
|
+
s.eventMask |= mask;
|
|
292
449
|
dispatchTraces({
|
|
293
450
|
"@type": TRACE_TYPE_SESSION_MASK_UPDATE,
|
|
294
451
|
id: s.id,
|
|
295
452
|
main: true,
|
|
296
|
-
mask: s.
|
|
453
|
+
mask: s.eventMask
|
|
297
454
|
});
|
|
298
455
|
}
|
|
299
456
|
return { sessionId: s.id };
|
|
300
457
|
});
|
|
301
458
|
return req || {};
|
|
302
459
|
}
|
|
303
|
-
initUserAction() {
|
|
304
|
-
const req = this.getCurrentSessionCallBack(s => ({ sessionId: s.id }));
|
|
305
|
-
return req || {};
|
|
306
|
-
}
|
|
307
|
-
addException(exception) {
|
|
308
|
-
this.getCurrentSessionCallBack(s => s.exception = exception);
|
|
309
|
-
}
|
|
310
460
|
info(message) {
|
|
311
461
|
this.log("INFO", message);
|
|
312
462
|
}
|
|
@@ -316,9 +466,9 @@ class SessionManager {
|
|
|
316
466
|
error(message) {
|
|
317
467
|
this.log("ERROR", message);
|
|
318
468
|
}
|
|
319
|
-
log(
|
|
469
|
+
log(type, message) {
|
|
320
470
|
if (message) {
|
|
321
|
-
this.getCurrentSessionCallBack(s => dispatchLog(
|
|
471
|
+
this.getCurrentSessionCallBack(s => dispatchLog(type, message, this.traceSessionMaskUpdate(Mask.EVENT).sessionId)); // update mask
|
|
322
472
|
}
|
|
323
473
|
}
|
|
324
474
|
}
|
|
@@ -330,7 +480,7 @@ function sessionManager(tech) {
|
|
|
330
480
|
WIN["inspect-session-manager"] = SessionManager._instance;
|
|
331
481
|
}
|
|
332
482
|
|
|
333
|
-
const TRACE_HEADER = '
|
|
483
|
+
const TRACE_HEADER = 'Inspect-Trace-Id';
|
|
334
484
|
class RestRequestMonitor {
|
|
335
485
|
constructor() {
|
|
336
486
|
this.start = dateNow();
|
|
@@ -339,7 +489,7 @@ class RestRequestMonitor {
|
|
|
339
489
|
preProcess(restRequest) {
|
|
340
490
|
const url = new URL(restRequest.urlWithParams, globalThis.location.origin);
|
|
341
491
|
const auth_user = extractAuthSchemeAnduser(restRequest.headers);
|
|
342
|
-
dispatchTraces({ ...SessionManager.instance.
|
|
492
|
+
dispatchTraces({ ...SessionManager.instance.traceSessionMaskUpdate(Mask.REST),
|
|
343
493
|
"@type": TRACE_TYPE_REST_REQUEST,
|
|
344
494
|
id: this.id,
|
|
345
495
|
method: restRequest.method,
|
|
@@ -374,15 +524,15 @@ class RestRequestMonitor {
|
|
|
374
524
|
}
|
|
375
525
|
// Erreur réseau/annulation
|
|
376
526
|
if (error) {
|
|
377
|
-
status = error
|
|
378
|
-
exception =
|
|
379
|
-
type: error.name,
|
|
380
|
-
message: error.error && error.status ? JSON.stringify(error.error) : error.message
|
|
381
|
-
};
|
|
527
|
+
status = retrieveStatus(error);
|
|
528
|
+
exception = createException(error, this.id, TraceType.HTTP_REQ, false);
|
|
382
529
|
callback.bodyContent = JSON.stringify(error.error);
|
|
383
530
|
callback.dataSize = sizeOf(error.error);
|
|
384
531
|
callback.contentType = extractContentType(error.headers);
|
|
385
532
|
callback.linked = assertSessionID(this.id, error.headers);
|
|
533
|
+
if (exception) {
|
|
534
|
+
dispatchTraces(exception);
|
|
535
|
+
}
|
|
386
536
|
}
|
|
387
537
|
callback.status = status;
|
|
388
538
|
dispatchTraces(callback, {
|
|
@@ -396,6 +546,13 @@ class RestRequestMonitor {
|
|
|
396
546
|
});
|
|
397
547
|
}
|
|
398
548
|
}
|
|
549
|
+
function retrieveStatus(error) {
|
|
550
|
+
if (!error.status) {
|
|
551
|
+
if (error.name === 'TimeoutError')
|
|
552
|
+
return 3;
|
|
553
|
+
}
|
|
554
|
+
return error.status || 0;
|
|
555
|
+
}
|
|
399
556
|
function assertSessionID(id, headers) {
|
|
400
557
|
return headers?.get(TRACE_HEADER) == id;
|
|
401
558
|
}
|
|
@@ -419,7 +576,7 @@ function extractUser(scheme, authorization) {
|
|
|
419
576
|
case "Basic":
|
|
420
577
|
return atob(authorization).split(':')[0] || undefined;
|
|
421
578
|
case "Bearer": {
|
|
422
|
-
const payloadMatch =
|
|
579
|
+
const payloadMatch = new RegExp(/^[^.]+\.([^.]+)\.[^.]+$/).exec(authorization);
|
|
423
580
|
if (payloadMatch?.[1]) {
|
|
424
581
|
return JSON.parse(atob(payloadMatch[1])).sub;
|
|
425
582
|
}
|
|
@@ -509,15 +666,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
509
666
|
class GlobalErrorHandler {
|
|
510
667
|
handleError(error) {
|
|
511
668
|
try {
|
|
512
|
-
SessionManager.instance.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
669
|
+
let ex = createException(error, SessionManager.instance.markSessionFailed(), TraceType.MAIN_SES, true);
|
|
670
|
+
if (ex) {
|
|
671
|
+
dispatchTraces(ex);
|
|
672
|
+
}
|
|
516
673
|
}
|
|
517
674
|
catch (e) {
|
|
518
675
|
dispatchReport("GlobalErrorHandlerService.handleError", e);
|
|
519
676
|
}
|
|
520
|
-
throw error;
|
|
521
677
|
}
|
|
522
678
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: GlobalErrorHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
523
679
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: GlobalErrorHandler, providedIn: 'root' }); }
|
|
@@ -532,9 +688,12 @@ class EventTraceScheduledDispatcherService {
|
|
|
532
688
|
constructor(_techConfig) {
|
|
533
689
|
this._techConfig = _techConfig;
|
|
534
690
|
this.traceQueue = [];
|
|
691
|
+
this.lastPacket = null;
|
|
535
692
|
this.dispatchAttempts = 0;
|
|
693
|
+
this.dispatchSequence = 0;
|
|
536
694
|
this.dispatching = false;
|
|
537
695
|
this.instanceDispatched = false;
|
|
696
|
+
this.instanceDispatching = false; // guard contre les appels concurrents
|
|
538
697
|
this.wasDestroyed = false;
|
|
539
698
|
this.subscription = interval(_techConfig.interval)
|
|
540
699
|
.pipe(startWith(0))
|
|
@@ -544,13 +703,13 @@ class EventTraceScheduledDispatcherService {
|
|
|
544
703
|
dispatchExport();
|
|
545
704
|
this.dispatch()
|
|
546
705
|
.then(arr => this.revertQueueSize(arr))
|
|
547
|
-
.catch(
|
|
706
|
+
.catch(() => { })
|
|
548
707
|
.finally(() => { this.dispatching = false; });
|
|
549
708
|
}
|
|
550
709
|
}))
|
|
551
710
|
.subscribe();
|
|
552
|
-
addTraceListener(e => this.appendTrace(e.detail.traces));
|
|
553
|
-
addShutdownListener(
|
|
711
|
+
this.removeTraceListener = addTraceListener(e => this.appendTrace(e.detail.traces));
|
|
712
|
+
this.removeShutdownListener = addShutdownListener(() => this.destroy());
|
|
554
713
|
}
|
|
555
714
|
appendTrace(events) {
|
|
556
715
|
if (!this.wasDestroyed) {
|
|
@@ -558,70 +717,150 @@ class EventTraceScheduledDispatcherService {
|
|
|
558
717
|
}
|
|
559
718
|
}
|
|
560
719
|
trace(instance) {
|
|
561
|
-
this.instance = instance;
|
|
720
|
+
this.instance = { ...instance };
|
|
721
|
+
this.updateInstance(); // Dispatch immédiatement au lieu d'attendre l'intervalle
|
|
722
|
+
}
|
|
723
|
+
updateInstance() {
|
|
724
|
+
if (this.instanceDispatched || this.instanceDispatching || this.wasDestroyed || !this.instance) {
|
|
725
|
+
return Promise.resolve(); // Déjà dispatché, en cours, ou pas prêt
|
|
726
|
+
}
|
|
727
|
+
this.instanceDispatching = true;
|
|
728
|
+
return this.dispatchInstance()
|
|
729
|
+
.then(success => {
|
|
730
|
+
if (success) {
|
|
731
|
+
this.instanceDispatched = true;
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
console.warn(`Error while attempting to send Environement instance, attempts ${this.dispatchAttempts}`);
|
|
735
|
+
}
|
|
736
|
+
})
|
|
737
|
+
.finally(() => { this.instanceDispatching = false; });
|
|
562
738
|
}
|
|
563
739
|
dispatch() {
|
|
564
740
|
if (this.instanceDispatched) {
|
|
565
741
|
return this.dispatchTraces();
|
|
566
742
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
return Promise.reject(new Error('No instance id'));
|
|
743
|
+
if (this.instanceDispatching)
|
|
744
|
+
return Promise.resolve(EMPTY_ARRAY); // attendre
|
|
745
|
+
return this.updateInstance().then(() => {
|
|
746
|
+
if (this.instanceDispatched)
|
|
747
|
+
return this.dispatchTraces(); // seulement si confirmé
|
|
748
|
+
return Promise.reject(new Error('Instance not dispatched yet')); // instance pas encore dispatchée, traces non envoyées
|
|
574
749
|
});
|
|
575
750
|
}
|
|
576
|
-
dispatchTraces(destroy) {
|
|
577
|
-
if (this.
|
|
751
|
+
dispatchTraces(destroy = false) {
|
|
752
|
+
if (this.wasDestroyed && !destroy) {
|
|
578
753
|
return Promise.resolve(EMPTY_ARRAY);
|
|
579
754
|
}
|
|
580
|
-
|
|
755
|
+
if (!this.inFlightDispatch) {
|
|
756
|
+
const request = this.lastPacket !== null
|
|
757
|
+
? this.dispatchPrevious(destroy && this.traceQueue.length === 0).then(() => EMPTY_ARRAY)
|
|
758
|
+
: this.dispatchQueuedTraces(destroy);
|
|
759
|
+
this.inFlightDispatch = request.finally(() => { this.inFlightDispatch = undefined; });
|
|
760
|
+
}
|
|
761
|
+
if (destroy && this.traceQueue.length > 0) {
|
|
762
|
+
// L'envoi keepalive en cours garde son paquet ; seules les nouvelles traces partent ici.
|
|
763
|
+
return Promise.all([this.inFlightDispatch, this.dispatchQueuedTraces(true)]).then(() => EMPTY_ARRAY);
|
|
764
|
+
}
|
|
765
|
+
return this.inFlightDispatch;
|
|
766
|
+
}
|
|
767
|
+
async dispatchQueuedTraces(destroy) {
|
|
768
|
+
if (this.traceQueue.length === 0) {
|
|
769
|
+
return EMPTY_ARRAY;
|
|
770
|
+
}
|
|
771
|
+
const packet = {
|
|
772
|
+
body: JSON.stringify(this.traceQueue),
|
|
773
|
+
sequence: ++this.dispatchSequence,
|
|
774
|
+
size: this.traceQueue.length
|
|
775
|
+
};
|
|
776
|
+
let uri = this._techConfig.sessionApi + "?atm=" + ++this.dispatchAttempts + "&seq=" + packet.sequence;
|
|
581
777
|
if (destroy) {
|
|
582
778
|
uri += "&end=" + new Date().toISOString();
|
|
583
779
|
}
|
|
584
|
-
const traces = [...this.traceQueue];
|
|
585
780
|
this.traceQueue.length = 0;
|
|
586
781
|
return fetch(uri, {
|
|
587
782
|
method: 'PUT',
|
|
588
|
-
headers: { 'Content-Type': 'application/json' },
|
|
783
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': this._techConfig.namespaceHeader },
|
|
589
784
|
mode: 'cors',
|
|
590
785
|
keepalive: true,
|
|
591
|
-
body:
|
|
786
|
+
body: packet.body
|
|
592
787
|
})
|
|
593
788
|
.then(res => {
|
|
594
|
-
if (res.ok) {
|
|
789
|
+
if (res.ok || res.status === 409) {
|
|
595
790
|
this.dispatchAttempts = 0;
|
|
596
791
|
return EMPTY_ARRAY;
|
|
597
792
|
}
|
|
598
793
|
console.warn(`Error while attempting to send sessions, attempts: ${this.dispatchAttempts}`);
|
|
599
|
-
if (res.status
|
|
600
|
-
|
|
794
|
+
if (res.status === 429 || (res.status >= 500 && res.headers?.get('Inspect-Trace-Retry') === '1')) {
|
|
795
|
+
console.warn('Dispatch failed with status', res.status, 'retrying...');
|
|
796
|
+
this.lastPacket = packet;
|
|
601
797
|
}
|
|
602
|
-
return
|
|
603
|
-
.then(body => body?.retry ? traces : EMPTY_ARRAY)
|
|
604
|
-
.catch(() => EMPTY_ARRAY);
|
|
798
|
+
return EMPTY_ARRAY; // retry on 3XX
|
|
605
799
|
})
|
|
606
800
|
.catch(() => {
|
|
607
801
|
console.warn(`Error while attempting to send sessions, attempts: ${this.dispatchAttempts}`); //no cnx !
|
|
608
|
-
|
|
802
|
+
this.lastPacket = packet;
|
|
803
|
+
return EMPTY_ARRAY;
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
async dispatchPrevious(destroy = false) {
|
|
807
|
+
const packet = this.lastPacket;
|
|
808
|
+
if (!packet)
|
|
809
|
+
return;
|
|
810
|
+
let uri = this._techConfig.sessionApi + "?atm=" + ++this.dispatchAttempts + "&seq=" + packet.sequence;
|
|
811
|
+
if (destroy) {
|
|
812
|
+
uri += "&end=" + new Date().toISOString();
|
|
813
|
+
}
|
|
814
|
+
return fetch(uri, {
|
|
815
|
+
method: 'PUT',
|
|
816
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': this._techConfig.namespaceHeader },
|
|
817
|
+
mode: 'cors',
|
|
818
|
+
keepalive: true,
|
|
819
|
+
body: packet.body
|
|
820
|
+
}).then(res => {
|
|
821
|
+
if (res.ok || res.status === 409) {
|
|
822
|
+
if (this.lastPacket === packet)
|
|
823
|
+
this.lastPacket = null;
|
|
824
|
+
this.dispatchAttempts = 0;
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
console.warn(`Error while attempting to send sessions, attempts: ${this.dispatchAttempts}`);
|
|
828
|
+
if (res.status >= 500) {
|
|
829
|
+
dispatchReport('EventTraceScheduledDispatcher.dispatchPrevious', res);
|
|
830
|
+
}
|
|
831
|
+
}).catch(() => {
|
|
832
|
+
console.warn(`Error while attempting to send sessions, attempts: ${this.dispatchAttempts}`);
|
|
833
|
+
if (this.lastPacket === packet)
|
|
834
|
+
this.discardLastPacketIfQueueCapacityExceeded();
|
|
609
835
|
});
|
|
610
836
|
}
|
|
837
|
+
discardLastPacketIfQueueCapacityExceeded() {
|
|
838
|
+
if ((this.lastPacket?.size ?? 0) + this.traceQueue.length > this._techConfig.queueCapacity) {
|
|
839
|
+
console.warn(`Error while attempting to send ${this.lastPacket?.size} traces, giving up`);
|
|
840
|
+
this.lastPacket = null;
|
|
841
|
+
this.dispatchAttempts = 0;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
611
844
|
dispatchInstance() {
|
|
612
|
-
this.dispatchAttempts
|
|
613
|
-
return fetch(
|
|
614
|
-
method: '
|
|
615
|
-
headers: { 'Content-Type': 'application/json' },
|
|
845
|
+
const uri = this._techConfig.instanceApi + "?atm=" + ++this.dispatchAttempts;
|
|
846
|
+
return fetch(uri, {
|
|
847
|
+
method: 'PUT',
|
|
848
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': this._techConfig.namespaceHeader },
|
|
616
849
|
mode: 'cors',
|
|
617
850
|
keepalive: true,
|
|
618
851
|
body: JSON.stringify(this.instance)
|
|
619
852
|
})
|
|
620
|
-
.then(res =>
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
853
|
+
.then(res => {
|
|
854
|
+
if (res.ok || res.status === 409) {
|
|
855
|
+
this.dispatchAttempts = 0;
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
858
|
+
if (res.status >= 500) {
|
|
859
|
+
dispatchReport('EventTraceScheduledDispatcher.dispatchInstance', res);
|
|
860
|
+
}
|
|
861
|
+
return false;
|
|
862
|
+
})
|
|
863
|
+
.catch(() => false);
|
|
625
864
|
}
|
|
626
865
|
revertQueueSize(traces) {
|
|
627
866
|
if (!this.wasDestroyed) {
|
|
@@ -632,27 +871,44 @@ class EventTraceScheduledDispatcherService {
|
|
|
632
871
|
}
|
|
633
872
|
}
|
|
634
873
|
destroy() {
|
|
874
|
+
if (this.wasDestroyed) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
635
877
|
this.subscription?.unsubscribe();
|
|
878
|
+
dispatchExport(); // Collecter les dernières métriques avant de refuser les nouvelles traces.
|
|
636
879
|
this.wasDestroyed = true;
|
|
637
|
-
|
|
638
|
-
this.
|
|
880
|
+
this.removeTraceListener();
|
|
881
|
+
this.removeShutdownListener();
|
|
882
|
+
void this.dispatchTraces(true);
|
|
639
883
|
}
|
|
640
884
|
}
|
|
641
885
|
function eventTraceScheduledDispatcher(tech) {
|
|
642
|
-
|
|
886
|
+
EventTraceScheduledDispatcherService._instance?.destroy();
|
|
887
|
+
return EventTraceScheduledDispatcherService._instance = new EventTraceScheduledDispatcherService({ ...tech });
|
|
643
888
|
}
|
|
644
889
|
|
|
645
890
|
const eventHandlers = {
|
|
646
891
|
'click': (target) => lookUpChild(target, 1),
|
|
647
892
|
};
|
|
893
|
+
const RESIZE_IDLE_DELAY = 250;
|
|
894
|
+
const SCROLL_IDLE_DELAY = 250;
|
|
895
|
+
const SELECTION_IDLE_DELAY = 400;
|
|
896
|
+
const CLICK_DELAY = 300;
|
|
897
|
+
const ELEMENT_EVENTS = [
|
|
898
|
+
'click', 'dblclick', 'change',
|
|
899
|
+
];
|
|
900
|
+
let globalBrowserValues = { c: globalThis.devicePixelRatio, o: `${innerWidth}x${innerHeight}` };
|
|
901
|
+
let Timer;
|
|
902
|
+
let selectionTimer;
|
|
903
|
+
const clickTimers = new WeakMap();
|
|
648
904
|
function initUserActionMonitor() {
|
|
649
905
|
try {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
906
|
+
ELEMENT_EVENTS.forEach(type => document.addEventListener(type, globalHandler, true));
|
|
907
|
+
globalThis.addEventListener('scroll', scrollHandler, true); // do costum handler with timeout
|
|
908
|
+
globalThis.addEventListener('resize', resizeHandler, true);
|
|
909
|
+
document.addEventListener('visibilitychange', visibilityHandler);
|
|
910
|
+
document.readyState === 'loading' ? document.addEventListener('DOMContentLoaded', () => { addActionUser('DOMContentLoaded', null); }, { once: true }) : addActionUser('DOMContentLoaded', null);
|
|
911
|
+
traceBrowserConfig();
|
|
656
912
|
}
|
|
657
913
|
catch (e) {
|
|
658
914
|
dispatchReport("initUserActionMonitor", e);
|
|
@@ -662,15 +918,110 @@ function globalHandler(event) {
|
|
|
662
918
|
const target = event.target;
|
|
663
919
|
const eventType = event.type;
|
|
664
920
|
try {
|
|
665
|
-
if (eventHandlers.hasOwnProperty(eventType) && !eventHandlers[eventType](target)) {
|
|
921
|
+
/*if (eventHandlers.hasOwnProperty(eventType) && !eventHandlers[eventType](target)) {
|
|
922
|
+
return;
|
|
923
|
+
} */
|
|
924
|
+
const value = target.attributes.getNamedItem("data-inspect-track")?.value;
|
|
925
|
+
if (!value) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const scope = target.attributes.getNamedItem("data-inspect-scope")?.value;
|
|
929
|
+
const location = target.attributes.getNamedItem("data-inspect-location")?.value;
|
|
930
|
+
if (eventType === 'click') {
|
|
931
|
+
const pendingClick = clickTimers.get(target);
|
|
932
|
+
if (pendingClick) {
|
|
933
|
+
clearTimeout(pendingClick);
|
|
934
|
+
}
|
|
935
|
+
const timer = setTimeout(() => {
|
|
936
|
+
clickTimers.delete(target);
|
|
937
|
+
addActionUser('click', value, scope, location);
|
|
938
|
+
}, CLICK_DELAY);
|
|
939
|
+
clickTimers.set(target, timer);
|
|
666
940
|
return;
|
|
667
941
|
}
|
|
668
|
-
|
|
942
|
+
const pendingClick = clickTimers.get(target);
|
|
943
|
+
if (eventType === 'dblclick' && pendingClick) {
|
|
944
|
+
clearTimeout(pendingClick);
|
|
945
|
+
clickTimers.delete(target);
|
|
946
|
+
}
|
|
947
|
+
addActionUser(eventType, value, scope, location);
|
|
669
948
|
}
|
|
670
949
|
catch (err) {
|
|
671
950
|
dispatchReport("UserACTION.globalHandler", err);
|
|
672
951
|
}
|
|
673
952
|
}
|
|
953
|
+
function addActionUser(eventType, value, scope, location) {
|
|
954
|
+
const at = dateNow();
|
|
955
|
+
dispatchTraces({
|
|
956
|
+
...SessionManager.instance.traceSessionMaskUpdate(Mask.EVENT),
|
|
957
|
+
'@type': TRACE_TYPE_SESSION_EVENT,
|
|
958
|
+
type: eventType,
|
|
959
|
+
instant: at,
|
|
960
|
+
value: value,
|
|
961
|
+
scope: scope,
|
|
962
|
+
location: location
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
function traceBrowserConfig() {
|
|
966
|
+
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
967
|
+
dispatchTraces({
|
|
968
|
+
'@type': TRACE_TYPE_ADDITIONAL_VALUES,
|
|
969
|
+
deviceDisplayResolution: `${screen?.width}x${screen?.height}`,
|
|
970
|
+
deviceOrientation: screen.orientation?.type ?? (innerWidth >= innerHeight ? 'landscape' : 'portrait'),
|
|
971
|
+
deviceConnectivity: connection?.effectiveType ?? 'unknown',
|
|
972
|
+
windowViewportBounds: `${innerWidth}x${innerHeight}`,
|
|
973
|
+
windowZoomLevel: String(visualViewport?.scale ?? devicePixelRatio),
|
|
974
|
+
userLanguage: navigator.language,
|
|
975
|
+
userTheme: matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light',
|
|
976
|
+
saveData: connection?.saveData ?? undefined
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
function resizeHandler() {
|
|
980
|
+
if (Timer) {
|
|
981
|
+
clearTimeout(Timer);
|
|
982
|
+
}
|
|
983
|
+
Timer = setTimeout(() => {
|
|
984
|
+
Timer = undefined;
|
|
985
|
+
const previousRatio = globalBrowserValues.c;
|
|
986
|
+
const currentRatio = globalThis.devicePixelRatio;
|
|
987
|
+
globalBrowserValues.o = `${innerWidth}x${innerHeight}`;
|
|
988
|
+
if (previousRatio !== currentRatio) {
|
|
989
|
+
// Signed delta: '+' when zooming in, '-' when zooming out.
|
|
990
|
+
const delta = Math.round((currentRatio - previousRatio) * 100);
|
|
991
|
+
const sign = delta > 0 ? '+' : '';
|
|
992
|
+
addActionUser('zoom', `${sign}${delta}%`);
|
|
993
|
+
}
|
|
994
|
+
else {
|
|
995
|
+
addActionUser('resize', `${innerWidth}x${innerHeight}`);
|
|
996
|
+
}
|
|
997
|
+
globalBrowserValues.c = currentRatio;
|
|
998
|
+
}, RESIZE_IDLE_DELAY);
|
|
999
|
+
}
|
|
1000
|
+
function scrollHandler() {
|
|
1001
|
+
if (Timer) {
|
|
1002
|
+
clearTimeout(Timer);
|
|
1003
|
+
}
|
|
1004
|
+
Timer = setTimeout(() => {
|
|
1005
|
+
Timer = undefined;
|
|
1006
|
+
addActionUser('scroll', null); // todo to enhance ( vertical / horizontal )
|
|
1007
|
+
}, SCROLL_IDLE_DELAY);
|
|
1008
|
+
}
|
|
1009
|
+
function visibilityHandler() {
|
|
1010
|
+
addActionUser(document.hidden ? 'DOC_HIDDEN' : 'DOC_VISIBLE', null);
|
|
1011
|
+
}
|
|
1012
|
+
// Debounced; only the selection length is reported, never its content (privacy).
|
|
1013
|
+
function selectionHandler() {
|
|
1014
|
+
if (selectionTimer) {
|
|
1015
|
+
clearTimeout(selectionTimer);
|
|
1016
|
+
}
|
|
1017
|
+
selectionTimer = setTimeout(() => {
|
|
1018
|
+
selectionTimer = undefined;
|
|
1019
|
+
const length = document.getSelection ? String(document.getSelection()).length : 0;
|
|
1020
|
+
if (length > 0) {
|
|
1021
|
+
addActionUser('select', `length=${length}`);
|
|
1022
|
+
}
|
|
1023
|
+
}, SELECTION_IDLE_DELAY);
|
|
1024
|
+
}
|
|
674
1025
|
function lookUpChild(t, depth) {
|
|
675
1026
|
if (t.hasChildNodes() && t.children.length <= 5) {
|
|
676
1027
|
if (++depth > 5) {
|
|
@@ -680,16 +1031,6 @@ function lookUpChild(t, depth) {
|
|
|
680
1031
|
}
|
|
681
1032
|
return true;
|
|
682
1033
|
}
|
|
683
|
-
function addActionUser(eventType, target) {
|
|
684
|
-
dispatchTraces({
|
|
685
|
-
...SessionManager.instance.initUserAction(),
|
|
686
|
-
'@type': TRACE_TYPE_USER_ACTION,
|
|
687
|
-
type: eventType,
|
|
688
|
-
instant: dateNow(),
|
|
689
|
-
name: extractName(target),
|
|
690
|
-
nodeName: target.tagName?.toLowerCase()
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
1034
|
function getFirst(c, t) {
|
|
694
1035
|
for (const o of c) {
|
|
695
1036
|
let r = o(t)?.trim();
|
|
@@ -739,10 +1080,16 @@ const MAP = {
|
|
|
739
1080
|
],
|
|
740
1081
|
};
|
|
741
1082
|
|
|
1083
|
+
let monitoredRouter;
|
|
1084
|
+
let routerSubscription;
|
|
742
1085
|
function initNavigationMonitor(router) {
|
|
1086
|
+
if (monitoredRouter === router && !routerSubscription?.closed)
|
|
1087
|
+
return;
|
|
743
1088
|
try {
|
|
1089
|
+
routerSubscription?.unsubscribe();
|
|
744
1090
|
initStartupSession();
|
|
745
|
-
router.events.subscribe(routeHandler);
|
|
1091
|
+
routerSubscription = router.events.subscribe(routeHandler);
|
|
1092
|
+
monitoredRouter = router;
|
|
746
1093
|
window.addEventListener('pageshow', bfCacheHandler);
|
|
747
1094
|
window.addEventListener("beforeunload", windowUnloadHandler);
|
|
748
1095
|
}
|
|
@@ -755,22 +1102,22 @@ function routeHandler(event) {
|
|
|
755
1102
|
SessionManager.instance.navigate(event.url);
|
|
756
1103
|
}
|
|
757
1104
|
if (event instanceof NavigationEnd || event instanceof NavigationCancel) {
|
|
758
|
-
|
|
1105
|
+
SessionManager.instance.validateSession(true, 0);
|
|
759
1106
|
}
|
|
760
1107
|
}
|
|
761
|
-
function windowUnloadHandler(
|
|
1108
|
+
function windowUnloadHandler() {
|
|
762
1109
|
SessionManager.instance.navigate();
|
|
763
1110
|
dispatchShutown();
|
|
764
1111
|
}
|
|
765
1112
|
function initStartupSession() {
|
|
766
|
-
SessionManager.instance.navigate(new URL(document.URL).
|
|
767
|
-
SessionManager.instance.
|
|
1113
|
+
SessionManager.instance.navigate(new URL(document.URL).origin);
|
|
1114
|
+
SessionManager.instance.validateSession(false);
|
|
768
1115
|
}
|
|
769
1116
|
function bfCacheHandler(event) {
|
|
770
1117
|
if (event.persisted) { // if the page was restored from bfcache
|
|
771
1118
|
dispatchReload();
|
|
772
1119
|
SessionManager.instance.navigate(document.URL);
|
|
773
|
-
|
|
1120
|
+
SessionManager.instance.validateSession(true, 0);
|
|
774
1121
|
}
|
|
775
1122
|
}
|
|
776
1123
|
|
|
@@ -792,6 +1139,7 @@ function ressourceUsageHandler() {
|
|
|
792
1139
|
instant: dateNow(),
|
|
793
1140
|
usedHeap: memory.usedJSHeapSize / (1024 * 1024),
|
|
794
1141
|
commitedHeap: memory.totalJSHeapSize / (1024 * 1024),
|
|
1142
|
+
availableProcessors: navigator.hardwareConcurrency
|
|
795
1143
|
});
|
|
796
1144
|
}
|
|
797
1145
|
catch (e) {
|
|
@@ -799,11 +1147,58 @@ function ressourceUsageHandler() {
|
|
|
799
1147
|
}
|
|
800
1148
|
}
|
|
801
1149
|
|
|
1150
|
+
let captureInstalled = false;
|
|
1151
|
+
function installConsoleCapture() {
|
|
1152
|
+
if (captureInstalled)
|
|
1153
|
+
return;
|
|
1154
|
+
captureInstalled = true;
|
|
1155
|
+
const originalWarn = console.warn;
|
|
1156
|
+
const originalError = console.error;
|
|
1157
|
+
function capture(level, args) {
|
|
1158
|
+
try {
|
|
1159
|
+
dispatchTraces({
|
|
1160
|
+
...SessionManager.instance.traceSessionMaskUpdate(Mask.EVENT),
|
|
1161
|
+
"@type": TRACE_TYPE_SESSION_EVENT,
|
|
1162
|
+
type: level,
|
|
1163
|
+
instant: dateNow(),
|
|
1164
|
+
value: `${args.map(formatArg).join(" ")}`,
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
catch (error) {
|
|
1168
|
+
// Report capture failures using the saved method, avoiding another capture.
|
|
1169
|
+
originalError.call(console, "Failed to capture console message", error);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
console.warn = (...args) => {
|
|
1173
|
+
originalWarn.apply(console, args);
|
|
1174
|
+
capture("WARN", args);
|
|
1175
|
+
};
|
|
1176
|
+
console.error = (...args) => {
|
|
1177
|
+
originalError.apply(console, args);
|
|
1178
|
+
capture("ERROR", args);
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
function formatArg(value) {
|
|
1182
|
+
if (value instanceof Error) {
|
|
1183
|
+
return `${value.name}: ${value.message}${value.stack ? `\n${value.stack}` : ""}`;
|
|
1184
|
+
}
|
|
1185
|
+
if (typeof value === "string")
|
|
1186
|
+
return value;
|
|
1187
|
+
try {
|
|
1188
|
+
return JSON.stringify(value) ?? String(value);
|
|
1189
|
+
}
|
|
1190
|
+
catch {
|
|
1191
|
+
return String(value);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
|
|
802
1195
|
const COLLECTOR_CONFIG = new InjectionToken('COLLECTOR_CONFIG');
|
|
1196
|
+
const initializedConfigs = new WeakSet();
|
|
1197
|
+
let removeReloadListener;
|
|
803
1198
|
class NgCollectorModule {
|
|
804
1199
|
static forRoot(configuration) {
|
|
805
1200
|
const providers = [];
|
|
806
|
-
if (configuration?.enabled) {
|
|
1201
|
+
if (configuration?.collector?.enabled) {
|
|
807
1202
|
try {
|
|
808
1203
|
let config = initializeCollector(configuration);
|
|
809
1204
|
providers.push({ provide: COLLECTOR_CONFIG, useValue: config }, { provide: APP_INITIALIZER, useFactory: initializeEventsFactory, deps: [COLLECTOR_CONFIG, Router], multi: true }, { provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, deps: [COLLECTOR_CONFIG], multi: true }, { provide: ErrorHandler, useClass: GlobalErrorHandler });
|
|
@@ -823,23 +1218,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
823
1218
|
}] });
|
|
824
1219
|
function initializeEventsFactory(config, router) {
|
|
825
1220
|
return () => {
|
|
1221
|
+
configureReporter(config.tech.reporter);
|
|
1222
|
+
removeReloadListener?.();
|
|
1223
|
+
removeReloadListener = addReloadListener(() => reloadCollector(config));
|
|
1224
|
+
if (initializedConfigs.has(config.tech))
|
|
1225
|
+
return;
|
|
1226
|
+
initializedConfigs.add(config.tech);
|
|
1227
|
+
initNavigationMonitor(router);
|
|
826
1228
|
if (config.tech.analytics) {
|
|
827
1229
|
initUserActionMonitor();
|
|
828
1230
|
}
|
|
829
1231
|
if (config.tech.resources) {
|
|
830
1232
|
initResourceUsageMonitor();
|
|
831
1233
|
}
|
|
832
|
-
|
|
1234
|
+
if (config.tech.logger) {
|
|
1235
|
+
installConsoleCapture();
|
|
1236
|
+
}
|
|
833
1237
|
//storageEventListener();
|
|
834
|
-
//eventTraceDebugger
|
|
835
|
-
addReloadListener(e => {
|
|
836
|
-
reloadCollector(config);
|
|
837
|
-
});
|
|
1238
|
+
//eventTraceDebugger(config.tech)
|
|
838
1239
|
};
|
|
839
1240
|
}
|
|
840
1241
|
function initializeCollector(config) {
|
|
841
1242
|
const id = crypto.randomUUID();
|
|
842
1243
|
const tech = validateAndGetConfig(config, id);
|
|
1244
|
+
configureReporter(tech.reporter);
|
|
843
1245
|
const dispatch = eventTraceScheduledDispatcher(tech);
|
|
844
1246
|
const instance = createInstance(config, id);
|
|
845
1247
|
dispatch.trace(instance);
|
|
@@ -861,23 +1263,30 @@ class LocalRequestMonitor {
|
|
|
861
1263
|
this.id = crypto.randomUUID();
|
|
862
1264
|
}
|
|
863
1265
|
preProcess(propertyKey, target) {
|
|
864
|
-
|
|
865
|
-
|
|
1266
|
+
const sessionManager = WIN["inspect-session-manager"];
|
|
1267
|
+
const trace = {
|
|
1268
|
+
...sessionManager?.traceSessionMaskUpdate(Mask.LOCAL),
|
|
866
1269
|
"@type": TRACE_TYPE_LOCAL_REQUEST,
|
|
867
1270
|
id: this.id,
|
|
868
1271
|
name: propertyKey,
|
|
869
1272
|
location: target.constructor.name,
|
|
870
|
-
user:
|
|
1273
|
+
user: sessionManager?.currentSession?.user,
|
|
871
1274
|
start: this.start
|
|
872
|
-
}
|
|
1275
|
+
};
|
|
1276
|
+
WIN["event-bus"].dispatchEvent(new CustomEvent('trace', { detail: { traces: [trace] } }));
|
|
873
1277
|
}
|
|
874
1278
|
postProcess(exception) {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1279
|
+
const traces = [{
|
|
1280
|
+
"@type": TRACE_TYPE_LOCAL_REQUEST_CALLBACK,
|
|
1281
|
+
id: this.id,
|
|
1282
|
+
end: dateNow(),
|
|
1283
|
+
status: exception ? 400 : 200
|
|
1284
|
+
}];
|
|
1285
|
+
if (exception) {
|
|
1286
|
+
exception.traceId = this.id;
|
|
1287
|
+
traces.push(exception);
|
|
1288
|
+
}
|
|
1289
|
+
WIN["event-bus"].dispatchEvent(new CustomEvent('trace', { detail: { traces } }));
|
|
881
1290
|
}
|
|
882
1291
|
}
|
|
883
1292
|
|
|
@@ -892,7 +1301,7 @@ function TraceableStage() {
|
|
|
892
1301
|
return originalMethod.apply(this, args);
|
|
893
1302
|
}
|
|
894
1303
|
catch (e) {
|
|
895
|
-
exception =
|
|
1304
|
+
exception = createException(e, undefined, TraceType.LCL_RQT, false);
|
|
896
1305
|
throw e;
|
|
897
1306
|
}
|
|
898
1307
|
finally {
|
|
@@ -902,22 +1311,6 @@ function TraceableStage() {
|
|
|
902
1311
|
return descriptor;
|
|
903
1312
|
};
|
|
904
1313
|
}
|
|
905
|
-
function resolveException(e) {
|
|
906
|
-
let type = null, message = null;
|
|
907
|
-
if (e) {
|
|
908
|
-
if (typeof e === "string") {
|
|
909
|
-
message = e;
|
|
910
|
-
}
|
|
911
|
-
else if (e instanceof Error) {
|
|
912
|
-
type = e.name;
|
|
913
|
-
message = e.message;
|
|
914
|
-
}
|
|
915
|
-
else {
|
|
916
|
-
message = JSON.stringify(e);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
return { type, message };
|
|
920
|
-
}
|
|
921
1314
|
|
|
922
1315
|
/*
|
|
923
1316
|
* Public API Surface of inspect-ng-collector
|
|
@@ -927,5 +1320,5 @@ function resolveException(e) {
|
|
|
927
1320
|
* Generated bundle index. Do not edit.
|
|
928
1321
|
*/
|
|
929
1322
|
|
|
930
|
-
export { NgCollectorModule, TraceableStage, initializeCollector, initializeEventsFactory, reloadCollector,
|
|
1323
|
+
export { NgCollectorModule, TraceableStage, initializeCollector, initializeEventsFactory, reloadCollector, sessionlogger };
|
|
931
1324
|
//# sourceMappingURL=oneteme-inspect-ng-collector.mjs.map
|