@oneteme/inspect-ng-collector 1.3.0-beta.6 → 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,22 +245,27 @@ class SessionManager {
237
245
  navigate(url) {
238
246
  this.getCurrentSession(s => {
239
247
  if (s) {
240
- s.end = dateNow();
241
- s.traced && window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { force: !url, traces: s } }));
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
263
+ requestMask: 0,
264
+ };
265
+ this.currentSessionCallBack = {
266
+ '@type': "11",
267
+ id: id,
268
+ requestMask: 0,
256
269
  };
257
270
  }
258
271
  }
@@ -262,7 +275,6 @@ class SessionManager {
262
275
  s.location = document.URL;
263
276
  if (!ContextManager.instance.techConfig.exclude?.some((e) => e.test(s.location))) {
264
277
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: s } }));
265
- s.traced = true;
266
278
  }
267
279
  });
268
280
  }
@@ -273,14 +285,21 @@ class SessionManager {
273
285
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: createReport("no active session found ") } }));
274
286
  return undefined;
275
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
+ }
276
295
  currentSessionID() {
277
296
  return this.getCurrentSession(s => s.id);
278
297
  }
279
298
  updateMask(requestMask) {
280
- this.getCurrentSession(s => s.requestsMask |= requestMask);
299
+ this.getCurrentSessionCallBack(s => s.requestMask |= requestMask);
281
300
  }
282
301
  addException(exception) {
283
- this.getCurrentSession(s => s.exceptions.push(exception));
302
+ this.getCurrentSessionCallBack(s => s.exception = exception);
284
303
  }
285
304
  }
286
305
 
@@ -290,7 +309,7 @@ class RestRequestMonitor {
290
309
  const url = toHref(restRequest.urlWithParams);
291
310
  const auth_user = extractAuthSchemeAnduser(restRequest.headers);
292
311
  this.restRequest = {
293
- "@type": "http-req",
312
+ "@type": "120",
294
313
  id: crypto.randomUUID(),
295
314
  method: restRequest.method,
296
315
  protocol: url.protocol.slice(0, -1),
@@ -301,40 +320,48 @@ class RestRequestMonitor {
301
320
  contentType: restRequest.responseType,
302
321
  authScheme: auth_user.authScheme,
303
322
  user: auth_user.user,
304
- ouDataSize: sizeOf(restRequest.body),
323
+ dataSize: sizeOf(restRequest.body),
305
324
  start: start,
306
- linked: false,
307
325
  sessionId: SessionManager.instance.currentSessionID()
308
326
  };
309
327
  SessionManager.instance.updateMask(RequestMask.REST);
328
+ this.restRequestCallBack = {
329
+ "@type": "121",
330
+ id: this.restRequest.id,
331
+ dataSize: -1,
332
+ linked: false
333
+ };
310
334
  }
311
335
  postProcess(event, error) {
312
336
  let status = 0, exception = null;
313
337
  if (event) {
314
338
  status = +event.status;
315
- this.restRequest.inDataSize = sizeOf(event.body);
316
- 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);
317
341
  }
318
342
  if (error) {
319
- 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);
320
344
  status = +error.status;
321
345
  exception = {
322
346
  type: error.name,
323
347
  message: error.error && error.status ? JSON.stringify(error.error) : error.message
324
348
  };
349
+ this.restRequestCallBack.bodyContent = error instanceof HttpErrorResponse ? JSON.stringify(error.error) : undefined;
350
+ this.restRequestCallBack.dataSize = sizeOf(error.error);
325
351
  }
326
- this.restRequest.end = dateNow();
327
- this.restRequest.status = +status;
352
+ this.restRequestCallBack.contentType = extractContentType(event?.headers);
353
+ this.restRequestCallBack.end = dateNow();
354
+ this.restRequestCallBack.status = +status;
328
355
  let stage = {
329
- "@type": "http-stg",
356
+ "@type": "220",
330
357
  name: "PROCESS",
331
- start: this.restRequest.start,
358
+ start: this.restRequest.start, // use request
332
359
  end: dateNow(),
333
360
  order: 0,
334
361
  exception: exception,
335
- requestId: this.restRequest.id
362
+ requestId: this.restRequestCallBack.id
336
363
  };
337
- window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: this.restRequest } }));
364
+ window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: this.restRequestCallBack } }));
338
365
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: stage } }));
339
366
  }
340
367
  assertSessionID(id, headers) {
@@ -382,6 +409,17 @@ function extractAuthSchemeAnduser(headers) {
382
409
  }
383
410
  return auth_user;
384
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
+ }
385
423
  function sizeOf(body) {
386
424
  return body ? JSON.stringify(body).length : 0;
387
425
  }
