-
Notifications
You must be signed in to change notification settings - Fork 45
feat(cdk): add sentry_sdk.capture_message() to MemoryMonitor for high-memory warnings (AI-Triage PR) #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cdk): add sentry_sdk.capture_message() to MemoryMonitor for high-memory warnings (AI-Triage PR) #958
Changes from 2 commits
4e77c78
5a8ff06
374528a
0ecdbb2
7a0fa21
cfc7f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,11 @@ | |||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||
| from typing import Optional | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| import sentry_sdk | ||||||||||||||||||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||||||||||||||||||
| sentry_sdk = None # type: ignore[assignment] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| logger = logging.getLogger("airbyte") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # cgroup v2 paths | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -47,6 +52,7 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||
| self._message_count = 0 | ||||||||||||||||||||||||||||||||||||||||
| self._cgroup_version: Optional[int] = None | ||||||||||||||||||||||||||||||||||||||||
| self._probed = False | ||||||||||||||||||||||||||||||||||||||||
| self._sentry_alerted = False | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def _probe_cgroup(self) -> None: | ||||||||||||||||||||||||||||||||||||||||
| """Detect which cgroup version (if any) is available. | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -138,3 +144,10 @@ def check_memory_usage(self) -> None: | |||||||||||||||||||||||||||||||||||||||
| usage_gb, | ||||||||||||||||||||||||||||||||||||||||
| limit_gb, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| if not self._sentry_alerted and sentry_sdk is not None: | ||||||||||||||||||||||||||||||||||||||||
| self._sentry_alerted = True | ||||||||||||||||||||||||||||||||||||||||
| sentry_sdk.capture_message( | ||||||||||||||||||||||||||||||||||||||||
| "Source memory usage at %d%% of container limit (%.2f / %.2f GB)." | ||||||||||||||||||||||||||||||||||||||||
| % (usage_percent, usage_gb, limit_gb), | ||||||||||||||||||||||||||||||||||||||||
| level="warning", | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| self._sentry_alerted = True | |
| sentry_sdk.capture_message( | |
| "Source memory usage at %d%% of container limit (%.2f / %.2f GB)." | |
| % (usage_percent, usage_gb, limit_gb), | |
| level="warning", | |
| ) | |
| try: | |
| sentry_sdk.capture_message( | |
| "Source memory usage at %d%% of container limit (%.2f / %.2f GB)." | |
| % (usage_percent, usage_gb, limit_gb), | |
| level="warning", | |
| ) | |
| self._sentry_alerted = True | |
| except Exception as exc: | |
| logger.debug( | |
| "Failed to send memory usage alert to Sentry: %s", | |
| exc, | |
| exc_info=True, | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The soft-import fallback uses
sentry_sdk = None # type: ignore[assignment], which suppresses type checking for this symbol. To keep mypy coverage stronger, consider explicitly typing the variable (e.g.,sentry_sdk: object | None = None/Optional[Any]) and using# type: ignore[import-not-found](or aTYPE_CHECKINGimport) instead of ignoring the assignment.