Skip to content

Commit

Permalink
🔧 chore: remove redundant slack logging & metrics (#82852)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrajjoshi authored Jan 8, 2025
1 parent 9f72add commit 29d8325
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 69 deletions.
19 changes: 0 additions & 19 deletions src/sentry/integrations/slack/actions/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ def get_thread_ts(lifecycle: EventLifecycle) -> str | None:
thread_ts=thread_ts,
reply_broadcast=reply_broadcast,
)
metrics.incr(
SLACK_ISSUE_ALERT_SUCCESS_DATADOG_METRIC,
sample_rate=1.0,
tags={"action": "send_notification"},
)
except SlackApiError as e:
# Record the error code and details from the exception
new_notification_message_object.error_code = e.response.status_code
Expand All @@ -220,20 +215,6 @@ def get_thread_ts(lifecycle: EventLifecycle) -> str | None:
if self.get_option("channel"):
log_params["channel_name"] = self.get_option("channel")

self.logger.info(
"slack.issue_alert.error",
extra=log_params,
)
metrics.incr(
SLACK_ISSUE_ALERT_FAILURE_DATADOG_METRIC,
sample_rate=1.0,
tags={
"action": "send_notification",
"ok": e.response.get("ok", False),
"status": e.response.status_code,
},
)

lifecycle.add_extras(log_params)
# If the error is a channel not found or archived, we can halt the flow
if (
Expand Down
8 changes: 0 additions & 8 deletions src/sentry/integrations/slack/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
"sentry.integrations.slack.group_actions.failure"
)

# Slack Commands
SLACK_COMMANDS_ENDPOINT_SUCCESS_DATADOG_METRIC = (
"sentry.integrations.slack.commands_endpoint.success"
)
SLACK_COMMANDS_ENDPOINT_FAILURE_DATADOG_METRIC = (
"sentry.integrations.slack.commands_endpoint.failure"
)