@@ -419,10 +457,10 @@ class HttpInterceptorService {
419
457
  });
420
458
  }));
421
459
  }
422
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: HttpInterceptorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
423
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", 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' }); }
424
462
  }
425
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: HttpInterceptorService, decorators: [{
463
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: HttpInterceptorService, decorators: [{
426
464
  type: Injectable,
427
465
  args: [{ providedIn: 'root' }]
428
466
  }], ctorParameters: () => [] });
@@ -440,10 +478,10 @@ class GlobalErrorHandlerService {
440
478
  }
441
479
  throw error;
442
480
  }
443
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: GlobalErrorHandlerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
444
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", 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' }); }
445
483
  }
446
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: GlobalErrorHandlerService, decorators: [{
484
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: GlobalErrorHandlerService, decorators: [{
447
485
  type: Injectable,
448
486
  args: [{ providedIn: 'root' }]
449
487
  }] });
@@ -462,14 +500,19 @@ class EventTraceScheduledDispatcherService {
462
500
  .pipe(tap$1(() => {
463
501
  if (this.sendSessionfinished) {
464
502
  this.sendSessionfinished = false;
465
- setTimeout(() => window.dispatchEvent(new CustomEvent(PRE_DISPATCH)), 50);
466
- this.Dispatch().finally(() => { this.sendSessionfinished = true; });
503
+ window.dispatchEvent(new CustomEvent(PRE_DISPATCH));
504
+ setTimeout(() => this.Dispatch()
505
+ .catch(err => { })
506
+ .finally(() => { this.sendSessionfinished = true; }), 5);
467
507
  }
468
508
  }))
469
509
  .subscribe();
470
510
  window.addEventListener(DISPATCH, (e) => {
471
511
  e.detail.traces && this.addtoQueue(e.detail.traces);
472
- e.detail.force && this.sendSessions(true);
512
+ if (e.detail.force) {
513
+ this.sendSessions(true);
514
+ this.onDestroy();
515
+ }
473
516
  });
474
517
  }
475
518
  Dispatch() {
@@ -548,20 +591,32 @@ class EventTraceScheduledDispatcherService {
548
591
  this.addtoQueue(createReport(String(e)));
549
592
  }
550
593
  }
594
+ onDestroy() {
595
+ this.traceQueue.clear();
596
+ this.sendSessionfinished = true;
597
+ this.instanceSaved = false;
598
+ this.sessionSendAttempts = 0;
599
+ }
551
600
  }
552
601
 
553
- ;
554
602
  function routeHandler(event) {
555
603
  if (event instanceof NavigationStart) {
556
604
  SessionManager.instance.navigate(event.url);
557
605
  }
558
606
  if (event instanceof NavigationEnd || event instanceof NavigationCancel) {
559
- SessionManager.instance.updateSession();
607
+ setTimeout(() => SessionManager.instance.updateSession(), 0);
560
608
  }
561
609
  }
562
610
  function windowUnloadHandler(event) {
563
611
  SessionManager.instance.navigate();
564
612
  }
613
+ function bfCacheHandler(event) {
614
+ if (event.persisted) { // if the page was restored from bfcache
615
+ ContextManager.init(NgCollectorModule.configuration);
616
+ SessionManager.instance.navigate(document.URL);
617
+ setTimeout(() => SessionManager.instance.updateSession(), 0);
618
+ }
619
+ }
565
620
 
