feat: sentry proxy (#399)
* feat: sentry proxy * refactor: extracting init
This commit is contained in:
+3
-26
@@ -4,7 +4,6 @@ import { SnackbarProvider } from 'notistack'
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import { HashRouter as Router } from 'react-router-dom'
|
import { HashRouter as Router } from 'react-router-dom'
|
||||||
import * as Sentry from '@sentry/react'
|
import * as Sentry from '@sentry/react'
|
||||||
import { BrowserTracing } from '@sentry/tracing'
|
|
||||||
import './App.css'
|
import './App.css'
|
||||||
import Dashboard from './layout/Dashboard'
|
import Dashboard from './layout/Dashboard'
|
||||||
import { Provider as BeeProvider } from './providers/Bee'
|
import { Provider as BeeProvider } from './providers/Bee'
|
||||||
@@ -17,9 +16,8 @@ import { Provider as TopUpProvider } from './providers/TopUp'
|
|||||||
import BaseRouter from './routes'
|
import BaseRouter from './routes'
|
||||||
import { theme } from './theme'
|
import { theme } from './theme'
|
||||||
import { config } from './config'
|
import { config } from './config'
|
||||||
import { getBeeDesktopLogs, getBeeLogs } from './utils/desktop'
|
|
||||||
import packageJson from '../package.json'
|
|
||||||
import ItsBroken from './layout/ItsBroken'
|
import ItsBroken from './layout/ItsBroken'
|
||||||
|
import { initSentry } from './utils/sentry'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
beeApiUrl?: string
|
beeApiUrl?: string
|
||||||
@@ -28,29 +26,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.SENTRY_KEY) {
|
if (config.SENTRY_KEY) {
|
||||||
Sentry.init({
|
// eslint-disable-next-line no-console
|
||||||
dsn: config.SENTRY_KEY,
|
initSentry().catch(e => console.error(e))
|
||||||
release: packageJson.version,
|
|
||||||
integrations: [new BrowserTracing({ tracingOrigins: ['localhost'] })],
|
|
||||||
tracesSampleRate: 1.0,
|
|
||||||
beforeSend: async (event, hint) => {
|
|
||||||
hint.attachments = []
|
|
||||||
|
|
||||||
try {
|
|
||||||
// This will fail if we are not running in Bee Desktop, but that is alright
|
|
||||||
hint.attachments.push({ filename: 'bee-desktop.log', data: await getBeeDesktopLogs() })
|
|
||||||
// eslint-disable-next-line no-empty
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// This will fail if we are not running in Bee Desktop, but that is alright
|
|
||||||
hint.attachments.push({ filename: 'bee.log', data: await getBeeLogs() })
|
|
||||||
// eslint-disable-next-line no-empty
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
return event
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const App = ({ beeApiUrl, beeDebugApiUrl, lockedApiSettings }: Props): ReactElement => {
|
const App = ({ beeApiUrl, beeDebugApiUrl, lockedApiSettings }: Props): ReactElement => {
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { config } from '../config'
|
||||||
|
import * as Sentry from '@sentry/react'
|
||||||
|
import packageJson from '../../package.json'
|
||||||
|
import { BrowserTracing } from '@sentry/tracing'
|
||||||
|
import { getBeeDesktopLogs, getBeeLogs } from './desktop'
|
||||||
|
|
||||||
|
export async function initSentry(): Promise<void> {
|
||||||
|
let tunnelAvailable
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await fetch(`${config.BEE_DESKTOP_URL}/sentry`, { method: 'OPTIONS' })
|
||||||
|
|
||||||
|
if (result.status === 204) {
|
||||||
|
tunnelAvailable = true
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// There was an error, so tunnel is not available
|
||||||
|
tunnelAvailable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentry.init({
|
||||||
|
dsn: config.SENTRY_KEY,
|
||||||
|
release: packageJson.version,
|
||||||
|
tunnel: tunnelAvailable ? `${config.BEE_DESKTOP_URL}/sentry` : undefined,
|
||||||
|
integrations: [new BrowserTracing({ tracingOrigins: ['localhost'] })],
|
||||||
|
tracesSampleRate: 0.3,
|
||||||
|
beforeSend: async (event, hint) => {
|
||||||
|
hint.attachments = []
|
||||||
|
|
||||||
|
try {
|
||||||
|
// This will fail if we are not running in Bee Desktop, but that is alright
|
||||||
|
hint.attachments.push({ filename: 'bee-desktop.log', data: await getBeeDesktopLogs() })
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// This will fail if we are not running in Bee Desktop, but that is alright
|
||||||
|
hint.attachments.push({ filename: 'bee.log', data: await getBeeLogs() })
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return event
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user