Skip to content

Commit

Permalink
Merge branch 'sentry' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
NidalChateur committed Feb 18, 2024
2 parents 6654472 + 9e0f17d commit 8acab3c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/settings/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path

import sentry_sdk
from cryptography.fernet import Fernet
from dotenv import dotenv_values
from sqlalchemy import create_engine
Expand Down Expand Up @@ -54,3 +55,17 @@ def init_test_db(Base=Base, db_name="db_test.sqlite3"):
session = Session()

return session


SENTRY_DSN = env_vars.get("SENTRY_DSN")
if SENTRY_DSN:
sentry_sdk.init(
dsn=env_vars.get("SENTRY_DSN"),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
)
10 changes: 8 additions & 2 deletions src/utils/fernet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from ..settings.settings import fernet


Expand All @@ -9,11 +11,15 @@ def encrypt(value: str) -> str:
try:
return fernet.encrypt(value.encode()).decode()
except Exception as e:
print(f"encrypt error : {e}")
error_msg = f"encrypt error : {e}"
print(error_msg)
logging.exception(error_msg)

@staticmethod
def decrypt(value: str) -> str:
try:
return fernet.decrypt(value.encode()).decode()
except Exception as e:
print(f"decrypt error : {e}")
error_msg = f"decrypt error : {e}"
print(error_msg)
logging.exception(error_msg)
5 changes: 5 additions & 0 deletions src/views/mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys

from rich.console import Console
import logging

console = Console()

Expand All @@ -15,6 +16,7 @@ def print_create_success(self, obj):
success_msg = f"{self.name.title()}{obj.id} créé avec succès !\n"

console.print(success_msg, style="bold green")
logging.info(success_msg)

@classmethod
def print_update_success(self, obj):
Expand All @@ -23,11 +25,13 @@ def print_update_success(self, obj):
success_msg = f"{self.name.title()}{obj.id} modifié avec succès !\n"

console.print(success_msg, style="bold green")
logging.info(success_msg)

@classmethod
def print_delete_success(self, obj_id: int):
success_msg = f"\n\n{self.name.title()}{obj_id} supprimé avec succès !\n\n"
console.print(success_msg, style="bold green")
logging.info(success_msg)

@classmethod
def print_signature_success(self, session, obj):
Expand All @@ -37,6 +41,7 @@ def print_signature_success(self, session, obj):
)

console.print(success_msg1, style="bold green")
logging.info(success_msg1)

success_msg2 = f"Vous pouvez maintenant créer un événement pour le {self.name}{obj.id}.\n"

Expand Down

0 comments on commit 8acab3c

Please sign in to comment.