: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(logs): expose logs_pattern_buckets rollup in hogql (#119446)
Jon McCallum187eb365f011
diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.pyindex 9ba974f83e29..1221916e2f7e 100644--- a/posthog/hogql/database/database.py+++ b/posthog/hogql/database/database.py@@ -110,6 +110,7 @@ from posthog.hogql.database.schema.log_entries import (from posthog.hogql.database.schema.logs import (LogAttributesTable,LogsKafkaMetricsTable,+ LogsPatternBucketsTable,LogsTable,LogsVolumeBucketsTable,)@@ -585,6 +586,7 @@ def _construct_database_root_node(*, include_posthog_tables: bool) -> TableNode:**clone_root_tables(),# Add new tables here"logs_volume_buckets": TableNode(name="logs_volume_buckets", table=LogsVolumeBucketsTable()),+ "logs_pattern_buckets": TableNode(name="logs_pattern_buckets", table=LogsPatternBucketsTable()),"ai_events": TableNode(name="ai_events", table=AiEventsTable()),# Pruned per org in _build_from_sources; see is_flag_evaluations_table_enabled.# The flag check must stay out of this cached, process-global tree.diff --git a/posthog/hogql/database/schema/logs.py b/posthog/hogql/database/schema/logs.pyindex 3bbb438e7234..f7d00b09f233 100644--- a/posthog/hogql/database/schema/logs.py+++ b/posthog/hogql/database/schema/logs.py@@ -169,6 +169,60 @@ class LogsVolumeBucketsTable(Table):return "logs_volume_buckets"+class LogsPatternBucketsTable(Table):+ description: str = (+ "Log pattern volume rollup on a 5-minute UTC grid, one row per (service, namespace, environment, severity, "+ "pattern_version, pattern) series per bucket. Only holds logs with a pattern. 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)."+ ),+ "pattern_version": IntegerDatabaseField(+ name="pattern_version",+ nullable=False,+ description="Version of the masking rules that produced `pattern`. Compare patterns only within one version.",+ ),+ "pattern": StringDatabaseField(+ name="pattern",+ nullable=False,+ description="Masked template of the log message, with variable parts replaced. Logs that share a pattern are the same kind of message.",+ ),+ "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_pattern_buckets_distributed"++ def to_printed_hogql(self) -> str:+ return "logs_pattern_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