@oneteme/inspect-ng-collector 1.3.0-beta.7 → 1.3.0-beta.8

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.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
3
- import { HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
3
+ import { HttpErrorResponse, HttpResponse, 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';
@@ -19,7 +19,7 @@ const PRE_DISPATCH = 'pre-dispatch';
19
19
  const BEFOREUNLOAD = 'beforeunload';
20
20
  function createLogEntry(level, message, sessionId) {
21
21
  return {
22
- "@type": "log",
22
+ "@type": "00",
23
23
  level: level,
24
24
  message: message,
25
25
  instant: dateNow(),
@@ -28,7 +28,7 @@ function createLogEntry(level, message, sessionId) {
28
28
  }
29
29
  function createReport(message) {
30
30
  return {
31
- "@type": "log",
31
+ "@type": "00",
32
32
  level: "ERROR",
33
33
  message: message,
34
34
  instant: dateNow(),
@@ -147,7 +147,7 @@ function adaptedConfig(conf) {
147
147
  ...conf.tracing,
148
148
  remote: {
149
149
  ...conf.tracing?.remote,
150
- '@type': "rest-rmt",
150
+ '@type': "02",
151
151
  retentionMaxAge: (conf.tracing?.remote?.retentionMaxAge ?? 10) * 60 * 60 * 24
152
152
  }
153
153
  }
@@ -202,7 +202,7 @@ class ContextManager {
202
202
  id: instanceId,
203
203
  name: require(getStringOrCall(conf?.monitoring?.name), 'name'),
204
204
  version: getStringOrCall(conf?.monitoring?.version),
205
- address: undefined, //server side
205
+ address: getSessionAddress(), //server side
206
206
  env: require(getStringOrCall(conf?.monitoring?.env), 'env'),
207
207
  os: detectOs(),
208
208
  re: detectBrowser(),
@@ -216,6 +216,14 @@ class ContextManager {
216
216
  };
217
217
  }
218
218
  }
219
+ function getSessionAddress() {
220
+ let inspectId = localStorage.getItem("inspect-id");
221
+ if (!inspectId) {
222
+ inspectId = crypto.randomUUID();
223
+ localStorage.setItem("inspect-id", inspectId);
224
+ }
225
+ return inspectId;
226
+ }
219
227
  function instanceApiURL(host, path) {
220
228
  return toURL(host, path);
221
229
  }
@@ -237,24 +245,27 @@ class SessionManager {
237
245
  navigate(url) {
238
246
  this.getCurrentSession(s => {
239
247
  if (s) {
240
- s.end = dateNow();
241
- window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { force: !url } }));
248
+ this.getCurrentSessionCallBack(cb => cb.end = dateNow());
249
+ window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { force: !url, traces: this.currentSessionCallBack } }));
242
250
  }
243
251
  this.currentSession = null;
244
252
  });
245
253
  if (url) {
254
+ let id = crypto.randomUUID();
246
255
  this.currentSession = {
247
- '@type': "main-ses",
248
- id: crypto.randomUUID(),
256
+ '@type': "10",
257
+ id: id,
249
258
  user: ContextManager.instance.techConfig.user,
250
259
  start: dateNow(),
251
260
  type: "VIEW",
252
261
  location: url,
253
262
  loading: true,
254
- exceptions: [],
255
- requestsMask: 0,
256
- end: null,
257
- address: this.getSessionAddress()
263
+ requestMask: 0,
264
+ };
265
+ this.currentSessionCallBack = {
266
+ '@type': "11",
267
+ id: id,
268
+ requestMask: 0,
258
269
  };
259
270
  }
260
271
  }
@@ -267,14 +278,6 @@ class SessionManager {
267
278
  }
268
279
  });
269
280
  }
270
- getSessionAddress() {
271
- let inspectId = localStorage.getItem("inspect-id");
272
- if (!inspectId) {
273
- inspectId = crypto.randomUUID();
274
- localStorage.setItem("inspect-id", inspectId);
275
- }
276
- return inspectId;
277
- }
278
281
  getCurrentSession(fn) {
279
282
  if (this.currentSession) {
280
283
  return fn(this.currentSession);
@@ -282,14 +285,21 @@ class SessionManager {
282
285
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: createReport("no active session found ") } }));
283
286
  return undefined;
284
287
  }
288
+ getCurrentSessionCallBack(fn) {
289
+ if (this.currentSessionCallBack) {
290
+ return fn(this.currentSessionCallBack);
291
+ }
292
+ window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: createReport("no active session found ") } }));
293
+ return undefined;
294
+ }
285
295
  currentSessionID() {
286
296
  return this.getCurrentSession(s => s.id);
287
297
  }
