Skip to content

Commit 139a9ad

Browse files
authored
Don't send asyncio.CancelledError to Sentry (#3404)
1 parent 635c38d commit 139a9ad

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/dstack/_internal/server/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
SERVER_URL,
5959
UPDATE_DEFAULT_PROJECT,
6060
)
61+
from dstack._internal.server.utils import sentry_utils
6162
from dstack._internal.server.utils.logging import configure_logging
6263
from dstack._internal.server.utils.routers import (
6364
CustomORJSONResponse,
@@ -105,6 +106,7 @@ async def lifespan(app: FastAPI):
105106
enable_tracing=True,
106107
traces_sampler=_sentry_traces_sampler,
107108
profiles_sample_rate=settings.SENTRY_PROFILES_SAMPLE_RATE,
109+
before_send=sentry_utils.AsyncioCancelledErrorFilterEventProcessor(),
108110
)
109111
server_executor = ThreadPoolExecutor(max_workers=settings.SERVER_EXECUTOR_MAX_WORKERS)
110112
asyncio.get_running_loop().set_default_executor(server_executor)

src/dstack/_internal/server/utils/sentry_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import asyncio
12
import functools
3+
from typing import Optional
24

35
import sentry_sdk
6+
from sentry_sdk.types import Event, Hint
47

58

69
def instrument_background_task(f):
@@ -10,3 +13,12 @@ async def wrapper(*args, **kwargs):
1013
return await f(*args, **kwargs)
1114

1215
return wrapper
16+
17+
18+
class AsyncioCancelledErrorFilterEventProcessor:
19+
# See https://docs.sentry.io/platforms/python/configuration/filtering/#filtering-error-events
20+
def __call__(self, event: Event, hint: Hint) -> Optional[Event]:
21+
exc_info = hint.get("exc_info")
22+
if exc_info and isinstance(exc_info[1], asyncio.CancelledError):
23+
return None
24+
return event

0 commit comments

Comments
 (0)