Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(conversations): count legacy ticket auth by team (#105237)

Patricio4edec15ba734
diff --git a/products/conversations/backend/api/external.py b/products/conversations/backend/api/external.py
index 40f81a1a0f2a..3f2b0a536828 100644
--- a/products/conversations/backend/api/external.py
+++ b/products/conversations/backend/api/external.py
@@ -27,7 +27,7 @@ from products.conversations.backend.api.ticket_actions import (
handle_ticket_patch,
wants_first_customer_message_text,
)
-from products.conversations.backend.metrics import TICKET_ACTION_AUTH_COUNTER
+from products.conversations.backend.metrics import LEGACY_TICKET_AUTH_BY_TEAM_COUNTER, TICKET_ACTION_AUTH_COUNTER
class _ExternalTicketThrottle(SimpleRateThrottle):
@@ -71,6 +71,7 @@ def _authenticate_team(request: Request) -> tuple[Team, None] | tuple[None, Resp
return None, Response({"error": "Invalid API key"}, status=status.HTTP_401_UNAUTHORIZED)
TICKET_ACTION_AUTH_COUNTER.labels(auth_method="secret_api_token", http_method=(request.method or "").lower()).inc()
+ LEGACY_TICKET_AUTH_BY_TEAM_COUNTER.labels(team_id=str(team.id)).inc()
return team, None
diff --git a/products/conversations/backend/api/tests/test_external.py b/products/conversations/backend/api/tests/test_external.py
index dc23a1c7e62c..1d757acaebd5 100644
--- a/products/conversations/backend/api/tests/test_external.py
+++ b/products/conversations/backend/api/tests/test_external.py
@@ -83,12 +83,18 @@ class TestExternalTicketAPI(BaseTest):
response = self.client.get(self.url, **self._auth_headers())
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
- def test_authenticated_requests_increment_the_legacy_auth_counter(self):
- labels = {"auth_method": "secret_api_token", "http_method": "get"}
- before = REGISTRY.get_sample_value("posthog_conversations_ticket_action_auth_total", labels) or 0
+ def test_authenticated_requests_increment_the_legacy_auth_counters(self):
+ auth_labels = {"auth_method": "secret_api_token", "http_method": "get"}
+ team_labels = {"team_id": str(self.team.id)}
+ auth_before = REGISTRY.get_sample_value("posthog_conversations_ticket_action_auth_total", auth_labels) or 0
+ team_before = (
+ REGISTRY.get_sample_value("posthog_conversations_external_ticket_legacy_team_total", team_labels) or 0
+ )
self.client.get(self.url, **self._auth_headers())
- after = REGISTRY.get_sample_value("posthog_conversations_ticket_action_auth_total", labels)
- self.assertEqual(after, before + 1)
+ auth_after = REGISTRY.get_sample_value("posthog_conversations_ticket_action_auth_total", auth_labels)
+ team_after = REGISTRY.get_sample_value("posthog_conversations_external_ticket_legacy_team_total", team_labels)
+ self.assertEqual(auth_after, auth_before + 1)
+ self.assertEqual(team_after, team_before + 1)
# -- GET ticket -------------------------------------------------------
diff --git a/products/conversations/backend/metrics.py b/products/conversations/backend/metrics.py
index 4894e10418f4..3953a3693666 100644
--- a/products/conversations/backend/metrics.py
+++ b/products/conversations/backend/metrics.py
@@ -9,6 +9,15 @@ TICKET_ACTION_AUTH_COUNTER = Counter(
labelnames=["auth_method", "http_method"], # auth_method: secret_api_token | scoped_jwt
)
+# Temporary (#63111): identifies which teams still call the external ticket route with the
+# legacy token, so their owner can be found before the route is removed. Bounded cardinality:
+# only teams that actually hit the route (a handful). Delete together with the route.
+LEGACY_TICKET_AUTH_BY_TEAM_COUNTER = Counter(
+ "posthog_conversations_external_ticket_legacy_team_total",
+ "Legacy secret_api_token authentications on the external ticket route, by team",
+ labelnames=["team_id"],
+)
+
TICKET_SEARCH_DURATION_SECONDS = Histogram(
"posthog_support_ticket_search_duration_seconds",
"End-to-end duration of support ticket list requests that include a search term",