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.

fix(metrics): stop writing observed_timestamp_arr to metrics4_samples (#126541)

Daniel Visca4f67f021f132
diff --git a/posthog/clickhouse/hcl/golden/dev/apm.hcl b/posthog/clickhouse/hcl/golden/dev/apm.hcl
index 733ff3ea59af..98851c33ac1a 100644
--- a/posthog/clickhouse/hcl/golden/dev/apm.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/apm.hcl
@@ -1908,7 +1908,6 @@ SELECT
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
@@ -1968,9 +1967,6 @@ SQL
column "timestamp_arr" {
type = "Array(DateTime64(6))"
}
- column "observed_timestamp_arr" {
- type = "Array(DateTime64(6))"
- }
column "value_arr" {
type = "Array(Float64)"
}
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index a02902b3a8b8..03d8076731c5 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -5055,7 +5055,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -5088,7 +5087,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -5105,7 +5103,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00')
SQL
diff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
index c3b9cf2c7a0f..f3bc0e118830 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
@@ -4749,7 +4749,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -4782,7 +4781,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -4799,7 +4797,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00')
SQL
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 1980b548d7a0..1cea290222d1 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -22942,7 +22942,6 @@ SELECT
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
@@ -23002,9 +23001,6 @@ SQL
column "timestamp_arr" {
type = "Array(DateTime64(6))"
}
- column "observed_timestamp_arr" {
- type = "Array(DateTime64(6))"
- }
column "value_arr" {
type = "Array(Float64)"
}
@@ -26542,7 +26538,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -26575,7 +26570,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -26592,7 +26586,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00')
SQL
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl b/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl
index b595d93c9a8d..7ca5a537b81f 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl
@@ -1355,7 +1355,6 @@ SELECT
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
@@ -1415,9 +1414,6 @@ SQL
column "timestamp_arr" {
type = "Array(DateTime64(6))"
}
- column "observed_timestamp_arr" {
- type = "Array(DateTime64(6))"
- }
column "value_arr" {
type = "Array(Float64)"
}
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
index 1bc44a9dfe47..eba94cd3001a 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
@@ -5288,7 +5288,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -5321,7 +5320,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -5338,7 +5336,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00')
SQL
diff --git a/posthog/clickhouse/hcl/golden/prod-us/apm.hcl b/posthog/clickhouse/hcl/golden/prod-us/apm.hcl
index b595d93c9a8d..7ca5a537b81f 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/apm.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/apm.hcl
@@ -1355,7 +1355,6 @@ SELECT
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
@@ -1415,9 +1414,6 @@ SQL
column "timestamp_arr" {
type = "Array(DateTime64(6))"
}
- column "observed_timestamp_arr" {
- type = "Array(DateTime64(6))"
- }
column "value_arr" {
type = "Array(Float64)"
}
diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
index 1dbbce442320..4a5a2312bc1f 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
@@ -5270,7 +5270,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -5303,7 +5302,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -5320,7 +5318,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00')
SQL
diff --git a/posthog/clickhouse/hcl/roles/apm/shared/metrics4.hcl b/posthog/clickhouse/hcl/roles/apm/shared/metrics4.hcl
index c1abd6dbda52..4a8b28f426c8 100644
--- a/posthog/clickhouse/hcl/roles/apm/shared/metrics4.hcl
+++ b/posthog/clickhouse/hcl/roles/apm/shared/metrics4.hcl
@@ -219,7 +219,6 @@ database "posthog" {
column "histogram_bounds" { type = "Array(Float64)" }
column "_topic" { type = "String" }
column "timestamp_arr" { type = "Array(DateTime64(6))" }
- column "observed_timestamp_arr" { type = "Array(DateTime64(6))" }
column "value_arr" { type = "Array(Float64)" }
column "count_arr" { type = "Array(UInt64)" }
column "histogram_counts_arr" { type = "Array(Array(UInt64))" }
diff --git a/posthog/clickhouse/hcl/roles/apm/shared/sql/metrics4_input_to_metrics4_samples.sql b/posthog/clickhouse/hcl/roles/apm/shared/sql/metrics4_input_to_metrics4_samples.sql
index 4d9ccb9b5ef4..08199089b679 100644
--- a/posthog/clickhouse/hcl/roles/apm/shared/sql/metrics4_input_to_metrics4_samples.sql
+++ b/posthog/clickhouse/hcl/roles/apm/shared/sql/metrics4_input_to_metrics4_samples.sql
@@ -15,7 +15,6 @@ SELECT
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics4_view.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics4_view.sql
index 139c3b91caf7..466bc9f29726 100644
--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics4_view.sql
+++ b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics4_view.sql
@@ -5,7 +5,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -38,7 +37,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -55,5 +53,5 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00')
diff --git a/posthog/clickhouse/hcl/sql/dev/apm.sql b/posthog/clickhouse/hcl/sql/dev/apm.sql
index cb2ba552e502..8b2d24d21ed7 100644
--- a/posthog/clickhouse/hcl/sql/dev/apm.sql
+++ b/posthog/clickhouse/hcl/sql/dev/apm.sql
@@ -607,7 +607,7 @@ FROM
GROUP BY
team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes
);
-CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), observed_timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
+CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
team_id,
metric_name,
toDateTime(toStartOfHour(timestamp)) AS time_bucket,
@@ -624,7 +624,6 @@ CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.w
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index 37f86bd49800..561cc73f2b95 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -1570,7 +1570,6 @@ CREATE VIEW posthog.metrics4_view AS SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -1603,7 +1602,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -1620,7 +1618,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00');
CREATE TABLE posthog.metric_samples (
team_id Int32,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
index 524eab6935b6..c00f774c64a1 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
@@ -1411,7 +1411,6 @@ CREATE VIEW posthog.metrics4_view AS SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -1444,7 +1443,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -1461,7 +1459,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00');
CREATE TABLE posthog.logs (
time_bucket DateTime MATERIALIZED toStartOfDay(timestamp) CODEC(DoubleDelta, ZSTD(1)),
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index 5140a852867f..2a5c87ae4e2b 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -5341,7 +5341,7 @@ FROM
GROUP BY
team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes
);
-CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), observed_timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
+CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
team_id,
metric_name,
toDateTime(toStartOfHour(timestamp)) AS time_bucket,
@@ -5358,7 +5358,6 @@ CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.w
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
@@ -6310,7 +6309,6 @@ CREATE VIEW posthog.metrics4_view AS SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -6343,7 +6341,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -6360,7 +6357,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00');
CREATE VIEW posthog.persons_batch_export AS WITH
new_persons AS (SELECT id, max(version) AS version, argMax(_timestamp, person.version) AS _timestamp2 FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (id IN (SELECT id FROM posthog.person WHERE (team_id = {team_id: Int64}) AND (_timestamp >= {interval_start: DateTime64}) AND (_timestamp < {interval_end: DateTime64}))) GROUP BY id HAVING (_timestamp2 >= {interval_start: DateTime64}) AND (_timestamp2 < {interval_end: DateTime64})),
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/apm.sql b/posthog/clickhouse/hcl/sql/prod-eu/apm.sql
index 5de4a6d7ba49..2dd0f8791302 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/apm.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/apm.sql
@@ -443,7 +443,7 @@ FROM
GROUP BY
team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes
);
-CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), observed_timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
+CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
team_id,
metric_name,
toDateTime(toStartOfHour(timestamp)) AS time_bucket,
@@ -460,7 +460,6 @@ CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.w
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
index 677aca03d390..0418fe664aa8 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
@@ -1647,7 +1647,6 @@ CREATE VIEW posthog.metrics4_view AS SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -1680,7 +1679,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -1697,7 +1695,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00');
CREATE TABLE posthog.metric_samples (
team_id Int32,
diff --git a/posthog/clickhouse/hcl/sql/prod-us/apm.sql b/posthog/clickhouse/hcl/sql/prod-us/apm.sql
index d2b4e514e0a1..5e6187899412 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/apm.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/apm.sql
@@ -443,7 +443,7 @@ FROM
GROUP BY
team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes
);
-CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), observed_timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
+CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.writable_metrics4_samples (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime, series_fingerprint UInt64, original_expiry_date Date32, resource_fingerprint UInt64, service_name String, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, has_labels UInt8, instrumentation_scope String, histogram_bounds Array(Float64), _topic String, timestamp_arr Array(DateTime64(6)), value_arr Array(Float64), count_arr Array(UInt64), histogram_counts_arr Array(Array(UInt64)), trace_id_arr Array(String), span_id_arr Array(String), trace_flags_arr Array(Int32)) AS SELECT
team_id,
metric_name,
toDateTime(toStartOfHour(timestamp)) AS time_bucket,
@@ -460,7 +460,6 @@ CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_samples TO posthog.w
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
index 3262e3406a93..b973b438921a 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
@@ -1641,7 +1641,6 @@ CREATE VIEW posthog.metrics4_view AS SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -1674,7 +1673,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -1691,7 +1689,7 @@ SELECT
toBool(is_monotonic) AS is_monotonic,
instrumentation_scope
FROM
- posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, observed_timestamp_arr AS point_observed_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
+ posthog.metrics4_samples ARRAY JOIN timestamp_arr AS point_timestamp, value_arr AS point_value, count_arr AS point_count, histogram_counts_arr AS point_histogram_counts, trace_id_arr AS point_trace_id, span_id_arr AS point_span_id, trace_flags_arr AS point_trace_flags
WHERE time_bucket >= toDateTime('2026-09-14 00:00:00');
CREATE TABLE posthog.metric_samples (
team_id Int32,
diff --git a/posthog/clickhouse/metrics/metrics4.py b/posthog/clickhouse/metrics/metrics4.py
index 2e2616a1f90e..7e818e11d9f0 100644
--- a/posthog/clickhouse/metrics/metrics4.py
+++ b/posthog/clickhouse/metrics/metrics4.py
@@ -77,6 +77,10 @@ _ARRAY_CODECS: dict[str, str] = {
"histogram_counts": " CODEC(T64, Default)",
}
+# The ingest MV does not write these arrays, so new rows store an empty array.
+# Do not ARRAY JOIN them with the other point arrays: the lengths do not agree.
+METRICS4_UNWRITTEN_POINT_ARRAY_COLUMNS: frozenset[str] = frozenset({"observed_timestamp"})
+
def _db() -> str:
return settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE
@@ -355,6 +359,7 @@ def METRICS4_INPUT_TO_METRICS4_SAMPLES_MV() -> str:
group_arrays = ",\n".join(
f" groupArray({METRICS4_MAX_SAMPLES_PER_SERIES_HOUR})({name}) AS {name}_arr"
for name, _ in METRICS4_POINT_ARRAY_COLUMNS
+ if name not in METRICS4_UNWRITTEN_POINT_ARRAY_COLUMNS
)
return f"""
CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.{METRICS4_INPUT_TABLE_NAME}_to_{METRICS4_SAMPLES_TABLE_NAME} TO {db}.{WRITABLE_METRICS4_SAMPLES_TABLE_NAME}
@@ -515,7 +520,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
timestamp,
- observed_timestamp,
original_expiry_timestamp,
service_name,
metric_type,
@@ -544,7 +548,6 @@ SELECT
series_fingerprint,
resource_fingerprint,
point_timestamp AS timestamp,
- point_observed_timestamp AS observed_timestamp,
toDateTime64(original_expiry_date, 6) AS original_expiry_timestamp,
service_name,
metric_type,
@@ -563,7 +566,6 @@ SELECT
FROM {db}.{METRICS4_SAMPLES_TABLE_NAME}
ARRAY JOIN
timestamp_arr AS point_timestamp,
- observed_timestamp_arr AS point_observed_timestamp,
value_arr AS point_value,
count_arr AS point_count,
histogram_counts_arr AS point_histogram_counts,
diff --git a/posthog/clickhouse/migrations/0366_metrics4_stop_writing_observed_timestamp.py b/posthog/clickhouse/migrations/0366_metrics4_stop_writing_observed_timestamp.py
new file mode 100644
index 000000000000..84fc76cda371
--- /dev/null
+++ b/posthog/clickhouse/migrations/0366_metrics4_stop_writing_observed_timestamp.py
@@ -0,0 +1,50 @@
+from django.conf import settings
+
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+from posthog.clickhouse.metrics import METRICS4_VIEW_SQL
+
+DB = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE
+
+# The view must stop the ARRAY JOIN of observed_timestamp_arr before the MV stops writing it.
+# After that, new rows store an empty observed_timestamp_arr, so its length differs from the other point arrays.
+# The column stays on metrics4_samples and writable_metrics4_samples until the ClickHouse team drops it.
+operations = [
+ run_sql_with_exceptions(METRICS4_VIEW_SQL(), node_roles=[NodeRole.LOGS]),
+ run_sql_with_exceptions(
+ f"""ALTER TABLE {DB}.metrics4_input_to_metrics4_samples MODIFY QUERY
+SELECT
+ team_id,
+ metric_name,
+ toDateTime(toStartOfHour(timestamp)) AS time_bucket,
+ series_fingerprint,
+ toDate32(original_expiry_timestamp) AS original_expiry_date,
+ any(resource_fingerprint) AS resource_fingerprint,
+ any(service_name) AS service_name,
+ any(metric_type) AS metric_type,
+ any(unit) AS unit,
+ any(aggregation_temporality) AS aggregation_temporality,
+ max(toUInt8(is_monotonic)) AS is_monotonic,
+ max(toUInt8(has_labels)) AS has_labels,
+ any(instrumentation_scope) AS instrumentation_scope,
+ anyLast(histogram_bounds) AS histogram_bounds,
+ any(_topic) AS _topic,
+ groupArray(10000)(timestamp) AS timestamp_arr,
+ groupArray(10000)(value) AS value_arr,
+ groupArray(10000)(count) AS count_arr,
+ groupArray(10000)(histogram_counts) AS histogram_counts_arr,
+ groupArray(10000)(trace_id) AS trace_id_arr,
+ groupArray(10000)(span_id) AS span_id_arr,
+ groupArray(10000)(trace_flags) AS trace_flags_arr
+FROM {DB}.metrics4_input
+GROUP BY
+ team_id,
+ metric_name,
+ time_bucket,
+ series_fingerprint,
+ original_expiry_date""",
+ node_roles=[NodeRole.APM],
+ sharded=False,
+ is_alter_on_replicated_table=False,
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index c8ad93a53a90..27a09f6e6254 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0365_experiment_preaggregated_person_columns
+0366_metrics4_stop_writing_observed_timestamp
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index 9744547c03c5..0276a0d0bd3e 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -5225,7 +5225,6 @@
anyLast(histogram_bounds) AS histogram_bounds,
any(_topic) AS _topic,
groupArray(10000)(timestamp) AS timestamp_arr,
- groupArray(10000)(observed_timestamp) AS observed_timestamp_arr,
groupArray(10000)(value) AS value_arr,
groupArray(10000)(count) AS count_arr,
groupArray(10000)(histogram_counts) AS histogram_counts_arr,
diff --git a/products/metrics/backend/tests/test_metric_event_samples_query_runner.py b/products/metrics/backend/tests/test_metric_event_samples_query_runner.py
index a5603a5b83b0..409ff3672fc3 100644
--- a/products/metrics/backend/tests/test_metric_event_samples_query_runner.py
+++ b/products/metrics/backend/tests/test_metric_event_samples_query_runner.py
@@ -33,10 +33,10 @@ def _insert_orphan_sample(*, team_id: int, metric_name: str, timestamp: dt.datet
# ARRAY JOIN needs every point array to have the same length.
sync_execute(
"INSERT INTO metrics4_samples (team_id, metric_name, time_bucket, series_fingerprint, original_expiry_date, "
- "timestamp_arr, observed_timestamp_arr, value_arr, count_arr, histogram_counts_arr, trace_id_arr, span_id_arr, "
+ "timestamp_arr, value_arr, count_arr, histogram_counts_arr, trace_id_arr, span_id_arr, "
"trace_flags_arr) "
"VALUES (%(team_id)s, %(metric_name)s, toStartOfHour(toDateTime64(%(ts)s, 6)), 42, '2200-01-01', "
- "[toDateTime64(%(ts)s, 6)], [toDateTime64(%(ts)s, 6)], [%(value)s], [1], [[]], [''], [''], [0])",
+ "[toDateTime64(%(ts)s, 6)], [%(value)s], [1], [[]], [''], [''], [0])",
{
"team_id": team_id,
"metric_name": metric_name,
diff --git a/products/metrics/backend/tests/test_metric_query_runner.py b/products/metrics/backend/tests/test_metric_query_runner.py
index 4f4a1fa0efb7..33c571648cfd 100644
--- a/products/metrics/backend/tests/test_metric_query_runner.py
+++ b/products/metrics/backend/tests/test_metric_query_runner.py
@@ -317,6 +317,30 @@ class TestMetricQueryRunner(ClickhouseTestMixin, APIBaseTest):
self.assertEqual([row["value"] for row in runner.run()], [3.0])
+ def test_reads_points_ingested_without_observed_timestamps(self):
+ # Both points sit in one storage hour, so ingest writes a single samples row.
+ anchor = timezone.now().replace(minute=0, second=0, microsecond=0)
+ seed_metric(
+ team_id=self.team.id,
+ metric_name="m1",
+ points=[(anchor - dt.timedelta(minutes=50), 2.0), (anchor - dt.timedelta(minutes=49), 3.0)],
+ )
+
+ stored = sync_execute(
+ "SELECT length(timestamp_arr), length(observed_timestamp_arr) FROM metrics4_samples WHERE team_id = %(team_id)s",
+ {"team_id": self.team.id},
+ )
+ runner = self.runner_class(
+ team=self.team,
+ metric_name="m1",
+ aggregation="sum",
+ date_from=anchor - dt.timedelta(hours=1),
+ date_to=anchor,
+ )
+
+ self.assertEqual(stored, [(2, 0)])
+ self.assertEqual(sum(row["value"] for row in runner.run()), 5.0)
+
def test_respects_team_isolation(self):
anchor = timezone.now().replace(microsecond=0)
seed_metric(