diff --git a/.env.example b/.env.example index 299a9ff..bb03764 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,11 @@ # HOST=0.0.0.0 # PORT=8000 # RELOAD=True + +# Sentry Configuration +# SENTRY_DSN=https://a5da7e2cd15fd85150e012a6d62fc13c@sentry.pirogov.ai/26 +# SENTRY_ENVIRONMENT=production +# SENTRY_TRACES_SAMPLE_RATE=0.2 +# SENTRY_PROFILES_SAMPLE_RATE=0.1 +# SENTRY_SEND_DEFAULT_PII=true + diff --git a/.env.test b/.env.test index 1256174..3cafb81 100644 --- a/.env.test +++ b/.env.test @@ -26,3 +26,11 @@ FILESAPTH = audiofiles GIGAAM_API_URL = http://host.docker.internal:5002 CALLS_WEB_CLIENT_URL=http://web_client_test:8642 AUDIO_FILES_PATH_TEST=D:\SpeechAnalitics\audiofiles + +# Sentry Configuration +SENTRY_DSN=https://a5da7e2cd15fd85150e012a6d62fc13c@sentry.pirogov.ai/26 +SENTRY_ENVIRONMENT=test +SENTRY_TRACES_SAMPLE_RATE=0.2 +SENTRY_PROFILES_SAMPLE_RATE=0.1 +SENTRY_SEND_DEFAULT_PII=true + diff --git a/apiApp/config.py b/apiApp/config.py index 33cb42c..5237d29 100644 --- a/apiApp/config.py +++ b/apiApp/config.py @@ -43,4 +43,11 @@ AUTO_RESTORE_LIMIT = int(os.getenv("AUTO_RESTORE_LIMIT", "100")) # Максим AUTO_RESTORE_DELAY = int(os.getenv("AUTO_RESTORE_DELAY", "5")) # Задержка перед запуском (секунды) # Recognition retry policy (FileAudioAPI side) -MAX_RECOGNITION_ATTEMPTS = int(os.getenv("MAX_RECOGNITION_ATTEMPTS", "3")) \ No newline at end of file +MAX_RECOGNITION_ATTEMPTS = int(os.getenv("MAX_RECOGNITION_ATTEMPTS", "3")) + +# Sentry Configuration +SENTRY_DSN = os.getenv("SENTRY_DSN", "") +SENTRY_ENVIRONMENT = os.getenv("SENTRY_ENVIRONMENT", "production") +SENTRY_TRACES_SAMPLE_RATE = float(os.getenv("SENTRY_TRACES_SAMPLE_RATE", "0.2")) +SENTRY_PROFILES_SAMPLE_RATE = float(os.getenv("SENTRY_PROFILES_SAMPLE_RATE", "0.1")) +SENTRY_SEND_DEFAULT_PII = os.getenv("SENTRY_SEND_DEFAULT_PII", "true").lower() == "true" \ No newline at end of file diff --git a/main.py b/main.py index 001b180..c38ac53 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,10 @@ from fastapi.middleware.cors import CORSMiddleware from sqlalchemy.exc import SQLAlchemyError import logging -from apiApp.config import APP_TITLE, APP_VERSION, API_V1_PREFIX, UPLOAD_FOLDER, DATABASE_URL, PORT, HOST +from apiApp.config import ( + APP_TITLE, APP_VERSION, API_V1_PREFIX, UPLOAD_FOLDER, DATABASE_URL, PORT, HOST, + SENTRY_DSN, SENTRY_ENVIRONMENT, SENTRY_TRACES_SAMPLE_RATE, SENTRY_PROFILES_SAMPLE_RATE, SENTRY_SEND_DEFAULT_PII +) from apiApp.database import engine, Base from apiApp.routers import audio_router, recognition_router from apiApp.routers.ai_conclusion_router import ai_conclusion_router @@ -19,6 +22,20 @@ print("✅ audio_management_router imported successfully") logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) +# Инициализация Sentry SDK до создания FastAPI приложения +if SENTRY_DSN: + import sentry_sdk + + sentry_sdk.init( + dsn=SENTRY_DSN, + traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE, + profiles_sample_rate=SENTRY_PROFILES_SAMPLE_RATE, + send_default_pii=SENTRY_SEND_DEFAULT_PII, + environment=SENTRY_ENVIRONMENT, + release=f"speech-fileaudio-api@{APP_VERSION}", + ) + logger.info("✅ Sentry initialized for speech-fileaudio-api") + # Создание FastAPI приложения app = FastAPI( title=APP_TITLE, @@ -28,6 +45,13 @@ app = FastAPI( openapi_url=f"{API_V1_PREFIX}/openapi.json" ) +@app.get("/sentry-debug") +async def trigger_sentry_debug(): + """Эндпоинт для проверки интеграции Sentry""" + division_by_zero = 1 / 0 + return {"status": "ok"} + + # CORS middleware app.add_middleware( CORSMiddleware, diff --git a/requirements.txt b/requirements.txt index 34206bc..5e6a023 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ python-multipart==0.0.12 aiofiles==24.1.0 psycopg2-binary paramiko -requests \ No newline at end of file +requests +sentry-sdk[fastapi]>=2.0.0 \ No newline at end of file