# Sending messages upon linking/unlinking
SLACK_LINK_IDENTITY_MSG_SUCCESS_DATADOG_METRIC = (
"sentry.integrations.slack.link_identity_msg.success"
Expand Down
19 changes: 0 additions & 19 deletions src/sentry/integrations/slack/webhooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@
from sentry.integrations.messaging.metrics import MessageCommandHaltReason
from sentry.integrations.messaging.spec import MessagingIntegrationSpec
from sentry.integrations.slack.message_builder.help import SlackHelpMessageBuilder
from sentry.integrations.slack.metrics import (
SLACK_WEBHOOK_DM_ENDPOINT_FAILURE_DATADOG_METRIC,
SLACK_WEBHOOK_DM_ENDPOINT_SUCCESS_DATADOG_METRIC,
)
from sentry.integrations.slack.requests.base import SlackDMRequest, SlackRequestError
from sentry.integrations.slack.spec import SlackMessagingSpec
from sentry.integrations.types import EventLifecycleOutcome, IntegrationResponse
from sentry.utils import metrics

LINK_USER_MESSAGE = (
"<{associate_url}|Link your Slack identity> to your Sentry account to receive notifications. "
Expand All @@ -47,9 +42,6 @@
class SlackDMEndpoint(Endpoint, abc.ABC):
slack_request_class = SlackDMRequest

_METRICS_SUCCESS_KEY = SLACK_WEBHOOK_DM_ENDPOINT_SUCCESS_DATADOG_METRIC
_METRIC_FAILURE_KEY = SLACK_WEBHOOK_DM_ENDPOINT_FAILURE_DATADOG_METRIC

def post_dispatcher(self, request: SlackDMRequest) -> Response:
"""
All Slack commands are handled by this endpoint. This block just
Expand Down Expand Up @@ -80,7 +72,6 @@ def link_user(self, slack_request: SlackDMRequest) -> Response:

if not (slack_request.integration and slack_request.user_id and slack_request.channel_id):
logger.error(".link-user.bad_request.error", extra={"slack_request": slack_request})
metrics.incr(self._METRIC_FAILURE_KEY + "link_user.bad_request", sample_rate=1.0)
raise SlackRequestError(status=status.HTTP_400_BAD_REQUEST)

associate_url = build_linking_url(
Expand All @@ -90,23 +81,15 @@ def link_user(self, slack_request: SlackDMRequest) -> Response:
response_url=slack_request.response_url,
)

metrics.incr(self._METRICS_SUCCESS_KEY + ".link_user", sample_rate=1.0)

return self.reply(slack_request, LINK_USER_MESSAGE.format(associate_url=associate_url))

def unlink_user(self, slack_request: SlackDMRequest) -> Response:
from sentry.integrations.slack.views.unlink_identity import build_unlinking_url

if not slack_request.has_identity:
logger.error(".unlink-user.no-identity.error", extra={"slack_request": slack_request})
metrics.incr(self._METRIC_FAILURE_KEY + "unlink_user.no_identity", sample_rate=1.0)

return self.reply(slack_request, NOT_LINKED_MESSAGE)

if not (slack_request.integration and slack_request.user_id and slack_request.channel_id):
logger.error(".unlink-user.bad_request.error", extra={"slack_request": slack_request})
metrics.incr(self._METRIC_FAILURE_KEY + "unlink_user.bad_request", sample_rate=1.0)

raise SlackRequestError(status=status.HTTP_400_BAD_REQUEST)

associate_url = build_unlinking_url(
Expand All @@ -116,8 +99,6 @@ def unlink_user(self, slack_request: SlackDMRequest) -> Response:
response_url=slack_request.response_url,
)

metrics.incr(self._METRICS_SUCCESS_KEY + ".unlink_user", sample_rate=1.0)

return self.reply(slack_request, UNLINK_USER_MESSAGE.format(associate_url=associate_url))

def link_team(self, slack_request: SlackDMRequest) -> Response:
Expand Down
23 changes: 0 additions & 23 deletions src/sentry/integrations/slack/webhooks/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
from sentry.api.helpers.teams import is_team_admin
from sentry.integrations.models.external_actor import ExternalActor
from sentry.integrations.slack.message_builder.disconnected import SlackDisconnectedMessageBuilder
from sentry.integrations.slack.metrics import (
SLACK_COMMANDS_ENDPOINT_FAILURE_DATADOG_METRIC,
SLACK_COMMANDS_ENDPOINT_SUCCESS_DATADOG_METRIC,
)
from sentry.integrations.slack.requests.base import SlackDMRequest, SlackRequestError
from sentry.integrations.slack.requests.command import SlackCommandRequest
from sentry.integrations.slack.utils.auth import is_valid_role
Expand All @@ -24,7 +20,6 @@
from sentry.integrations.types import ExternalProviders
from sentry.models.organization import Organization
from sentry.models.organizationmember import OrganizationMember
from sentry.utils import metrics

_logger = logging.getLogger("sentry.integration.slack.bot-commands")

Expand Down Expand Up @@ -68,9 +63,6 @@ class SlackCommandsEndpoint(SlackDMEndpoint):
permission_classes = ()
slack_request_class = SlackCommandRequest

_METRICS_SUCCESS_KEY = SLACK_COMMANDS_ENDPOINT_SUCCESS_DATADOG_METRIC
_METRICS_FAILURE_KEY = SLACK_COMMANDS_ENDPOINT_FAILURE_DATADOG_METRIC

def reply(self, slack_request: SlackDMRequest, message: str) -> Response:
return self.respond(
{
Expand Down Expand Up @@ -103,10 +95,6 @@ def link_team(self, slack_request: SlackDMRequest) -> Response:
has_valid_role = True

if not has_valid_role:
_logger.error("insufficient-role", extra=logger_params)
metrics.incr(
self._METRICS_FAILURE_KEY + ".link_team.insufficient_role", sample_rate=1.0
)
return self.reply(slack_request, INSUFFICIENT_ROLE_MESSAGE)

associate_url = build_team_linking_url(
Expand All @@ -117,7 +105,6 @@ def link_team(self, slack_request: SlackDMRequest) -> Response:
response_url=slack_request.response_url,
)

metrics.incr(self._METRICS_SUCCESS_KEY + ".link_team", sample_rate=1.0)
return self.reply(slack_request, LINK_TEAM_MESSAGE.format(associate_url=associate_url))

def unlink_team(self, slack_request: SlackDMRequest) -> Response:
Expand Down Expand Up @@ -153,7 +140,6 @@ def unlink_team(self, slack_request: SlackDMRequest) -> Response:
response_url=slack_request.response_url,
)

metrics.incr(self._METRICS_SUCCESS_KEY + ".unlink_team", sample_rate=1.0)
return self.reply(slack_request, UNLINK_TEAM_MESSAGE.format(associate_url=associate_url))

def post(self, request: Request) -> Response:
Expand All @@ -162,16 +148,7 @@ def post(self, request: Request) -> Response:
slack_request.validate()
except SlackRequestError as e:
if e.status == status.HTTP_403_FORBIDDEN:
metrics.incr(
self._METRICS_FAILURE_KEY + ".slack-commands-endpoint.forbidden",
sample_rate=1.0,
)
return self.respond(SlackDisconnectedMessageBuilder().build())
metrics.incr(
self._METRICS_FAILURE_KEY + ".slack-commands-endpoint.validation_error",
sample_rate=1.0,
)
return self.respond(status=e.status)

metrics.incr(self._METRICS_SUCCESS_KEY + ".slack-commands-endpoint", sample_rate=1.0)
return super().post_dispatcher(slack_request)

0 comments on commit 29d8325

Please sign in to comment.