This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git

commit bc589c8e5a63eccf14778442d83cfcb776efbb44
Author: Qiuxia Fan <[email protected]>
AuthorDate: Fri Aug 7 17:23:36 2020 +0800

    feat: set config for pref detail
---
 src/monitor.ts            | 38 +++++++++++++-------------------------
 src/performance/index.ts  | 22 +++++++++++++++-------
 src/performance/type.d.ts |  2 +-
 src/types.d.ts            |  8 +++++++-
 4 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/src/monitor.ts b/src/monitor.ts
index 3c405c2..1563a92 100644
--- a/src/monitor.ts
+++ b/src/monitor.ts
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-import { CustomOptionsType, CustomPerfOptionsType } from './types';
+import { CustomOptionsType } from './types';
 import { JSErrors, PromiseErrors, AjaxErrors, ResourceErrors, VueErrors } from 
'./errors/index';
 import Performance from './performance/index';
 
@@ -23,18 +23,14 @@ const ClientMonitor = {
   customOptions: {
     jsErrors: true,
     promiseErrors: true,
-    consoleErrors: false,
     vueErrors: false,
-    ajaxErrors: true,
+    apiErrors: true, // ajax promise
     resourceErrors: true,
+    autoTracePerf: true,
+    traceResource: false,
+    useFmp: false,
   } as CustomOptionsType,
 
-  customPerfOptions: {
-    pageId: '',
-    serviceName: '',
-    reportUrl: '',
-  } as CustomPerfOptionsType,
-
   register(options: CustomOptionsType) {
     const { serviceName, reportUrl } = options;
 
@@ -45,31 +41,23 @@ const ClientMonitor = {
 
     if (this.customOptions.jsErrors) {
       JSErrors.handleErrors({reportUrl, serviceName});
+      if (this.customOptions.vue) {
+        VueErrors.handleErrors({reportUrl, serviceName}, 
this.customOptions.vue);
+      }
     }
-    if (this.customOptions.promiseErrors) {
+    if (this.customOptions.apiErrors) {
       PromiseErrors.handleErrors({reportUrl, serviceName});
+      AjaxErrors.handleError({reportUrl, serviceName});
     }
     if (this.customOptions.resourceErrors) {
       ResourceErrors.handleErrors({reportUrl, serviceName});
     }
-    if (this.customOptions.ajaxErrors) {
-      AjaxErrors.handleError({reportUrl, serviceName});
-    }
-    if (this.customOptions.vueErrors && this.customOptions.vue) {
-      VueErrors.handleErrors({reportUrl, serviceName}, this.customOptions.vue);
-    }
-  },
-
-  tracePerfDetail(options: CustomPerfOptionsType) {
-    const customPerfOptions = {
-      ...this.customPerfOptions,
-      ...options,
-    };
+    // trace and report perf data and pv to serve when page loaded
     if (document.readyState === 'complete') {
-      Performance.recordPerf(customPerfOptions);
+      Performance.recordPerf(this.customOptions);
     } else {
       window.addEventListener('load', () => {
-        Performance.recordPerf(customPerfOptions);
+        Performance.recordPerf(this.customOptions);
       }, false);
     }
   },
diff --git a/src/performance/index.ts b/src/performance/index.ts
index ef32ad8..68b548f 100644
--- a/src/performance/index.ts
+++ b/src/performance/index.ts
@@ -16,28 +16,36 @@
  * limitations under the License.
  */
 
-import { CustomPerfOptionsType } from '../types';
+import { CustomOptionsType } from '../types';
 import Report from '../services/report';
 import pagePerf from './perf';
 import FMP from './fmp';
 import { IPerfDetail } from './type';
 
 class TracePerf {
-  private isPerf: boolean = true;
   private perfConfig = {
     perfDetail: {},
   } as { perfDetail: IPerfDetail };
 
-  public async recordPerf(options: CustomPerfOptionsType) {
-    if (this.isPerf) {
+  public async recordPerf(options: CustomOptionsType) {
+    let fmp: {fmpTime: number | undefined} = {fmpTime: undefined};
+    if (options.autoTracePerf) {
       this.perfConfig.perfDetail = await new pagePerf().getPerfTiming();
+      if (options.useFmp) {
+        fmp = await new FMP();
+      }
     }
-    const fmp: {fmpTime: number} = await new FMP();
 
     setTimeout(() => {
       const perfInfo = {
-        perfDetail: {...this.perfConfig.perfDetail, fmpTime: fmp.fmpTime},
-        ...options,
+        perfDetail: options.autoTracePerf ? {
+          ...this.perfConfig.perfDetail,
+          fmpTime: options.useFmp ? fmp.fmpTime : undefined,
+        } : undefined,
+        pageId: options.pageId,
+        serviceName: options.serviceName,
+        versionId: options.versionId,
+        serviceId: options.serviceId,
       };
       new Report(options.reportUrl).sendByXhr(perfInfo);
       this.clearPerf();
diff --git a/src/performance/type.d.ts b/src/performance/type.d.ts
index 8b43d6d..07e0b62 100644
--- a/src/performance/type.d.ts
+++ b/src/performance/type.d.ts
@@ -29,7 +29,7 @@ export type IPerfDetail = {
   redirectTime: number | undefined; // Time of redirection
   dnsTime: number | undefined; // DNS query time
   ttfbTime: number | undefined; // Time to First Byte
-  tcpTime: number | undefined; // tcp connection time
+  tcpTime: number | undefined; // Tcp connection time
   transTime: number | undefined; // Content transfer time
   domAnalysisTime: number | undefined; // Dom parsing time
   fptTime: number | undefined; // First Paint Time or Blank Screen Time
diff --git a/src/types.d.ts b/src/types.d.ts
index 3b858a2..c8edcae 100644
--- a/src/types.d.ts
+++ b/src/types.d.ts
@@ -18,12 +18,18 @@
 export interface CustomOptionsType {
   reportUrl: string;
   serviceName?: string;
+  pageId: '',
+  versionId: string;
+  serviceId: string;
   jsErrors: boolean;
   promiseErrors: boolean;
   consoleErrors: boolean;
   vueErrors: boolean;
-  ajaxErrors: boolean;
+  apiErrors: boolean;
   resourceErrors: boolean;
+  autoTracePerf: boolean;
+  traceResource: boolean;
+  useFmp: boolean;
 }
 export type CustomPerfOptionsType = {
   pageId: string;

Reply via email to