Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(errorMonitor): add config for errormonitor #381

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/controller/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {})

/**
* 页面更新
Expand Down
31 changes: 17 additions & 14 deletions packages/controller/js/monitor.js
Original file line number Diff line number Diff line change
@@ -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 异常信息
Expand All @@ -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(),
Expand Down Expand Up @@ -67,7 +69,7 @@ const promiseMonitoring = () => {
}
}

requestEvent({
requestEvent(monitorUrl, {
event_type: 'design_promiseError',
url: window.location.href,
unit: getUrlUnit(),
Expand All @@ -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(),
Expand All @@ -106,7 +108,8 @@ export const iframeMonitoring = () => {
}
}

export const initMonitor = () => {
export const initMonitor = (url) => {
monitorUrl = url
globalMonitoring()
promiseMonitoring()
}
5 changes: 5 additions & 0 deletions packages/design-core/.env.alpha
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions packages/design-core/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
Loading