Skip to content

Commit

Permalink
feat: delete capture events in reverse proxy (#26625)
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhi-posthog authored Dec 4, 2024
1 parent f0d9c49 commit f79cb71
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions posthog/api/proxy_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def generate_target_cname(organization_id, domain) -> str:
return f"{digest}.{settings.PROXY_BASE_CNAME}"


def _capture_proxy_event(request, record: ProxyRecord, event_type: str) -> None:
organization = Organization.objects.get(id=record.organization_id)
posthoganalytics.capture(
request.user.distinct_id,
f"managed reverse proxy {event_type}",
properties={
"proxy_record_id": record.id,
"domain": record.domain,
"target_cname": record.target_cname,
},
groups=groups(organization),
)


class ProxyRecordSerializer(serializers.ModelSerializer):
class Meta:
model = ProxyRecord
Expand Down Expand Up @@ -79,17 +93,7 @@ def create(self, request, *args, **kwargs):
)

serializer = self.get_serializer(record)
organization = Organization.objects.get(id=record.organization_id)
posthoganalytics.capture(
request.user.distinct_id,
"managed reverse proxy created",
properties={
"proxy_record_id": record.id,
"domain": record.domain,
"target_cname": record.target_cname,
},
groups=groups(organization),
)
_capture_proxy_event(request, record, "created")
return Response(serializer.data)

def destroy(self, request, *args, pk=None, **kwargs):
Expand Down Expand Up @@ -120,6 +124,8 @@ def destroy(self, request, *args, pk=None, **kwargs):
record.status = ProxyRecord.Status.DELETING
record.save()

_capture_proxy_event(request, record, "deleted")

return Response(
{"success": True},
status=status.HTTP_200_OK,
Expand Down

0 comments on commit f79cb71

Please sign in to comment.