Skip to content

Commit ef542dc

Browse files
committed
Add sentry to our task queues
1 parent 1434d1b commit ef542dc

File tree

9 files changed

+47
-16
lines changed

9 files changed

+47
-16
lines changed

alws/app.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import importlib
22
import logging
33

4-
import sentry_sdk
54
from fastapi import FastAPI
65
from fastapi_sqla import setup as fastapi_sqla_setup
7-
from pika.exceptions import StreamLostError
86
from starlette.middleware.exceptions import ExceptionMiddleware
97

108
from alws import routers
@@ -16,6 +14,7 @@
1614
from alws.config import settings
1715
from alws.middlewares import handlers
1816
from alws.utils.limiter import limiter_shutdown, limiter_startup
17+
from alws.utils.sentry import sentry_init
1918

2019
logging.basicConfig(level=settings.logging_level)
2120

@@ -27,16 +26,7 @@
2726
AUTH_PREFIX = APP_PREFIX + '/auth'
2827
AUTH_TAG = 'auth'
2928

30-
if settings.sentry_dsn:
31-
sentry_sdk.init(
32-
dsn=settings.sentry_dsn,
33-
traces_sample_rate=settings.sentry_traces_sample_rate,
34-
environment=settings.sentry_environment,
35-
ignore_errors=[
36-
ConnectionResetError,
37-
StreamLostError,
38-
],
39-
)
29+
sentry_init()
4030

4131

4232
app = FastAPI()

alws/dramatiq/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@
3838
move_issues,
3939
set_build_id_to_issues,
4040
)
41+
from alws.utils.sentry import sentry_init
42+
4143

4244
__all__ = ['start_build', 'build_done']
4345

4446
logger = logging.getLogger(__name__)
4547

48+
sentry_init()
4649

4750
def _sync_fetch_build(db: Session, build_id: int) -> models.Build:
4851
query = select(models.Build).where(models.Build.id == build_id)

alws/dramatiq/errata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
)
1515
from alws.dramatiq import event_loop
1616
from alws.utils.fastapi_sqla_setup import setup_all
17+
from alws.utils.sentry import sentry_init
1718

1819
__all__ = ["release_errata"]
1920

2021

22+
sentry_init()
23+
24+
2125
async def _create_new_errata_record(errata):
2226
await create_new_errata_record(errata)
2327

alws/dramatiq/products.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
from alws.utils.fastapi_sqla_setup import setup_all
1818
from alws.utils.log_utils import setup_logger
1919
from alws.utils.pulp_client import PulpClient
20+
from alws.utils.sentry import sentry_init
2021

2122
__all__ = ['perform_product_modification']
2223

2324
logger = setup_logger(__name__)
2425

2526

27+
sentry_init()
28+
29+
2630
async def get_existing_packages(
2731
pulp_client: PulpClient,
2832
repository: models.Repository,

alws/dramatiq/releases.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from contextlib import asynccontextmanager
2-
31
import dramatiq
42
from fastapi_sqla import open_async_session
53

@@ -8,10 +6,14 @@
86
from alws.dependencies import get_async_db_key
97
from alws.dramatiq import event_loop
108
from alws.utils.fastapi_sqla_setup import setup_all
9+
from alws.utils.sentry import sentry_init
1110

1211
__all__ = ["execute_release_plan"]
1312

1413

14+
sentry_init()
15+
16+
1517
async def _commit_release(release_id, user_id):
1618
async with open_async_session(key=get_async_db_key()) as db:
1719
await r_crud.commit_release(db, release_id, user_id)

alws/dramatiq/sign_task.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import typing
22

33
import dramatiq
4-
54
from alws.constants import DRAMATIQ_TASK_TIMEOUT
65
from alws.crud import sign_task
76
from alws.dramatiq import event_loop
87
from alws.schemas import sign_schema
98
from alws.utils.fastapi_sqla_setup import setup_all
9+
from alws.utils.sentry import sentry_init
1010

1111
__all__ = ['complete_sign_task']
1212

1313

14+
sentry_init()
15+
16+
1417
async def _complete_sign_task(
1518
task_id: int, payload: typing.Dict[str, typing.Any]
1619
):

alws/dramatiq/tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33

44
import dramatiq
55
from fastapi_sqla import open_async_session
6-
76
from alws.constants import DRAMATIQ_TASK_TIMEOUT, TestTaskStatus
87
from alws.crud import test as t_crud
98
from alws.dependencies import get_async_db_key
109
from alws.dramatiq import event_loop
1110
from alws.schemas.test_schema import TestTaskResult
1211
from alws.utils.fastapi_sqla_setup import setup_all
12+
from alws.utils.sentry import sentry_init
1313

1414
__all__ = ['complete_test_task']
1515

1616

17+
sentry_init()
18+
19+
1720
async def _complete_test_task(task_id: int, task_result: TestTaskResult):
1821
async with open_async_session(key=get_async_db_key()) as db:
1922
try:

alws/dramatiq/user.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
from alws.dependencies import get_async_db_key
1010
from alws.dramatiq import event_loop
1111
from alws.utils.fastapi_sqla_setup import setup_all
12+
from alws.utils.sentry import sentry_init
1213

1314
__all__ = ['perform_user_removal']
1415

1516

17+
sentry_init()
18+
19+
1620
async def _perform_user_removal(user_id: int):
1721
async with open_async_session(key=get_async_db_key()) as db:
1822
# Remove builds

alws/utils/sentry.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sentry_sdk
2+
from pika.exceptions import StreamLostError
3+
4+
from alws.config import settings
5+
6+
7+
def sentry_init():
8+
if not settings.sentry_dsn:
9+
return
10+
sentry_sdk.init(
11+
dsn=settings.sentry_dsn,
12+
traces_sample_rate=settings.sentry_traces_sample_rate,
13+
environment=settings.sentry_environment,
14+
ignore_errors=[
15+
ConnectionResetError,
16+
StreamLostError,
17+
],
18+
)

0 commit comments

Comments
 (0)