-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
🔧 chore: remove redundant slack logging & metrics #82744
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b8140e
:wrench: chore: remove redundant slack logging & metrics
iamrajjoshi ee717e9
:mag: nit: remove unused constants
iamrajjoshi b9b6e4a
:wrench: chore: fix tests
iamrajjoshi 3eb0398
:wrench: chore: mypy
iamrajjoshi 98b451f
:wrench: chore: cleanup more logs & metrics
iamrajjoshi 6313966
:bug: fix: tests
iamrajjoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,7 @@ | |
from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder | ||
from sentry.integrations.slack.message_builder.notifications import get_message_builder | ||
from sentry.integrations.slack.message_builder.types import SlackBlock | ||
from sentry.integrations.slack.metrics import ( | ||
SLACK_ACTIVITY_THREAD_FAILURE_DATADOG_METRIC, | ||
SLACK_ACTIVITY_THREAD_SUCCESS_DATADOG_METRIC, | ||
SLACK_NOTIFY_RECIPIENT_FAILURE_DATADOG_METRIC, | ||
SLACK_NOTIFY_RECIPIENT_SUCCESS_DATADOG_METRIC, | ||
record_lifecycle_termination_level, | ||
) | ||
from sentry.integrations.slack.metrics import record_lifecycle_termination_level | ||
from sentry.integrations.slack.sdk_client import SlackSdkClient | ||
from sentry.integrations.slack.spec import SlackMessagingSpec | ||
from sentry.integrations.slack.threads.activity_notifications import ( | ||
|
@@ -58,7 +52,6 @@ | |
from sentry.silo.base import SiloMode | ||
from sentry.types.activity import ActivityType | ||
from sentry.types.actor import Actor | ||
from sentry.utils import metrics | ||
|
||
_default_logger = getLogger(__name__) | ||
|
||
|
@@ -206,24 +199,31 @@ def notify_all_threads_for_activity(self, activity: Activity) -> None: | |
|
||
# We don't wrap this in a lifecycle because _handle_parent_notification is already wrapped in a lifecycle | ||
for parent_notification in parent_notifications: | ||
try: | ||
self._handle_parent_notification( | ||
parent_notification=parent_notification, | ||
notification_to_send=notification_to_send, | ||
client=slack_client, | ||
) | ||
except Exception as err: | ||
# TODO(iamrajjoshi): We can probably swallow this error once we audit the lifecycle | ||
self._logger.info( | ||
"failed to send notification", | ||
exc_info=err, | ||
extra={ | ||
with MessagingInteractionEvent( | ||
interaction_type=MessagingInteractionType.SEND_ACTIVITY_NOTIFICATION, | ||
spec=SlackMessagingSpec(), | ||
).capture() as lifecycle: | ||
lifecycle.add_extras( | ||
{ | ||
"activity_id": activity.id, | ||
"parent_notification_id": parent_notification.id, | ||
"notification_to_send": notification_to_send, | ||
"integration_id": integration.id, | ||
}, | ||
"group_id": activity.group.id, | ||
"project_id": activity.project.id, | ||
} | ||
) | ||
try: | ||
self._handle_parent_notification( | ||
parent_notification=parent_notification, | ||
notification_to_send=notification_to_send, | ||
client=slack_client, | ||
) | ||
except Exception as err: | ||
if isinstance(err, SlackApiError): | ||
record_lifecycle_termination_level(lifecycle, err) | ||
else: | ||
lifecycle.record_failure(err) | ||
|
||
def _handle_parent_notification( | ||
self, | ||
|
@@ -266,39 +266,12 @@ def _handle_parent_notification( | |
json_blocks = orjson.dumps(payload.get("blocks")).decode() | ||
payload["blocks"] = json_blocks | ||
|
||
extra = { | ||
"channel": channel_id, | ||
"thread_ts": parent_notification.message_identifier, | ||
"rule_action_uuid": parent_notification.rule_action_uuid, | ||
} | ||
cathteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with MessagingInteractionEvent( | ||
interaction_type=MessagingInteractionType.SEND_ACTIVITY_NOTIFICATION, | ||
spec=SlackMessagingSpec(), | ||
).capture() as lifecycle: | ||
try: | ||
client.chat_postMessage( | ||
channel=channel_id, | ||
thread_ts=parent_notification.message_identifier, | ||
text=notification_to_send, | ||
blocks=json_blocks, | ||
) | ||
# TODO(iamrajjoshi): Remove this after we validate lifecycle | ||
metrics.incr(SLACK_ACTIVITY_THREAD_SUCCESS_DATADOG_METRIC, sample_rate=1.0) | ||
except SlackApiError as e: | ||
# TODO(iamrajjoshi): Remove this after we validate lifecycle | ||
self._logger.info( | ||
"failed to post message to slack", | ||
extra={"error": str(e), "blocks": json_blocks, **extra}, | ||
) | ||
metrics.incr( | ||
SLACK_ACTIVITY_THREAD_FAILURE_DATADOG_METRIC, | ||
sample_rate=1.0, | ||
tags={"ok": e.response.get("ok", False), "status": e.response.status_code}, | ||
) | ||
lifecycle.add_extras({"rule_action_uuid": parent_notification.rule_action_uuid}) | ||
iamrajjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
record_lifecycle_termination_level(lifecycle, e) | ||
raise | ||
client.chat_postMessage( | ||
channel=channel_id, | ||
thread_ts=parent_notification.message_identifier, | ||
text=notification_to_send, | ||
blocks=json_blocks, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. diff is weird here, but basically we don't catch the SlackAPI in this function, rather the callee function above. |
||
|
||
def _get_notification_message_to_send(self, activity: Activity) -> str | None: | ||
""" | ||
|
@@ -467,17 +440,7 @@ def send_message_to_slack_channel( | |
unfurl_media=False, | ||
callback_id=str(payload.get("callback_id", "")), | ||
) | ||
# TODO(iamrajjoshi): Remove this after we validate lifecycle | ||
metrics.incr(SLACK_NOTIFY_RECIPIENT_SUCCESS_DATADOG_METRIC, sample_rate=1.0) | ||
except SlackApiError as e: | ||
# TODO(iamrajjoshi): Remove this after we validate lifecycle | ||
extra = {"error": str(e), **log_params} | ||
self._logger.info(log_error_message, extra=extra) | ||
metrics.incr( | ||
SLACK_NOTIFY_RECIPIENT_FAILURE_DATADOG_METRIC, | ||
sample_rate=1.0, | ||
tags={"ok": e.response.get("ok", False), "status": e.response.status_code}, | ||
) | ||
lifecycle.add_extras( | ||
{k: str(v) for k, v in log_params.items() if isinstance(v, (int, str))} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
taking care of the lifecycle here instead