You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by qi...@apache.org on 2022/10/10 10:16:30 UTC
[skywalking-client-js] branch master updated: feat: validate custom options (#102)
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git
The following commit(s) were added to refs/heads/master by this push:
new 7be3caf feat: validate custom options (#102)
7be3caf is described below
commit 7be3caf89b7023fd6884d0a81e27747d4ec0105f
Author: Fine0830 <fi...@outlook.com>
AuthorDate: Mon Oct 10 18:16:24 2022 +0800
feat: validate custom options (#102)
---
src/errors/vue.ts | 3 +++
src/monitor.ts | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/src/errors/vue.ts b/src/errors/vue.ts
index 2cf805c..454f141 100644
--- a/src/errors/vue.ts
+++ b/src/errors/vue.ts
@@ -28,6 +28,9 @@ class VueErrors extends Base {
};
public handleErrors(options: CustomReportOptions, Vue: any) {
this.infoOpt = options;
+ if (!(Vue && Vue.config)) {
+ return;
+ }
Vue.config.errorHandler = (error: Error, vm: any, info: string) => {
try {
this.logInfo = {
diff --git a/src/monitor.ts b/src/monitor.ts
index 3993ecf..70871c7 100644
--- a/src/monitor.ts
+++ b/src/monitor.ts
@@ -40,7 +40,7 @@ const ClientMonitor = {
...this.customOptions,
...configs,
};
- this.validation();
+ this.validateOptions();
this.catchErrors(this.customOptions);
if (!this.customOptions.enableSPA) {
this.performance(this.customOptions);
@@ -87,6 +87,7 @@ const ClientMonitor = {
...configs,
useFmp: false,
};
+ this.validateOptions();
this.performance(this.customOptions);
const { service, pagePath, serviceVersion, collector } = this.customOptions;
if (this.customOptions.jsErrors) {
@@ -107,8 +108,7 @@ const ClientMonitor = {
reportFrameErrors(configs: CustomReportOptions, error: Error) {
FrameErrors.handleErrors(configs, error);
},
- validation(customTags: TagOption[]) {
- // const { customTags } = this.customOptions;
+ validateTags(customTags?: TagOption[]) {
if (!customTags) {
return false;
}
@@ -118,7 +118,7 @@ const ClientMonitor = {
return false;
}
let isTags = true;
- for (const ele of this.customOptions.customTags) {
+ for (const ele of customTags) {
if (!(ele && ele.key && ele.value)) {
isTags = false;
}
@@ -130,9 +130,78 @@ const ClientMonitor = {
}
return true;
},
+ validateOptions() {
+ const {
+ collector,
+ service,
+ pagePath,
+ serviceVersion,
+ jsErrors,
+ apiErrors,
+ resourceErrors,
+ autoTracePerf,
+ useFmp,
+ enableSPA,
+ traceSDKInternal,
+ detailMode,
+ noTraceOrigins,
+ traceTimeInterval,
+ customTags,
+ vue,
+ } = this.customOptions;
+ this.validateTags(customTags);
+ if (typeof collector !== 'string') {
+ this.customOptions.collector = location.origin;
+ }
+ if (typeof service !== 'string') {
+ this.customOptions.service = '';
+ }
+ if (typeof pagePath !== 'string') {
+ this.customOptions.pagePath = '';
+ }
+ if (typeof serviceVersion !== 'string') {
+ this.customOptions.serviceVersion = '';
+ }
+ if (typeof jsErrors !== 'boolean') {
+ this.customOptions.jsErrors = true;
+ }
+ if (typeof apiErrors !== 'boolean') {
+ this.customOptions.apiErrors = true;
+ }
+ if (typeof resourceErrors !== 'boolean') {
+ this.customOptions.resourceErrors = true;
+ }
+ if (typeof autoTracePerf !== 'boolean') {
+ this.customOptions.autoTracePerf = true;
+ }
+ if (typeof useFmp !== 'boolean') {
+ this.customOptions.useFmp = false;
+ }
+ if (typeof enableSPA !== 'boolean') {
+ this.customOptions.enableSPA = false;
+ }
+ if (typeof traceSDKInternal !== 'boolean') {
+ this.customOptions.traceSDKInternal = false;
+ }
+ if (typeof detailMode !== 'boolean') {
+ this.customOptions.detailMode = true;
+ }
+ if (typeof detailMode !== 'boolean') {
+ this.customOptions.detailMode = true;
+ }
+ if (!Array.isArray(noTraceOrigins)) {
+ this.customOptions.noTraceOrigins = [];
+ }
+ if (typeof traceTimeInterval !== 'number') {
+ this.customOptions.traceTimeInterval = 60000;
+ }
+ if (typeof vue !== 'function') {
+ this.customOptions.vue = undefined;
+ }
+ },
setCustomTags(tags: TagOption[]) {
const opt = { ...this.customOptions, customTags: tags };
- if (this.validation(tags)) {
+ if (this.validateTags(tags)) {
setConfig(opt);
}
},