Skip to content

Commit efa2431

Browse files
committed
add sentry
1 parent cf00ce9 commit efa2431

7 files changed

Lines changed: 25 additions & 5 deletions

File tree

_shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildInputs = [
99
nodejs_24 #for the doc
1010
];
1111
shellHook = ''
12-
export VARIABLE_NAME="variable value"
12+
export SENTRY_DSN="variable value"
1313
'';
1414

1515
}
604 Bytes
Binary file not shown.
244 Bytes
Binary file not shown.

backend/main.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
from fastapi import FastAPI
2+
from var import SENTRY_DSN
3+
import sentry_sdk
4+
import logging
5+
logger = logging.getLogger(__name__)
26

3-
app = FastAPI()
7+
sentry_sdk.init(
8+
dsn=SENTRY_DSN,
9+
# Add data like request headers and IP for users,
10+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
11+
send_default_pii=True,
12+
enable_logs=True,
13+
)
414

15+
app = FastAPI()
516

617
@app.get("/")
718
def read_root():
@@ -10,4 +21,9 @@ def read_root():
1021

1122
@app.get("/items/{item_id}")
1223
def read_item(item_id: int, q: str | None = None):
13-
return {"item_id": item_id, "q": q}
24+
return {"item_id": item_id, "q": q}
25+
26+
@app.get("/sentry-debug")
27+
async def trigger_error():
28+
logger.info('This will be sent to Sentry')
29+
division_by_zero = 1 / 0

backend/poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ license = {text = "MIT"}
99
readme = "README.md"
1010
requires-python = ">=3.13"
1111
dependencies = [
12-
"fastapi[standard] (>=0.136.1,<0.137.0)"
12+
"fastapi[standard] (>=0.136.1,<0.137.0)",
13+
"sentry-sdk (>=2.58.0,<3.0.0)"
1314
]
1415

1516
[dependency-groups]

backend/var.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import os
2+
3+
SENTRY_DSN = os.environ['SENTRY_DSN']

0 commit comments

Comments
 (0)