288
298
  updateMask(requestMask) {
289
- this.getCurrentSession(s => s.requestsMask |= requestMask);
299
+ this.getCurrentSessionCallBack(s => s.requestMask |= requestMask);
290
300
  }
291
301
  addException(exception) {
292
- this.getCurrentSession(s => s.exceptions.push(exception));
302
+ this.getCurrentSessionCallBack(s => s.exception = exception);
293
303
  }
294
304
  }
295
305
 
@@ -299,7 +309,7 @@ class RestRequestMonitor {
299
309
  const url = toHref(restRequest.urlWithParams);
300
310
  const auth_user = extractAuthSchemeAnduser(restRequest.headers);
301
311
  this.restRequest = {
302
- "@type": "http-req",
312
+ "@type": "120",
303
313
  id: crypto.randomUUID(),
304
314
  method: restRequest.method,
305
315
  protocol: url.protocol.slice(0, -1),
@@ -310,40 +320,48 @@ class RestRequestMonitor {
310
320
  contentType: restRequest.responseType,
311
321
  authScheme: auth_user.authScheme,
312
322
  user: auth_user.user,
313
- ouDataSize: sizeOf(restRequest.body),
323
+ dataSize: sizeOf(restRequest.body),
314
324
  start: start,
315
- linked: false,
316
- end: undefined,
317
325
  sessionId: SessionManager.instance.currentSessionID()
318
326
  };
319
327
  SessionManager.instance.updateMask(RequestMask.REST);
328
+ this.restRequestCallBack = {
329
+ "@type": "121",
330
+ id: this.restRequest.id,
331
+ dataSize: -1,
332
+ linked: false
333
+ };
320
334
  }
321
335
  postProcess(event, error) {
322
336
  let status = 0, exception = null;
323
337
  if (event) {
324
338
  status = +event.status;
325
- this.restRequest.inDataSize = sizeOf(event.body);
326
- this.restRequest.linked = this.assertSessionID(this.restRequest.id, event.headers);
339
+ this.restRequestCallBack.dataSize = sizeOf(event.body);
340
+ this.restRequestCallBack.linked = this.assertSessionID(this.restRequest.id, event.headers);
327
341
  }
328
342
  if (error) {
329
- this.restRequest.linked = error?.headers && this.assertSessionID(this.restRequest.id, error.headers);
343
+ this.restRequestCallBack.linked = error?.headers && this.assertSessionID(this.restRequest.id, error.headers);
330
344
  status = +error.status;
331
345
  exception = {
332
346
  type: error.name,
333
347
  message: error.error && error.status ? JSON.stringify(error.error) : error.message
334
348
  };
349
+ this.restRequestCallBack.bodyContent = error instanceof HttpErrorResponse ? JSON.stringify(error.error) : undefined;
350
+ this.restRequestCallBack.dataSize = sizeOf(error.error);
335
351
  }
336
- this.restRequest.end = dateNow();
337
- this.restRequest.status = +status;
352
+ this.restRequestCallBack.contentType = extractContentType(event?.headers);
353
+ this.restRequestCallBack.end = dateNow();
354
+ this.restRequestCallBack.status = +status;
338
355
  let stage = {
339
- "@type": "http-stg",
356
+ "@type": "220",
340
357
  name: "PROCESS",
341
- start: this.restRequest.start,
358
+ start: this.restRequest.start, // use request
342
359
  end: dateNow(),
343
360
  order: 0,
344
361
  exception: exception,
345
- requestId: this.restRequest.id
362
+ requestId: this.restRequestCallBack.id
346
363
  };
364
+ window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: this.restRequestCallBack } }));
347
365
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: stage } }));
348
366
  }
349
367
  assertSessionID(id, headers) {
@@ -391,6 +409,17 @@ function extractAuthSchemeAnduser(headers) {
391
409
  }
392
410
  return auth_user;
393
411
  }
412
+ function extractContentType(headers) {
413
+ try {
414
+ if (headers?.has('Content-Type')) {
415
+ return headers.get('Content-Type');
416
+ }
417
+ }
418
+ catch (err) {
419
+ createReport(JSON.stringify(err));
420
+ }
421
+ return undefined;
422
+ }
394
423
  function sizeOf(body) {
395
424
  return body ? JSON.stringify(body).length : 0;
396
425
  }
@@ -428,10 +457,10 @@ class HttpInterceptorService {
428
457
  });
429
458
  }));
430
459
  }
