From 56a5c81fe41209301d6e8745e1966f0dab0cca13 Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Mon, 27 Nov 2023 10:08:00 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20sentry=20(#1716)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reduce sampling # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --- backend/chat_service.py | 8 -------- backend/crawl_service.py | 11 ----------- backend/main.py | 16 ++++++++++++++-- backend/requirements.txt | 4 ++-- backend/upload_service.py | 9 --------- 5 files changed, 16 insertions(+), 32 deletions(-) diff --git a/backend/chat_service.py b/backend/chat_service.py index 673166a2e..ba540bbc9 100644 --- a/backend/chat_service.py +++ b/backend/chat_service.py @@ -20,14 +20,6 @@ from routes.misc_routes import misc_router logger = get_logger(__name__) -sentry_dsn = os.getenv("SENTRY_DSN") -if sentry_dsn: - sentry_sdk.init( - dsn=sentry_dsn, - traces_sample_rate=0.1, - profiles_sample_rate=0.1, - ) - app = FastAPI() add_cors_middleware(app) diff --git a/backend/crawl_service.py b/backend/crawl_service.py index b9537f49a..6c7988df5 100644 --- a/backend/crawl_service.py +++ b/backend/crawl_service.py @@ -1,4 +1,3 @@ -import os from packages.utils import handle_request_validation_error @@ -8,7 +7,6 @@ if __name__ == "__main__": from dotenv import load_dotenv # type: ignore load_dotenv() -import sentry_sdk from fastapi import FastAPI, HTTPException from fastapi.responses import JSONResponse from logger import get_logger @@ -17,15 +15,6 @@ from routes.crawl_routes import crawl_router from routes.misc_routes import misc_router logger = get_logger(__name__) - -sentry_dsn = os.getenv("SENTRY_DSN") -if sentry_dsn: - sentry_sdk.init( - dsn=sentry_dsn, - traces_sample_rate=0.1, - profiles_sample_rate=0.1, - ) - app = FastAPI() add_cors_middleware(app) diff --git a/backend/main.py b/backend/main.py index 55b60b17e..51fcd5bbc 100644 --- a/backend/main.py +++ b/backend/main.py @@ -27,6 +27,8 @@ from routes.misc_routes import misc_router from routes.notification_routes import notification_router from routes.subscription_routes import subscription_router from routes.upload_routes import upload_router +from sentry_sdk.integrations.starlette import StarletteIntegration +from sentry_sdk.integrations.fastapi import FastApiIntegration logger = get_logger(__name__) @@ -41,8 +43,18 @@ sentry_dsn = os.getenv("SENTRY_DSN") if sentry_dsn: sentry_sdk.init( dsn=sentry_dsn, - traces_sample_rate=0.1, - profiles_sample_rate=0.1, + traces_sample_rate=0.1, + profiles_sample_rate=0.1, + sample_rate=0.1, + enable_tracing=True, + integrations=[ + StarletteIntegration( + transaction_style="endpoint" + ), + FastApiIntegration( + transaction_style="endpoint" + ), + ] ) app = FastAPI() diff --git a/backend/requirements.txt b/backend/requirements.txt index 148bb6093..eb4730a74 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -13,13 +13,13 @@ fastapi==0.95.2 python-multipart==0.0.6 uvicorn==0.22.0 pypandoc==1.11 - docx2txt==0.8 python-jose==3.3.0 asyncpg==0.27.0 flake8==6.0.0 flake8-black==0.3.6 -sentry-sdk==1.26.0 +sentry-sdk==1.37.1 +sentry-sdk[fastapi]==1.37.1 pyright==1.1.316 resend==0.5.1 html5lib==1.1 diff --git a/backend/upload_service.py b/backend/upload_service.py index b2cbb5267..d776c07ac 100644 --- a/backend/upload_service.py +++ b/backend/upload_service.py @@ -18,15 +18,6 @@ from routes.misc_routes import misc_router from routes.upload_routes import upload_router logger = get_logger(__name__) - -sentry_dsn = os.getenv("SENTRY_DSN") -if sentry_dsn: - sentry_sdk.init( - dsn=sentry_dsn, - traces_sample_rate=0.1, - profiles_sample_rate=0.1, - ) - app = FastAPI()