fix(errorMonitor): add config for errormonitor (#381)

This commit is contained in:
chilingling 2024-04-09 05:13:53 -07:00 committed by GitHub
parent a010bfa4d6
commit 68838ed5f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 19 deletions

View File

@ -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(() => {})
/**
* 页面更新

View File

@ -12,6 +12,8 @@
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()
}

View File

@ -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

View File

@ -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