Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dstack/_internal/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
SERVER_URL,
UPDATE_DEFAULT_PROJECT,
)
from dstack._internal.server.utils import sentry_utils
from dstack._internal.server.utils.logging import configure_logging
from dstack._internal.server.utils.routers import (
CustomORJSONResponse,
Expand Down Expand Up @@ -105,6 +106,7 @@ async def lifespan(app: FastAPI):
enable_tracing=True,
traces_sampler=_sentry_traces_sampler,
profiles_sample_rate=settings.SENTRY_PROFILES_SAMPLE_RATE,
before_send=sentry_utils.AsyncioCancelledErrorFilterEventProcessor(),
)
server_executor = ThreadPoolExecutor(max_workers=settings.SERVER_EXECUTOR_MAX_WORKERS)
asyncio.get_running_loop().set_default_executor(server_executor)
Expand Down
12 changes: 12 additions & 0 deletions src/dstack/_internal/server/utils/sentry_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import asyncio
import functools
from typing import Optional

import sentry_sdk
from sentry_sdk.types import Event, Hint


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

return wrapper


class AsyncioCancelledErrorFilterEventProcessor:
# See https://docs.sentry.io/platforms/python/configuration/filtering/#filtering-error-events
def __call__(self, event: Event, hint: Hint) -> Optional[Event]:
exc_info = hint.get("exc_info")
if exc_info and isinstance(exc_info[1], asyncio.CancelledError):
return None
return event