Skip to content

Commit

Permalink
feat: integrating sentry (#240) (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Nov 30, 2023
1 parent 0d8dd34 commit 732cff6
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 236 deletions.
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ types-requests = "*"
greenlet = "*"
emails = "*"
jinja2 = "*"
sentry-sdk = {extras = ["fastapi"], version = "*"}

[dev-packages]
aiosqlite = "*"
Expand Down
501 changes: 272 additions & 229 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/app/api/internal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def version():

@api_router.get("/frontend-settings")
@api_router.post("/frontend-settings")
async def matomo():
async def frontend_settings():
"""
Return frontend settings.
Expand Down
14 changes: 14 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pathlib
from contextlib import asynccontextmanager

import sentry_sdk
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from starlette.middleware.cors import CORSMiddleware
Expand All @@ -17,13 +18,26 @@

logger = logging.getLogger(__name__)

if settings.SENTRY_DSN: # pragma: no cover
sentry_sdk.init(
dsn=str(settings.SENTRY_DSN),
enable_tracing=True,
)

app = FastAPI(
title="REEV",
openapi_url=f"{settings.API_V1_STR}/openapi.json",
docs_url=f"{settings.API_V1_STR}/docs",
debug=settings.DEBUG,
)

if settings.SENTRY_DSN and settings.DEBUG: # pragma: no cover

@app.get("/sentry-debug")
async def trigger_error():
division_by_zero = 1 / 0


# Set all CORS enabled origins
if settings.BACKEND_CORS_ORIGINS:
app.add_middleware(
Expand Down
103 changes: 103 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"dependencies": {
"@mdi/font": "^7.2.96",
"@reactgular/chunks": "^1.0.1",
"@sentry/tracing": "^7.84.0",
"@sentry/vue": "^7.84.0",
"@vue/eslint-config-standard": "^8.0.1",
"igv": "^2.15.11",
"lodash": "^4.17.21",
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import type { App } from 'vue'

import router from '../router'
import pinia from '../stores'
import setupMatomo from './matomo'
import { setupMatomo } from './matomo'
import { setupSentry } from './sentry'
import vuetify from './vuetify'

export async function registerPlugins(app: App) {
app.use(vuetify).use(router).use(pinia)

// Initialize Matomo
await setupMatomo(app, router)
// Initialize Matomo and Sentry
await Promise.all([setupMatomo(app, router), setupSentry(app, router)])
}
5 changes: 2 additions & 3 deletions frontend/src/plugins/matomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
import { type App } from 'vue'
import VueMatomo from 'vue-matomo'
import { type Router } from 'vue-router'

import { SettingsClient } from '@/api/settings'

async function setupMatomo(app: App, router: any) {
export async function setupMatomo(app: App, router: Router) {
try {
const client = new SettingsClient()
const response = await client.fetchFrontendSettings()
Expand All @@ -27,5 +28,3 @@ async function setupMatomo(app: App, router: any) {
console.error('Failed to initialize Matomo:', error)
}
}

export default setupMatomo
41 changes: 41 additions & 0 deletions frontend/src/plugins/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* plugins/sentry.ts
*
* Integration of sentry into our frontend.
*/
import * as Sentry from '@sentry/vue'
import { type App } from 'vue'
import { type Router } from 'vue-router'

export async function setupSentry(app: App, router: Router) {
Sentry.init({
app,
dsn: 'https://[email protected]/7',
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router)
}),
new Sentry.Replay()
],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,

// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
tracePropagationTargets: [
// 'localhost',
// '127.0.0.1',
/^https:\/\/reev.bihealth.org\//,
/^https:\/\/reev.cubi.bihealth.org\//,
/^https:\/\/reev-staging.bihealth.org\//,
/^https:\/\/reev-staging.cubi.bihealth.org\//
],

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0
})
}

0 comments on commit 732cff6

Please sign in to comment.