From de8e6702ca9ca168d69807f92d1fb4d183ad6bb9 Mon Sep 17 00:00:00 2001 From: Paul Leclercq Date: Fri, 23 Feb 2024 11:15:52 +0100 Subject: [PATCH] feat sentry cron (#112) --- .../ingest_db/ingest_sitemap_in_db.py | 14 ++++++++++++++ .../data_processing/mediatree/api_import.py | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/quotaclimat/data_ingestion/ingest_db/ingest_sitemap_in_db.py b/quotaclimat/data_ingestion/ingest_db/ingest_sitemap_in_db.py index 6563d2fc..80c9bb3f 100644 --- a/quotaclimat/data_ingestion/ingest_db/ingest_sitemap_in_db.py +++ b/quotaclimat/data_ingestion/ingest_db/ingest_sitemap_in_db.py @@ -8,7 +8,19 @@ from postgres.schemas.models import create_tables, connect_to_db, get_last_month_sitemap_id from quotaclimat.utils.healthcheck_config import run_health_check_server from quotaclimat.utils.logger import CustomFormatter +import sentry_sdk +from sentry_sdk.crons import monitor +# read SENTRY_DSN from env +sentry_sdk.init( + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=0.7, + # Set profiles_sample_rate to 1.0 to profile 100% + # of sampled transactions. + # We recommend adjusting this value in production. + profiles_sample_rate=0.7, +) import asyncio from quotaclimat.data_ingestion.scrap_sitemap import \ @@ -38,6 +50,8 @@ async def batch_sitemap(exit_event): exit_event.set() return +#https://docs.sentry.io/platforms/python/crons/ +@monitor(monitor_slug='sitemap') async def main(): event_finish = asyncio.Event() # Start the health check server in the background diff --git a/quotaclimat/data_processing/mediatree/api_import.py b/quotaclimat/data_processing/mediatree/api_import.py index bb8b7ba0..ce99b422 100644 --- a/quotaclimat/data_processing/mediatree/api_import.py +++ b/quotaclimat/data_processing/mediatree/api_import.py @@ -22,6 +22,7 @@ from typing import List, Optional from tenacity import * import sentry_sdk +from sentry_sdk.crons import monitor # read SENTRY_DSN from env sentry_sdk.init( @@ -241,7 +242,9 @@ def log_dataframe_size(df, channel): logging.warning(f"High Dataframe size : {bytes_size / (1000 * 1000)}") if(len(df) == 1000): logging.error("We might lose data - df size is 1000 out of 1000 - we should divide this querry") - + +#https://docs.sentry.io/platforms/python/crons/ +@monitor(monitor_slug='mediatree') async def main(): logger.info("Start api mediatree import") create_tables()