Skip to content

ref(feedback): add a tag for whether spam detection was applied #97452

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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/sentry/feedback/usecases/ingest/create_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ def create_feedback_issue(
if event_fixed.get("release"):
event_fixed["tags"]["release"] = event_fixed["release"]

event_fixed["tags"]["has_spam_filter"] = "true" if is_message_spam is not None else "false"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix sentry tags with sentry.


Comment on lines +383 to +384
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, the is_mesage_spam value is currently also added to evidenceData on line ~70 in this same file:

if is_message_spam is True:
evidence_data["is_spam"] = is_message_spam # Used by alerts post process.
evidence_display.append(
IssueEvidence(name="is_spam", value=str(is_message_spam), important=False)
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, i think we could do better if we unconditionally recorded whether spam detection was even executed. Projects have a setting where that can be disabled, so for each feedback we could say "spam detected: disabled" OR "spam detection: enabled, is_spam: Nope"

and put the pair into context, instead of tags

# make sure event data is valid for issue platform
validate_issue_platform_event_schema(event_fixed)

Expand Down
22 changes: 21 additions & 1 deletion tests/sentry/feedback/usecases/ingest/test_create_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def test_create_feedback_tags_no_associated_event_id(


@django_db_all
def test_create_feedback_tags_skips_if_empty(
def test_create_feedback_tags_skips_email_if_empty(
default_project, mock_produce_occurrence_to_kafka
) -> None:
event = mock_feedback_event(default_project.id)
Expand All @@ -810,6 +810,26 @@ def test_create_feedback_tags_skips_if_empty(
assert "user.email" not in tags


@pytest.mark.parametrize("spam_enabled", (True, False))
@django_db_all
def test_create_feedback_tags_has_spam_filter(
default_project, mock_produce_occurrence_to_kafka, spam_enabled
) -> None:
with (
patch(
"sentry.feedback.usecases.ingest.create_feedback.spam_detection_enabled",
return_value=spam_enabled,
),
patch("sentry.feedback.usecases.ingest.create_feedback.is_spam", return_value=True),
):
event = mock_feedback_event(default_project.id)
create_feedback_issue(event, default_project, FeedbackCreationSource.NEW_FEEDBACK_ENVELOPE)

assert mock_produce_occurrence_to_kafka.call_count > 0 # is 2 when spam enabled
tags = mock_produce_occurrence_to_kafka.call_args_list[0].kwargs["event_data"]["tags"]
assert tags["has_spam_filter"] == "true" if spam_enabled else "false"


@django_db_all
@pytest.mark.parametrize("spam_enabled", (True, False))
def test_create_feedback_filters_large_message(
Expand Down
Loading