: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(hogql): expose the logs_volume_buckets rollup as a table (#87773)
Jon McCallum4c285dfecca4
diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.pyindex 7bdbe192f1ac..efee101fcbcb 100644--- a/posthog/hogql/database/database.py+++ b/posthog/hogql/database/database.py@@ -100,7 +100,12 @@ from posthog.hogql.database.schema.log_entries import (LogEntriesTable,ReplayConsoleLogsLogEntriesTable,)-from posthog.hogql.database.schema.logs import LogAttributesTable, LogsKafkaMetricsTable, LogsTable+from posthog.hogql.database.schema.logs import (+ LogAttributesTable,+ LogsKafkaMetricsTable,+ LogsTable,+ LogsVolumeBucketsTable,+)from posthog.hogql.database.schema.marketing_conversions_preaggregated import MarketingConversionsPreaggregatedTablefrom posthog.hogql.database.schema.marketing_costs_preaggregated import MarketingCostsPreaggregatedTablefrom posthog.hogql.database.schema.marketing_costs_precomputed import MarketingCostsPrecomputedTable@@ -406,6 +411,7 @@ def _construct_database_root_node(*, include_posthog_tables: bool) -> TableNode:children={**clone_root_tables(),# Add new tables here+ "logs_volume_buckets": TableNode(name="logs_volume_buckets", table=LogsVolumeBucketsTable()),"ai_events": TableNode(name="ai_events", table=AiEventsTable()),"trace_spans": TableNode(name="trace_spans", table=TraceSpansTable()),"trace_attributes": TableNode(name="trace_attributes", table=TraceAttributesTable()),diff --git a/posthog/hogql/database/schema/logs.py b/posthog/hogql/database/schema/logs.pyindex 8a5faf7d0958..0467faf006f7 100644--- a/posthog/hogql/database/schema/logs.py+++ b/posthog/hogql/database/schema/logs.py@@ -1,3 +1,5 @@+from typing import TYPE_CHECKING+from posthog.hogql.database.models import (DANGEROUS_NoTeamIdCheckTable,DateTimeDatabaseField,@@ -11,6 +13,9 @@ from posthog.hogql.database.models import (from posthog.clickhouse.workload import Workload+if TYPE_CHECKING:+ from posthog.hogql.context import HogQLContext+# 50GB - limit for user-provided HogQL queries on log tables to prevent expensive full scansHOGQL_MAX_BYTES_TO_READ_FOR_LOGS_USER_QUERIES = 50_000_000_000@@ -98,6 +103,49 @@ class LogsTable(Table):return "logs"+class LogsVolumeBucketsTable(Table):+ description: str = (+ "Log volume rollup on a 5-minute UTC grid, one row per (service, namespace, environment, severity) "+ "series per bucket. Holds partial counts: always GROUP BY the key columns and sum(log_count)."+ )+ workload: Workload | None = Workload.LOGS+ fields: dict[str, FieldOrTable] = {+ "team_id": IntegerDatabaseField(name="team_id", nullable=False),+ "time_bucket": DateTimeDatabaseField(+ name="time_bucket",+ nullable=False,+ description="Start of the 5-minute UTC bucket the counts fall in.",+ ),+ "service_name": StringDatabaseField(+ name="service_name", nullable=False, description="Name of the service that emitted the logs."+ ),+ "namespace": StringDatabaseField(+ name="namespace",+ nullable=False,+ description="Kubernetes or service namespace of the emitting resource; empty string when absent.",+ ),+ "environment": StringDatabaseField(+ name="environment",+ nullable=False,+ description="Deployment environment of the emitting resource; empty string when absent.",+ ),+ "severity_text": StringDatabaseField(+ name="severity_text", nullable=False, description="Lowercased log severity (for example info, warn, error)."+ ),+ "log_count": IntegerDatabaseField(+ name="log_count",+ nullable=False,+ description="Partial log count for the bucket; sum() across rows for the true count.",+ ),+ }++ def to_printed_clickhouse(self, context: "HogQLContext") -> str:+ return "logs_volume_buckets_distributed"++ def to_printed_hogql(self) -> str:+ return "logs_volume_buckets"++class LogAttributesTable(Table):description: str = "Distinct log attribute key/value pairs with occurrence counts, used to power log attribute autocomplete and faceting."workload: Workload | None = Workload.LOGS