From 2b47bde7d28239126927d10d965910a2022771f6 Mon Sep 17 00:00:00 2001 From: FCasal-LI Date: Wed, 15 Oct 2025 10:55:28 -0300 Subject: [PATCH 1/2] feat: add sentry configuration --- .env.example | 3 +++ app/core/config.py | 3 +++ app/main.py | 8 ++++++++ poetry.lock | 14 +++++++++----- pyproject.toml | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 8fc15a1..bc4842a 100644 --- a/.env.example +++ b/.env.example @@ -17,3 +17,6 @@ POSTGRES_PORT=5432 ACCESS_TOKEN_EXPIRE_MINUTES=480 ALGORITHM=HS256 AUTHENTICATION_API_RATE_LIMIT="5 per minute" + +# Sentry +SENTRY_DSN=" diff --git a/app/core/config.py b/app/core/config.py index a8be960..c42fcfc 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -50,6 +50,9 @@ class Settings(BaseSettings): SEND_WELCOME_EMAIL_MAX_RETRIES: int = 5 SEND_WELCOME_EMAIL_RETRY_BACKOFF_VALUE: int = 5 + # Sentry + SENTRY_DSN: Optional[str] = None + @field_validator("BACKEND_CORS_ORIGINS", mode="before") @classmethod def assemble_cors_origins( diff --git a/app/main.py b/app/main.py index 18be94a..da1c873 100644 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,7 @@ from celery import Celery import structlog +import sentry_sdk from asgi_correlation_id import CorrelationIdMiddleware from asgi_correlation_id.context import correlation_id from fastapi import FastAPI, Request, Response, status @@ -24,6 +25,13 @@ settings = get_settings() +if settings.SENTRY_DSN: + sentry_sdk.init( + dsn=settings.SENTRY_DSN, + environment=settings.RUN_ENV, + send_default_pii=True, + ) + app = FastAPI( title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json", diff --git a/poetry.lock b/poetry.lock index 9a8cf7d..3773be8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. [[package]] name = "alembic" @@ -1501,18 +1501,19 @@ files = [ [[package]] name = "sentry-sdk" -version = "2.32.0" +version = "2.42.0" description = "Python client for Sentry (https://sentry.io)" optional = false python-versions = ">=3.6" groups = ["main"] files = [ - {file = "sentry_sdk-2.32.0-py2.py3-none-any.whl", hash = "sha256:6cf51521b099562d7ce3606da928c473643abe99b00ce4cb5626ea735f4ec345"}, - {file = "sentry_sdk-2.32.0.tar.gz", hash = "sha256:9016c75d9316b0f6921ac14c8cd4fb938f26002430ac5be9945ab280f78bec6b"}, + {file = "sentry_sdk-2.42.0-py2.py3-none-any.whl", hash = "sha256:1a7986e638306ff158f52dd47d9480a4055e6c289388caa90628acb2563fe7bd"}, + {file = "sentry_sdk-2.42.0.tar.gz", hash = "sha256:91c69c9372fb5fb4df0ac39456ccf7286f0428b3ee1cdd389f9dd36c04e0f5c9"}, ] [package.dependencies] certifi = "*" +fastapi = {version = ">=0.79.0", optional = true, markers = "extra == \"fastapi\""} urllib3 = ">=1.26.11" [package.extras] @@ -1530,13 +1531,16 @@ django = ["django (>=1.8)"] falcon = ["falcon (>=1.4)"] fastapi = ["fastapi (>=0.79.0)"] flask = ["blinker (>=1.1)", "flask (>=0.11)", "markupsafe"] +google-genai = ["google-genai (>=1.29.0)"] grpcio = ["grpcio (>=1.21.1)", "protobuf (>=3.8.0)"] http2 = ["httpcore[http2] (==1.*)"] httpx = ["httpx (>=0.16.0)"] huey = ["huey (>=2)"] huggingface-hub = ["huggingface_hub (>=0.22)"] langchain = ["langchain (>=0.0.210)"] +langgraph = ["langgraph (>=0.6.6)"] launchdarkly = ["launchdarkly-server-sdk (>=9.8.0)"] +litellm = ["litellm (>=1.77.5)"] litestar = ["litestar (>=2.0.0)"] loguru = ["loguru (>=0.5)"] openai = ["openai (>=1.0.0)", "tiktoken (>=0.3.0)"] @@ -1975,4 +1979,4 @@ files = [ [metadata] lock-version = "2.1" python-versions = "^3.12" -content-hash = "4015dedd088923bf789af57f6dd347b73115ea53a15d20d34a429168fcc3272e" +content-hash = "47a86dfbd5156f8a671a26f098606f96591e4c56c6ea104f2a585ffcbbce7bf2" diff --git a/pyproject.toml b/pyproject.toml index 963e10e..bcc756a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ celery = "^5.4.0" pyjwt = "^2.10.1" pyotp = "^2.9.0" psycopg2-binary = "^2.9.10" +sentry-sdk = {extras = ["fastapi"], version = "^2.42.0"} [tool.poetry.group.dev.dependencies] From 9f7d6423ca2dbbe3bca454868306e774e5fcadab Mon Sep 17 00:00:00 2001 From: FCasal-LI Date: Wed, 15 Oct 2025 11:54:38 -0300 Subject: [PATCH 2/2] refactor: remove unused imports for Celery and structlog --- app/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/main.py b/app/main.py index 25652f3..33e57dd 100644 --- a/app/main.py +++ b/app/main.py @@ -2,8 +2,6 @@ from typing import Any from urllib.parse import urlparse -from celery import Celery -import structlog import sentry_sdk from asgi_correlation_id import CorrelationIdMiddleware from asgi_correlation_id.context import correlation_id