Skip to content

Commit

Permalink
feat: Soft delete user ip when scrub ip is on (#82057)
Browse files Browse the repository at this point in the history
Working on the hard deletion of these ips but in the mean time, this
will soft delete them.
  • Loading branch information
Zylphrex authored Dec 12, 2024
1 parent 02238a6 commit c5bdc3a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sentry/issues/endpoints/project_event_details.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from typing import Any

import sentry_sdk
from rest_framework.request import Request
from rest_framework.response import Response

Expand Down Expand Up @@ -130,4 +131,19 @@ def get(self, request: Request, project, event_id) -> Response:
if isinstance(event_dict["datetime"], datetime):
event_dict["datetime"] = event_dict["datetime"].isoformat()

try:
scrub_ip_addresses = project.organization.get_option(
"sentry:require_scrub_ip_address", False
) or project.get_option("sentry:scrub_ip_address", False)

if scrub_ip_addresses:
if "spans" in event_dict:
for span in event_dict["spans"]:
if "sentry_tags" not in span:
continue
if "user.ip" in span["sentry_tags"]:
del span["sentry_tags"]["user.ip"]
except Exception as e:
sentry_sdk.capture_exception(e)

return Response(event_dict, status=200)
44 changes: 44 additions & 0 deletions tests/snuba/api/endpoints/test_project_event_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,47 @@ def test_project_not_associated_with_event(self):
response = self.client.get(url, format="json")
assert response.status_code == 404, response.content
assert response.data == {"detail": "Event not found"}


class ProjectEventDetailsTransactionTestScrubbed(APITestCase, SnubaTestCase):
def setUp(self):
super().setUp()
self.login_as(user=self.user)
data = load_data("transaction")
for span in data["spans"]:
span["sentry_tags"]["user.ip"] = "127.0.0.1"
self.event = self.store_event(data=data, project_id=self.project.id)

self.url = reverse(
"sentry-api-0-event-json",
kwargs={
"organization_id_or_slug": self.organization.slug,
"project_id_or_slug": self.project.slug,
"event_id": self.event.event_id,
},
)

def test_no_scrubbed(self):
response = self.client.get(self.url, format="json")
assert response.status_code == 200, response.content
assert len(response.data["spans"]) > 0
for span in response.data["spans"]:
assert "user.ip" in span["sentry_tags"]

def test_scrubbed_project(self):
self.project.update_option("sentry:scrub_ip_address", True)

response = self.client.get(self.url, format="json")
assert response.status_code == 200, response.content
assert len(response.data["spans"]) > 0
for span in response.data["spans"]:
assert "user.ip" not in span["sentry_tags"]

def test_scrubbed_organization(self):
self.organization.update_option("sentry:require_scrub_ip_address", True)

response = self.client.get(self.url, format="json")
assert response.status_code == 200, response.content
assert len(response.data["spans"]) > 0
for span in response.data["spans"]:
assert "user.ip" not in span["sentry_tags"]

0 comments on commit c5bdc3a

Please sign in to comment.