diff --git a/packages/controller/js/http.js b/packages/controller/js/http.js index cef979b3b..28446e572 100644 --- a/packages/controller/js/http.js +++ b/packages/controller/js/http.js @@ -24,8 +24,7 @@ const http = useHttp() * @param { json } params {"event_type": design_error,"url": "elit in reprehenderit enim incididunt" } * @returns { Promise } */ -export const requestEvent = (params) => - http.post('/platform-center/api/platform/monitoring/event', params).catch(() => {}) +export const requestEvent = (url, params) => http.post(url, params).catch(() => {}) /** * 页面更新 diff --git a/packages/controller/js/monitor.js b/packages/controller/js/monitor.js index 6dc80e921..b2628caf4 100644 --- a/packages/controller/js/monitor.js +++ b/packages/controller/js/monitor.js @@ -1,17 +1,19 @@ /** -* Copyright (c) 2023 - present TinyEngine Authors. -* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. -* -* Use of this source code is governed by an MIT-style license. -* -* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, -* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR -* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. -* -*/ + * Copyright (c) 2023 - present TinyEngine Authors. + * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. + * + * Use of this source code is governed by an MIT-style license. + * + * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, + * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR + * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. + * + */ import { requestEvent } from './http.js' +let monitorUrl = '' + /** * 全局js异常埋点上报 * @param errorMessage 异常信息 @@ -35,7 +37,7 @@ const getUrlUnit = () => { const globalMonitoring = () => { window.onerror = function (errorMessage, scriptURI, lineNo, columnNo, error) { - requestEvent({ + requestEvent(monitorUrl, { event_type: 'design_JSError', url: window.location.href, unit: getUrlUnit(), @@ -67,7 +69,7 @@ const promiseMonitoring = () => { } } - requestEvent({ + requestEvent(monitorUrl, { event_type: 'design_promiseError', url: window.location.href, unit: getUrlUnit(), @@ -92,7 +94,7 @@ const promiseMonitoring = () => { export const iframeMonitoring = () => { window.frames[0].onerror = function (errorMessage, scriptURI, lineNo, columnNo, error) { - requestEvent({ + requestEvent(monitorUrl, { event_type: 'design_iframeError', url: window.location.href, unit: getUrlUnit(), @@ -106,7 +108,8 @@ export const iframeMonitoring = () => { } } -export const initMonitor = () => { +export const initMonitor = (url) => { + monitorUrl = url globalMonitoring() promiseMonitoring() } diff --git a/packages/design-core/.env.alpha b/packages/design-core/.env.alpha index 02380022a..cfd059c8b 100644 --- a/packages/design-core/.env.alpha +++ b/packages/design-core/.env.alpha @@ -3,3 +3,8 @@ NODE_ENV=production VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn # VITE_ORIGIN= + +# 错误监控上报 url +VITE_ERROR_MONITOR_URL=/platform-center/api/platform/monitoring/event +# 是否开启错误监控 +VITE_ERROR_MONITOR=false diff --git a/packages/design-core/src/main.js b/packages/design-core/src/main.js index f57b6f194..4da1396e4 100644 --- a/packages/design-core/src/main.js +++ b/packages/design-core/src/main.js @@ -17,7 +17,6 @@ import i18n from '@opentiny/tiny-engine-controller/js/i18n' import App from './App.vue' import globalConfig from '../config/lowcode.config' import { initMonitor } from '@opentiny/tiny-engine-controller/js/monitor' -import { isDevelopEnv } from '@opentiny/tiny-engine-controller/js/environments' import { injectGlobalComponents } from '@opentiny/tiny-engine-common' import { initHttp } from '@opentiny/tiny-engine-http' import 'virtual:svg-icons-register' @@ -30,8 +29,8 @@ initHttp({ env: import.meta.env }) // eslint-disable-next-line no-new new TinyThemeTool(tinySmbTheme, 'smbtheme') // 初始化主题 -if (!isDevelopEnv) { - initMonitor() +if (import.meta.env.VITE_ERROR_MONITOR === 'true' && import.meta.env.VITE_ERROR_MONITOR_URL) { + initMonitor(import.meta.env.VITE_ERROR_MONITOR_URL) } window.TinyGlobalConfig = globalConfig