feat(sentry): remove Sentry
This commit is contained in:
@ -21,9 +21,6 @@ from app.utils.n8n import get_tasks, submit_task
|
||||
|
||||
log: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
if config.sentry_enabled:
|
||||
import sentry_sdk
|
||||
|
||||
|
||||
class SubmitTaskCommand(Command):
|
||||
"""Submit task command."""
|
||||
@ -126,10 +123,7 @@ class SubmitTaskCommand(Command):
|
||||
],
|
||||
)
|
||||
_result = response_from_adaptive_card(card)
|
||||
if not config.sentry_enabled:
|
||||
return _result
|
||||
with sentry_sdk.start_transaction(name="submit_task_command"):
|
||||
return _result
|
||||
return _result
|
||||
|
||||
|
||||
class SubmitTaskCallback(Command):
|
||||
@ -173,10 +167,7 @@ class SubmitTaskCallback(Command):
|
||||
|
||||
def execute(self, message, attachment_actions, activity) -> str:
|
||||
"""Execute method."""
|
||||
if not config.sentry_enabled:
|
||||
return self.msg
|
||||
with sentry_sdk.start_transaction(name="submit_task_callback"):
|
||||
return self.msg
|
||||
return self.msg
|
||||
|
||||
|
||||
class MyTasksCallback(Command):
|
||||
@ -193,21 +184,13 @@ class MyTasksCallback(Command):
|
||||
def pre_execute(self, message, attachment_actions, activity) -> str:
|
||||
"""Pre-execute method."""
|
||||
_msg: str = "Getting your tasks..."
|
||||
if not config.sentry_enabled:
|
||||
return _msg
|
||||
with sentry_sdk.start_transaction(name="my_tasks_preexec"):
|
||||
return _msg
|
||||
return _msg
|
||||
|
||||
def execute(self, message, attachment_actions, activity) -> str | None:
|
||||
"""Execute method."""
|
||||
sender: str = attachment_actions.inputs.get("sender")
|
||||
result: bool = get_tasks(requestor=sender)
|
||||
_msg: str = "Failed to get tasks. Please try again."
|
||||
if not config.sentry_enabled:
|
||||
if not result:
|
||||
return _msg
|
||||
return None
|
||||
with sentry_sdk.start_transaction(name="my_tasks_exec"):
|
||||
if not result:
|
||||
return _msg
|
||||
return None
|
||||
if not result:
|
||||
return _msg
|
||||
return None
|
||||
|
13
app/main.py
13
app/main.py
@ -2,25 +2,12 @@
|
||||
|
||||
import sys
|
||||
|
||||
from sentry_sdk.integrations.stdlib import StdlibIntegration
|
||||
from webex_bot.webex_bot import WebexBot
|
||||
|
||||
from app.commands.exit import ExitCommand
|
||||
from app.commands.submit_task import SubmitTaskCommand
|
||||
from app.utils.config import config
|
||||
|
||||
if config.sentry_enabled:
|
||||
import sentry_sdk
|
||||
|
||||
apm = sentry_sdk.init(
|
||||
dsn=config.sentry_dsn,
|
||||
enable_tracing=True,
|
||||
environment=config.environment,
|
||||
release=config.version,
|
||||
integrations=[StdlibIntegration()],
|
||||
spotlight=True,
|
||||
)
|
||||
|
||||
|
||||
def create_bot() -> WebexBot:
|
||||
"""Create and return a Webex Bot object."""
|
||||
|
@ -11,15 +11,6 @@ class Config:
|
||||
def __init__(self) -> None:
|
||||
"""Configuration module."""
|
||||
|
||||
# Sentry config needs to be processed first for loop prevention.
|
||||
|
||||
self.__sentry_dsn: str = os.environ.get("SENTRY_DSN", "")
|
||||
|
||||
self.__sentry_enabled: bool = bool(
|
||||
os.environ.get("SENTRY_ENABLED", "False").upper() == "TRUE"
|
||||
and self.__sentry_dsn != ""
|
||||
)
|
||||
|
||||
@property
|
||||
def environment(self) -> str:
|
||||
"""Returns the current app lifecycle."""
|
||||
@ -30,19 +21,6 @@ class Config:
|
||||
"""Returns the current app version."""
|
||||
return os.environ["APP_VERSION"]
|
||||
|
||||
@property
|
||||
def sentry_enabled(self) -> bool:
|
||||
"""Returns True if Sentry SDK is enabled, else False."""
|
||||
return self.__sentry_enabled
|
||||
|
||||
@property
|
||||
def sentry_dsn(self) -> str:
|
||||
"""Returns the Sentry DSN value if Sentry SDK is enabled AND
|
||||
Sentry DSN is set, else blank string."""
|
||||
if not self.__sentry_enabled:
|
||||
return ""
|
||||
return self.__sentry_dsn
|
||||
|
||||
@property
|
||||
def bot_name(self) -> str:
|
||||
"""Returns the bot name."""
|
||||
|
@ -4,9 +4,6 @@ import requests
|
||||
|
||||
from app.utils.config import config
|
||||
|
||||
if config.sentry_enabled:
|
||||
import sentry_sdk
|
||||
|
||||
|
||||
def __n8n_post(data: dict) -> bool:
|
||||
"""Post data to N8N webhook URL.
|
||||
@ -46,12 +43,8 @@ def submit_task(summary, description, completion_date, requestor) -> bool:
|
||||
"description": description,
|
||||
"completiondate": completion_date,
|
||||
}
|
||||
if not config.sentry_enabled:
|
||||
_data = __n8n_post(data=data)
|
||||
return _data
|
||||
with sentry_sdk.start_transaction(name="submit_task"):
|
||||
_data = __n8n_post(data=data)
|
||||
return _data
|
||||
_data = __n8n_post(data=data)
|
||||
return _data
|
||||
|
||||
|
||||
def get_tasks(requestor) -> bool:
|
||||
@ -64,23 +57,12 @@ def get_tasks(requestor) -> bool:
|
||||
bool: True if successful, else False.
|
||||
"""
|
||||
headers: dict = {"Content-Type": "application/json"}
|
||||
if not config.sentry_enabled:
|
||||
resp: requests.Response = requests.get(
|
||||
url=config.n8n_webhook_url,
|
||||
headers=headers,
|
||||
timeout=10,
|
||||
verify=False,
|
||||
params={"requestor": requestor},
|
||||
)
|
||||
_data = bool(resp.status_code == 200)
|
||||
return _data
|
||||
with sentry_sdk.start_transaction(name="get_tasks"):
|
||||
resp: requests.Response = requests.get(
|
||||
url=config.n8n_webhook_url,
|
||||
headers=headers,
|
||||
timeout=10,
|
||||
verify=False,
|
||||
params={"requestor": requestor},
|
||||
)
|
||||
_data = bool(resp.status_code == 200)
|
||||
return _data
|
||||
resp: requests.Response = requests.get(
|
||||
url=config.n8n_webhook_url,
|
||||
headers=headers,
|
||||
timeout=10,
|
||||
verify=False,
|
||||
params={"requestor": requestor},
|
||||
)
|
||||
_data = bool(resp.status_code == 200)
|
||||
return _data
|
||||
|
Reference in New Issue
Block a user