|
@@ -3,9 +3,9 @@
|
|
|
try {
|
|
|
Sentry.init({
|
|
|
dsn: "https://ea0521e5b3584ca1879b940c165916e4@jysentry.jydev.jianyu360.cn/3",
|
|
|
- release: "v4.8.7910",
|
|
|
+ release: "v4.8.7930",
|
|
|
environment: "produce",
|
|
|
- sampleRate: 0.1
|
|
|
+ sampleRate: 0.08
|
|
|
});
|
|
|
Sentry.setTag("url", location.href);
|
|
|
var id = document.cookie.match(/(^|;)\s*ud_safe\s*=\s*([^;]+)/);
|
|
@@ -217,11 +217,11 @@
|
|
|
|
|
|
// 异常资源数组
|
|
|
const failedResources = []
|
|
|
+ const failedResourcesMap = {}
|
|
|
// 异常域名数组
|
|
|
const domains = []
|
|
|
// 备用域名映射
|
|
|
const BackCDNs = {
|
|
|
- 'cdn-jybx-webtest.jydev.jianyu360.com': 'jybx-webtest.jydev.jianyu360.com',
|
|
|
'cdn-ali.jianyu360.cn': 'cdn-ali.jianyu360.com',
|
|
|
'cdn-ali2.jianyu360.cn': 'cdn-ali2.jianyu360.com',
|
|
|
'cdn-ali3.jianyu360.cn': 'cdn-ali3.jianyu360.com',
|
|
@@ -232,8 +232,13 @@
|
|
|
const BackDomains = Object.keys(BackCDNs)
|
|
|
|
|
|
// 处理异常资源
|
|
|
- const handleResourceError = (url) => {
|
|
|
+ const handleResourceError = (url, type) => {
|
|
|
failedResources.push(url);
|
|
|
+ if (!failedResourcesMap[type]) {
|
|
|
+ failedResourcesMap[type] = []
|
|
|
+ }
|
|
|
+ failedResourcesMap[type].push(url)
|
|
|
+
|
|
|
// 提取域名
|
|
|
const domain = new URL(url).hostname
|
|
|
if(!domains.includes(domain)) {
|
|
@@ -249,21 +254,42 @@
|
|
|
window.addEventListener('error', (e) => {
|
|
|
// 脚本错误、图片错误
|
|
|
if(e.target.src && (e.target.tagName === 'SCRIPT' || e.target.tagName === 'IMG')) {
|
|
|
- handleResourceError(e.target.src)
|
|
|
+ handleResourceError(e.target.src, e.target.tagName)
|
|
|
}
|
|
|
|
|
|
// CSS错误
|
|
|
if(e.target.href && e.target.tagName === 'LINK') {
|
|
|
- handleResourceError(e.target.href)
|
|
|
+ handleResourceError(e.target.href, e.target.tagName)
|
|
|
}
|
|
|
}, true)
|
|
|
|
|
|
const currentTime = Date.now()
|
|
|
|
|
|
- function sendError (content) {
|
|
|
+ function sendError (content, options) {
|
|
|
if (window.Sentry && typeof window.Sentry.captureMessage === 'function') {
|
|
|
- Sentry.captureMessage(content)
|
|
|
+ Sentry.captureMessage(content, options)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 异常资源随机取样
|
|
|
+ function getRandomResourceByType () {
|
|
|
+ let randomData = {}
|
|
|
+
|
|
|
+ for (let type in failedResourcesMap) {
|
|
|
+ if (failedResourcesMap.hasOwnProperty(type)) {
|
|
|
+ const group = failedResourcesMap[type]
|
|
|
+
|
|
|
+ // 检查 group 是否为数组
|
|
|
+ if (Object.prototype.toString.call(group) === '[object Array]' && group.length > 0) {
|
|
|
+ const realGroup = filterErrorURL(group)
|
|
|
+ if (realGroup.length > 0) {
|
|
|
+ randomData[type] = realGroup[Math.floor(Math.random() * realGroup.length)]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return randomData
|
|
|
}
|
|
|
|
|
|
function filterErrorURL (urls) {
|
|
@@ -284,8 +310,14 @@
|
|
|
window.addEventListener('load', () => {
|
|
|
// 页面完全加载完毕
|
|
|
// console.log('load Failed resources:', failedResources)
|
|
|
- if (failedResources.length > 0) {
|
|
|
- sendError("[CDN] Has failedResources: " + filterErrorURL(failedResources).join('、'))
|
|
|
+ if (filterErrorURL(failedResources).length > 0) {
|
|
|
+ sendError(new Error('Error Resource'), {
|
|
|
+ level: 'info',
|
|
|
+ tags: getRandomResourceByType(),
|
|
|
+ extra: {
|
|
|
+ failedResources: failedResources
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
// console.log('load Extracted domains:', domains)
|
|
|
|
|
@@ -304,7 +336,15 @@
|
|
|
})))
|
|
|
})
|
|
|
|
|
|
- sendError("[CDN] Has wrong cdn: " + domains.join('、'))
|
|
|
+ sendError(new Error('Error CDN'), {
|
|
|
+ level: 'info',
|
|
|
+ tags: filterErrorURL(domains).join('、'),
|
|
|
+ extra: {
|
|
|
+ domains: domains,
|
|
|
+ failedResources: failedResources
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
addCDNDialogNode('加载中……')
|
|
|
|
|
|
function stopUnlimitedReload (callback) {
|