566
621
  function machineRessourceUsageHandler(event) {
567
622
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: getMemoryInfo() } }));
@@ -570,7 +625,7 @@ function getMemoryInfo() {
570
625
  try {
571
626
  const memory = performance.memory;
572
627
  return {
573
- '@type': 'rsrc-usg',
628
+ '@type': '01',
574
629
  instant: dateNow(),
575
630
  usedHeap: memory.usedJSHeapSize / (1024 * 1024),
576
631
  commitedHeap: memory.totalJSHeapSize / (1024 * 1024),
@@ -593,6 +648,9 @@ function beforeDispatchListener() {
593
648
  window.addEventListener(PRE_DISPATCH, machineRessourceUsageHandler);
594
649
  }
595
650
  }
651
+ function bfCacheListener() {
652
+ window.addEventListener('pageshow', bfCacheHandler);
653
+ }
596
654
 
597
655
  const genericMap = [
598
656
  t => t.getAttribute('placeholder'),
@@ -685,14 +743,14 @@ function lookUpChild(t, depth) {
685
743
  }
686
744
  function addActionUser(eventType, target) {
687
745
  const ua = {
688
- '@type': "user-act",
746
+ '@type': "300",
689
747
  type: eventType,
690
748
  start: dateNow(),
691
749
  name: extractName(target),
692
750
  nodeName: target.tagName?.toLowerCase(),
693
751
  sessionId: SessionManager.instance?.currentSessionID()
694
752
  };
695
- // window.dispatchEvent(new CustomEvent( DISPATCH ,{ detail : { traces:ua }}));
753
+ // window.dispatchEvent(new CustomEvent( DISPATCH ,{ detail : { traces:ua }}));
696
754
  }
697
755
 
698
756
  function eventTraceDebugger() {
@@ -764,7 +822,7 @@ class EventTraceDebugger {
764
822
  if (session.location) {
765
823
  s += `(${session.location}) `;
766
824
  }
767
- s += this.prettyDurationFormat(session.start, session.end) + '\n';
825
+ //s+= this.prettyDurationFormat(session.start, session.end)+'\n';
768
826
  s += this.getChildPrint(this.restRequests, this.prettyRestRequestFormat.bind(this));
769
827
  s += this.getChildPrint(this.localRequests, this.prettyLocalRequestFormat.bind(this));
770
828
  s += this.getChildPrint(this.userActions, this.prettyActionUserFormat.bind(this));
@@ -792,8 +850,9 @@ class EventTraceDebugger {
792
850
  if (rest.query) {
793
851
  s += rest.query;
794
852
  }
795
- s += ` >> ${rest.status} `;
796
- s += this.prettyDurationFormat(rest.start, rest.end) + '\n';
853
+ // s+= ` >> ${rest.status} `
854
+ // s+= this.prettyDurationFormat(rest.start,rest.end);
855
+ s += '\n';
797
856
  this.httpRequestStages.filter((s) => s.requestId == rest.id).forEach((stage) => {
798
857
  s += this.prettyHttpRequestStageFormat(stage);
799
858
  });
@@ -816,14 +875,14 @@ class EventTraceDebugger {
816
875
  if (local.location) {
817
876
  s += `(${local.location})`;
818
877
  }
819
- s += " >> ";
820
- if (local.exception?.type) {
821
- s += ` ${local.exception?.type}:`;
822
- }
823
- if (local.exception?.message) {
824
- s += ` ${local.exception.message}`;
825
- }
826
- 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)}`;*/
827
886
  return s;
828
887
  }
829
888
  prettyLogEntryFormat(log) {
@@ -882,7 +941,8 @@ class EventTraceDebugger {
882
941
  class NgCollectorModule {
883
942
  static { this.forRootCalled = false; }
884
943
  static forRoot(configuration) {
885
- console.log("forRoodtCalled");
944
+ console.log("forRootCalled");
945
+ this.configuration = configuration;
886
946
  if (configuration?.enabled && !NgCollectorModule.forRootCalled) {
887
947
  NgCollectorModule.forRootCalled = true;
888
948
  try {
@@ -905,15 +965,16 @@ class NgCollectorModule {
905
965
  ngModule: NgCollectorModule
906
966
  };
907
967
  }
908
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: NgCollectorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
909
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: NgCollectorModule }); }
910
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", 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 }); }
911
971
  }
912
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: NgCollectorModule, decorators: [{
972
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: NgCollectorModule, decorators: [{
913
973
  type: NgModule
914
974
  }] });
915
975
  function initializeEvents(router) {
916
976
  return () => {
977
+ ContextManager.init(NgCollectorModule.configuration);
917
978
  eventTraceScheduledDispatcher();
918
979
  eventTraceDebugger();
919
980
  analyticsEventsListener();
@@ -921,6 +982,7 @@ function initializeEvents(router) {
921
982
  beforeDispatchListener();
922
983
  beforeUnloadListener();
923
984
  routerEventsListener(router);
985
+ bfCacheListener();
924
986
  };
925
987
  }
926
988
 
@@ -957,19 +1019,26 @@ function TraceableStage() {
957
1019
  }
958
1020
  finally {
959
1021
  end = Date.now();
1022
+ let id = crypto.randomUUID();
960
1023
  window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: {
961
- "@type": "locl-req",
962
- id: crypto.randomUUID(),
1024
+ "@type": "110",
1025
+ id: id,
963
1026
  name: propertyKey,
964
1027
  location: target.constructor.name,
965
1028
  user: WIN["inspect-session-manager"]?.currentSession?.user,
966
1029
  start: start,
967
- end: end,
968
- exception: exception,
969
1030
  sessionId: WIN["inspect-session-manager"]?.currentSession?.id
970
1031
  }
971
1032
  }
972
1033
  }));
1034
+ window.dispatchEvent(new CustomEvent(DISPATCH, { detail: { traces: {
1035
+ "@type": "111",
1036
+ id: id,
1037
+ exception: exception,
1038
+ end: end
1039
+ }
1040
+ }
1041
+ }));
973
1042
  }
974
1043
  };
975
1044
  return descriptor;