431
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: HttpInterceptorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
432
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: HttpInterceptorService, providedIn: 'root' }); }
460
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: HttpInterceptorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
461
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: HttpInterceptorService, providedIn: 'root' }); }
433
462
  }
434
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: HttpInterceptorService, decorators: [{
463
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: HttpInterceptorService, decorators: [{
435
464
  type: Injectable,
436
465
  args: [{ providedIn: 'root' }]
437
466
  }], ctorParameters: () => [] });
@@ -449,10 +478,10 @@ class GlobalErrorHandlerService {
449
478
  }
450
479
  throw error;
451
480
  }
452
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: GlobalErrorHandlerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
453
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: GlobalErrorHandlerService, providedIn: 'root' }); }
481
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: GlobalErrorHandlerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
482
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: GlobalErrorHandlerService, providedIn: 'root' }); }
454
483
  }
455
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: GlobalErrorHandlerService, decorators: [{
484
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: GlobalErrorHandlerService, decorators: [{
456
485
  type: Injectable,
457
486
  args: [{ providedIn: 'root' }]
458
487
  }] });
@@ -472,7 +501,9 @@ class EventTraceScheduledDispatcherService {
472
501
  if (this.sendSessionfinished) {
473
502
  this.sendSessionfinished = false;
474
503
  window.dispatchEvent(new CustomEvent(PRE_DISPATCH));
475
- setTimeout(() => this.Dispatch().finally(() => { this.sendSessionfinished = true; }), 5);
504
+ setTimeout(() => this.Dispatch()
505
+ .catch(err => { })
506
+ .finally(() => { this.sendSessionfinished = true; }), 5);
476
507
  }
477
508
  }))
478
509
  .subscribe();
