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(query): tag query endpoint and hogql executor spans with team_id (#63090)

Robbie875f25fd4d80
diff --git a/posthog/api/query.py b/posthog/api/query.py
index e203454df98b..52ca90b0c123 100644
--- a/posthog/api/query.py
+++ b/posthog/api/query.py
@@ -198,6 +198,7 @@ class QueryViewSet(QueryCoalescingMixin, TeamAndOrgViewSetMixin, PydanticModelMi
limit_context = None
with tracer.start_as_current_span("posthog.query.process_query_model") as process_span:
+ process_span.set_attribute("team_id", self.team.pk)
process_span.set_attribute("query.kind", getattr(query, "kind", "Other"))
process_span.set_attribute(
"query.is_query_service", get_query_tag_value("access_method") == "personal_api_key"
diff --git a/posthog/hogql/query.py b/posthog/hogql/query.py
index 3209d96263d0..477e242f6e36 100644
--- a/posthog/hogql/query.py
+++ b/posthog/hogql/query.py
@@ -890,6 +890,7 @@ class HogQLQueryExecutor:
@tracer.start_as_current_span("HogQLQueryExecutor.execute")
def execute(self) -> HogQLQueryResponse:
+ trace.get_current_span().set_attribute("team_id", self.team.pk)
try:
if self.send_raw_query and self.connection_id is not None:
self._execute_raw_direct_postgres_query()