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

feat: integrating sentry (#240) #246

Merged
merged 3 commits into from
Nov 30, 2023
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
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
})
}
Loading