Skip to content
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

feat: delete capture events in reverse proxy #26625

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
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
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
Loading