diff --git a/app/main.py b/app/main.py index 2c23883..85cabe5 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ from datetime import datetime from typing import Any +import sentry_sdk from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse @@ -40,6 +41,14 @@ def render(self, content: Any) -> bytes: ).encode("utf-8") +if settings.sentry_dsn: + sentry_sdk.init( + dsn=settings.sentry_dsn, + environment=settings.environment, + traces_sample_rate=settings.sentry_traces_sample_rate, + send_default_pii=False, + ) + app = FastAPI( title=settings.app_name, version=settings.version, diff --git a/app/settings.py b/app/settings.py index f6d0092..3413a70 100644 --- a/app/settings.py +++ b/app/settings.py @@ -50,5 +50,12 @@ class Settings(BaseSettings): # Production restrictions disable_publisher_api: bool = False # Set to true in production + # Environment + environment: str = "development" # development, staging, production + + # Sentry + sentry_dsn: str | None = None + sentry_traces_sample_rate: float = 0.1 + settings = Settings() diff --git a/pyproject.toml b/pyproject.toml index 93fe572..e72a8e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ dependencies = [ "pyjwt[crypto]>=2.10.0", "python-multipart>=0.0.9", "redis>=5.2.0", + "sentry-sdk>=2.52.0", "signedshot>=0.1.0", "slowapi>=0.1.9", "sqlalchemy[asyncio]>=2.0.0", diff --git a/uv.lock b/uv.lock index 01b2b29..e1a813a 100644 --- a/uv.lock +++ b/uv.lock @@ -1395,6 +1395,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/4d/e1/7348090988095e4e39560cfc2f7555b1b2a7357deba19167b600fdf5215d/ruff-0.14.13-py3-none-win_arm64.whl", hash = "sha256:7ab819e14f1ad9fe39f246cfcc435880ef7a9390d81a2b6ac7e01039083dd247", size = 13080224, upload-time = "2026-01-15T20:14:45.853Z" }, ] +[[package]] +name = "sentry-sdk" +version = "2.52.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/59/eb/1b497650eb564701f9a7b8a95c51b2abe9347ed2c0b290ba78f027ebe4ea/sentry_sdk-2.52.0.tar.gz", hash = "sha256:fa0bec872cfec0302970b2996825723d67390cdd5f0229fb9efed93bd5384899", size = 410273, upload-time = "2026-02-04T15:03:54.706Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ca/63/2c6daf59d86b1c30600bff679d039f57fd1932af82c43c0bde1cbc55e8d4/sentry_sdk-2.52.0-py2.py3-none-any.whl", hash = "sha256:931c8f86169fc6f2752cb5c4e6480f0d516112e78750c312e081ababecbaf2ed", size = 435547, upload-time = "2026-02-04T15:03:51.567Z" }, +] + [[package]] name = "shellingham" version = "1.5.4" @@ -1432,6 +1445,7 @@ dependencies = [ { name = "pyjwt", extra = ["crypto"] }, { name = "python-multipart" }, { name = "redis" }, + { name = "sentry-sdk" }, { name = "signedshot" }, { name = "slowapi" }, { name = "sqlalchemy", extra = ["asyncio"] }, @@ -1464,6 +1478,7 @@ requires-dist = [ { name = "pyjwt", extras = ["crypto"], specifier = ">=2.10.0" }, { name = "python-multipart", specifier = ">=0.0.9" }, { name = "redis", specifier = ">=5.2.0" }, + { name = "sentry-sdk", specifier = ">=2.52.0" }, { name = "signedshot", specifier = ">=0.1.0" }, { name = "slowapi", specifier = ">=0.1.9" }, { name = "sqlalchemy", extras = ["asyncio"], specifier = ">=2.0.0" },