@@ -502,7 +533,8 @@ class EventTraceScheduledDispatcherService {
502
533
  if (instanceComplete) {
503
534
  uri += "&end=" + new Date().toISOString();
504
535
  }
505
- let sessions = this.extractEventTrace();
536
+ let sessions = this.traceQueue;
537
+ this.traceQueue = new Set();
506
538
  return fetch(uri, this.getRequestInit(sessions))
507
539
  .then(res => {
508
540
  if (res.ok) {
@@ -515,27 +547,6 @@ class EventTraceScheduledDispatcherService {
515
547
  }
516
548
  return Promise.resolve(0);
517
549
  }
518
- extractEventTrace() {
519
- let trc = this.traceQueue;
520
- this.traceQueue = new Set();
521
- let ses = new Set();
522
- trc.forEach(((e) => {
523
- if (e.hasOwnProperty("end")) {
524
- const copy = { ...e };
525
- if (!copy.end) {
526
- ses.add(copy);
527
- this.traceQueue.add(e);
528
- }
529
- else {
530
- ses.add(e);
531
- }
532
- }
533
- else {
534
- ses.add(e);
535
- }
536
- }));
537
- return ses;
538
- }
539
550
  handleEventTraceSavingError(sessions) {
540
551
  this.sessionSendAttempts % 5 == 0 && console.warn(`Error while attempting to send sessions, attempts: ${this.sessionSendAttempts}`);
541
552
  this.revertQueueSize(sessions);
@@ -593,7 +604,7 @@ function routeHandler(event) {
593
604
  SessionManager.instance.navigate(event.url);
594
605
  }
595
606
  if (event instanceof NavigationEnd || event instanceof NavigationCancel) {
596
- SessionManager.instance.updateSession();
607
+ setTimeout(() => SessionManager.instance.updateSession(), 0);
597
608
  }
598
609
  }
599
610
  function windowUnloadHandler(event) {
@@ -603,7 +614,7 @@ function bfCacheHandler(event) {
603
614
  if (event.persisted) { // if the page was restored from bfcache
604
615
  ContextManager.init(NgCollectorModule.configuration);
605
616
  SessionManager.instance.navigate(document.URL);
606
- SessionManager.instance.updateSession();
617
+ setTimeout(() => SessionManager.instance.updateSession(), 0);
607
618
  }
608
619
  }
609
620
 
@@ -614,7 +625,7 @@ function getMemoryInfo() {
614
625
  try {
615
626
  const memory = performance.memory;
616
627
  return {
617
- '@type': 'rsrc-usg',
628
+ '@type': '01',
618
629
  instant: dateNow(),
619
630
  usedHeap: memory.usedJSHeapSize / (1024 * 1024),
620
631
  commitedHeap: memory.totalJSHeapSize / (1024 * 1024),
@@ -732,14 +743,14 @@ function lookUpChild(t, depth) {
732
743
  }
733
744
  function addActionUser(eventType, target) {
734
745
  const ua = {
735
- '@type': "user-act",
746
+ '@type': "300",
736
747
  type: eventType,
737
748
  start: dateNow(),
738
749
  name: extractName(target),
739
750
  nodeName: target.tagName?.toLowerCase(),
740
751
  sessionId: SessionManager.instance?.currentSessionID()
741
752
  };
742
- // window.dispatchEvent(new CustomEvent( DISPATCH ,{ detail : { traces:ua }}));
753
+ // window.dispatchEvent(new CustomEvent( DISPATCH ,{ detail : { traces:ua }}));
743
754
  }
744
755
 
745
756
  function eventTraceDebugger() {
@@ -811,7 +822,7 @@ class EventTraceDebugger {
811
822
  if (session.location) {
812
823
  s += `(${session.location}) `;
813
824
  }
814
- s += this.prettyDurationFormat(session.start, session.end) + '\n';
825
+ //s+= this.prettyDurationFormat(session.start, session.end)+'\n';
815
826
  s += this.getChildPrint(this.restRequests, this.prettyRestRequestFormat.bind(this));
816
827
  s += this.getChildPrint(this.localRequests, this.prettyLocalRequestFormat.bind(this));
817
828
  s += this.getChildPrint(this.userActions, this.prettyActionUserFormat.bind(this));
@@ -839,8 +850,9 @@ class EventTraceDebugger {
839
850
  if (rest.query) {
840
851
  s += rest.query;
841
852
  }
842
- s += ` >> ${rest.status} `;
843
- s += this.prettyDurationFormat(rest.start, rest.end) + '\n';
853
+ // s+= ` >> ${rest.status} `
854
+ // s+= this.prettyDurationFormat(rest.start,rest.end);
855
+ s += '\n';
844
856
  this.httpRequestStages.filter((s) => s.requestId == rest.id).forEach((stage) => {
845
857
  s += this.prettyHttpRequestStageFormat(stage);
846
858
  });
@@ -863,14 +875,14 @@ class EventTraceDebugger {
863
875
  if (local.location) {
864
876
  s += `(${local.location})`;
865
877
  }
866
- s += " >> ";
867
- if (local.exception?.type) {
868
- s += ` ${local.exception?.type}:`;
869
- }
870
- if (local.exception?.message) {
871
- s += ` ${local.exception.message}`;
872
- }
873
- s += ` ${this.prettyDurationFormat(local.start, local.end)}`;
878
+ /*s+= " >> ";
879
+ if(local.exception?.type){
880
+ s+= ` ${local.exception?.type}:`;
881
+ }
882
+ if(local.exception?.message){
883
+ s+= ` ${local.exception.message}`
884
+ }
885
+ s+= ` ${this.prettyDurationFormat(local.start, local.end)}`;*/
874
886
  return s;
875
887
  }
876
888
  prettyLogEntryFormat(log) {
@@ -953,11 +965,11 @@ class NgCollectorModule {
953
965
  ngModule: NgCollectorModule
954
966
  };
955
967
  }
956
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgCollectorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
957
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: NgCollectorModule }); }
958
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgCollectorModule }); }
968
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: NgCollectorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
969
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.16", ngImport: i0, type: NgCollectorModule }); }
970
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: NgCollectorModule }); }
959
971
  }
960
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgCollectorModule, decorators: [{
972
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: NgCollectorModule, decorators: [{
961
973
  type: NgModule
962
974
  }] });
963
975
  function initializeEvents(router) {
@@ -1007,19 +1019,26 @@ function TraceableStage() {
1007
1019
  }
1008
1020
  finally {
1009
1021
  end = Date.now();
1022
+ let id = crypto.randomUUID();
1010
1023
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: {
1011
- "@type": "locl-req",
1012
- id: crypto.randomUUID(),
1024
+ "@type": "110",
1025
+ id: id,
1013
1026
  name: propertyKey,
1014
1027
  location: target.constructor.name,
1015
1028
  user: WIN["inspect-session-manager"]?.currentSession?.user,
1016
1029
  start: start,
1017
- end: end,
1018
- exception: exception,
1019
1030
  sessionId: WIN["inspect-session-manager"]?.currentSession?.id
1020
1031
  }
1021
1032
  }
1022
1033
  }));
1034
+ window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: {
1035
+ "@type": "111",
1036
+ id: id,
1037
+ exception: exception,
1038
+ end: end
1039
+ }
1040
+ }
1041
+ }));
1023
1042
  }
1024
1043
  };
1025
1044
  return descriptor;