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

Add initial sentry configuration for API #44

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This project supports [microk8s](https://microk8s.io/) development environment w

### 1. Install required tools

- Install [docker](https://snapcraft.io/docker) and setup permissions
- Install [docker](https://docs.docker.com/engine/install/ubuntu/) and [setup permissions](https://docs.docker.com/engine/install/linux-postinstall/)
- Install [microk8s](https://microk8s.io/docs/getting-started) and setup permissions
- Install [Skaffold](https://skaffold.dev/docs/install/#standalone-binary)
- Install [Poetry](https://python-poetry.org/docs/#installation)
Expand Down
3 changes: 3 additions & 0 deletions backend/k8s/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ spec:
image: localhost:32000/test-observer-api
ports:
- containerPort: 30000
env:
- name: SENTRY_DSN
value: "https://[email protected]//66"
nadzyah marked this conversation as resolved.
Show resolved Hide resolved
initContainers:
- name: wait-for-db-migrations
image: ghcr.io/groundnuty/k8s-wait-for:v2.0
Expand Down
50 changes: 47 additions & 3 deletions backend/poetry.lock

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

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg8000 = "^1.29.4"
alembic = "^1.10.3"
poetry-dynamic-versioning = {extras = ["plugin"], version = "^0.22.0"}
requests = "^2.31.0"
sentry-sdk = "0.10.2"

[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
Expand Down
6 changes: 6 additions & 0 deletions backend/test_observer/controllers/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@
def root(db: Session = Depends(get_db)):
db.execute(text("select 'test db connection'"))
return "test observer api"


@router.get("/sentry-debug")
def trigger_error():
division_by_zero = 1 / 0
return division_by_zero
nadzyah marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion backend/test_observer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@
# Omar Abou Selo <[email protected]>
# Nadzeya Hutsko <[email protected]>

import os

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import sentry_sdk


from test_observer.controllers.router import router

app = FastAPI()

SENTRY_DSN = os.getenv("SENTRY_DSN")
nadzyah marked this conversation as resolved.
Show resolved Hide resolved
if SENTRY_DSN:
sentry_sdk.init(SENTRY_DSN) # type: ignore
Copy link
Collaborator Author

@nadzyah nadzyah Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, I had to tell mypy to ignore Cannot instantiate abstract class "init" with abstract attribute "__exit__" [abstract] error while initialising sentry client. It's a known bug that was fixed in later versions. But since our self-hosted Sentry instance doesn't support latest clients that include this bug fix, we have to go with this approach.



app = FastAPI()

app.add_middleware(
CORSMiddleware,
Expand Down