-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): integrate Sentry for error tracking and monitoring (#171)
This pull request introduces several changes to integrate Sentry for error monitoring and improve environment configuration to the API. The key changes include adding Sentry DSN variables, updating Docker and FastAPI configurations, and creating tests for the new settings. ### Sentry Integration: * [`.env.example`](diffhunk://#diff-a3046da0d15a27e89f2afe639b25748a7ad4d9290af3e7b1b6c1a5533c8f0a8cR13-R16): Added `SENTRY_DSN_API` and `SENTRY_DSN_APP` environment variables for Sentry integration. * [`api/requirements.txt`](diffhunk://#diff-f380e1392f38d13c3831f35c9f505277739b484c035bc791c21cc6d081845607R8): Added `sentry-sdk[fastapi]==2.19.0` to dependencies. * [`api/src/app.py`](diffhunk://#diff-f5e838a574b5fb82ba7600e7be68894c5c9f6a24cae7c0b04fd7ae57139afa17R2-R21): Initialized Sentry SDK with DSN and environment settings. * [`api/src/config.py`](diffhunk://#diff-7df7ccee5a6672bf04f67eebb5964559fbbf239d77f594c8756ba3110e56fae0R1-R26): Added `SENTRY_DSN` and `APP_ENV` settings to the configuration. [[1]](diffhunk://#diff-7df7ccee5a6672bf04f67eebb5964559fbbf239d77f594c8756ba3110e56fae0R1-R26) [[2]](diffhunk://#diff-7df7ccee5a6672bf04f67eebb5964559fbbf239d77f594c8756ba3110e56fae0R58-R59) * [`compose.yml`](diffhunk://#diff-3493e6b5ddf34891e572f911db893efd9e46af828e011ea778a7c1eb64763588L82-R87): Added `SENTRY_DSN` to the environment variables. ### Environment Configuration: * [`.env.example`](diffhunk://#diff-a3046da0d15a27e89f2afe639b25748a7ad4d9290af3e7b1b6c1a5533c8f0a8cL3-L4): Removed the `ENV` variable. * [`api/Dockerfile`](diffhunk://#diff-21ee93e31c9cec7a5f33b680622da377c451b62b6c44eac6d9550eade41beb47R24): Added `APP_ENV` environment variable for different stages (development, test, production). [[1]](diffhunk://#diff-21ee93e31c9cec7a5f33b680622da377c451b62b6c44eac6d9550eade41beb47R24) [[2]](diffhunk://#diff-21ee93e31c9cec7a5f33b680622da377c451b62b6c44eac6d9550eade41beb47R33-R38) ### CI/CD Integration: * [`.github/workflows/main.yml`](diffhunk://#diff-7829468e86c1cc5d5133195b5cb48e1ff6c75e3e9203777f6b2e379d9e4882b3R156-R166): Added a step to release to Sentry using GitHub Actions. ### Testing: * [`api/tests/test_config.py`](diffhunk://#diff-9c77b4f9a6f75032e644de8b5d501ca971379aaf4f4214f4f6e4b881959b8f00R1-R47): Added tests for the new settings, including scenarios with and without passwords and handling non-existent password files.
- Loading branch information
Showing
8 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pydantic-settings==2.3.4 | |
uvicorn==0.30.1 | ||
sqlmodel==0.0.19 | ||
databases[mysql] | ||
sentry-sdk[fastapi]==2.19.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pytest | ||
from pydantic import ValidationError | ||
from src.config import Settings | ||
|
||
def test_settings_with_password(): | ||
settings = Settings( | ||
MARIADB_SERVER="localhost", | ||
MARIADB_USER="user", | ||
MARIADB_PASSWORD="password", | ||
MARIADB_DB="test_db", | ||
SENTRY_DSN="http://example.com" | ||
) | ||
assert settings.MARIADB_PASSWORD == "password" | ||
assert str(settings.SQLALCHEMY_DATABASE_URI) == "mysql+pymysql://user:password@localhost:3306/test_db" | ||
|
||
def test_settings_with_password_file(tmp_path): | ||
password_file = tmp_path / "password.txt" | ||
password_file.write_text("file_password") | ||
|
||
settings = Settings( | ||
MARIADB_SERVER="localhost", | ||
MARIADB_USER="user", | ||
MARIADB_PASSWORD_FILE=str(password_file), | ||
MARIADB_DB="test_db", | ||
SENTRY_DSN="http://example.com" | ||
) | ||
assert settings.MARIADB_PASSWORD_FILE == "file_password" | ||
assert str(settings.SQLALCHEMY_DATABASE_URI) == "mysql+pymysql://user:file_password@localhost:3306/test_db" | ||
|
||
def test_settings_missing_password(): | ||
with pytest.raises(ValidationError): | ||
Settings( | ||
MARIADB_SERVER="localhost", | ||
MARIADB_USER="user", | ||
MARIADB_DB="test_db", | ||
SENTRY_DSN="http://example.com" | ||
) | ||
|
||
def test_password_file_does_not_exist(): | ||
with pytest.raises(ValueError, match="Password file /non/existent/path does not exist."): | ||
Settings( | ||
MARIADB_SERVER="localhost", | ||
MARIADB_USER="user", | ||
MARIADB_PASSWORD_FILE="/non/existent/path", | ||
MARIADB_DB="test_db", | ||
SENTRY_DSN="http://example.com" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters