perf: sentry和posthog增加try...catch保护

pull/64/head
moonrailgun 2 years ago
parent 67960ac877
commit 1d924f1692

@ -1,17 +1,18 @@
import posthog from 'posthog-js';
import { sharedEvent } from '@capital/common';
posthog.init('phc_xRCv3qbbOBMQkz31kbYMngXxn7Ey5JMu0BZIFktO6km', {
try {
posthog.init('phc_xRCv3qbbOBMQkz31kbYMngXxn7Ey5JMu0BZIFktO6km', {
api_host: 'https://app.posthog.com',
autocapture: false, // 关闭autocapture以节约事件用量
disable_session_recording: true, // 关闭自动录屏(不需要且一直报错)
});
});
const PLUGIN_NAME = 'posthog';
const PLUGIN_NAME = 'posthog';
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
setTimeout(() => {
setTimeout(() => {
console.log('Report plugin install status');
try {
@ -39,13 +40,16 @@ setTimeout(() => {
} catch (err) {
// Ignore error
}
}, 2000);
}, 2000);
sharedEvent.on('loginSuccess', (userInfo) => {
sharedEvent.on('loginSuccess', (userInfo) => {
posthog.identify(userInfo._id, {
email: userInfo.email,
username: `${userInfo.nickname}#${userInfo.discriminator}`,
avatar: userInfo.avatar,
temporary: userInfo.temporary,
});
});
});
} catch (err) {
console.error(err);
}

@ -2,7 +2,8 @@ import * as Sentry from '@sentry/react';
import { BrowserTracing } from '@sentry/tracing';
import { sharedEvent } from '@capital/common';
Sentry.init({
try {
Sentry.init({
dsn: 'https://177fd98a1e9e4deba84146a769633c32@o4504196236836864.ingest.sentry.io/4504196241293312',
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 1.0,
@ -12,9 +13,9 @@ Sentry.init({
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 0.1, // reduce sentry quota usage
});
});
sharedEvent.on('loginSuccess', (userInfo) => {
sharedEvent.on('loginSuccess', (userInfo) => {
Sentry.setUser({
id: userInfo._id,
email: userInfo.email,
@ -22,4 +23,7 @@ sharedEvent.on('loginSuccess', (userInfo) => {
avatar: userInfo.avatar,
temporary: userInfo.temporary,
});
});
});
} catch (err) {
console.error(err);
}

Loading…
Cancel
Save