: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
fix(error-tracking): stabilize fingerprint grouping key (#76568)
Hugues Pouillot0fc5d3bfa8ec
diff --git a/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.py b/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.pyindex 4e2c27d4c50a..bceb520e76ad 100644--- a/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.py+++ b/products/error_tracking/backend/hogql_queries/error_tracking_query_builder.py@@ -87,6 +87,27 @@ def _merge(state_alias: str, base_aggregator: str) -> ast.Call:return ast.Call(name=base_aggregator + _MERGE_SUFFIX, args=[ast.Field(chain=["ev", state_alias])])+def _fingerprint_hash_expr() -> ast.Call:+ """Hash the fingerprint without resolving it to its materialized column.++ Distributed aggregation uses the textual expression as the block-column+ name for grouping keys. ClickHouse versions disagree on whether the ``$``+ in ``mat_$exception_fingerprint`` needs backticks in that name, which can+ make the coordinator reject an otherwise valid block returned by a shard.+ Reading the string directly from the properties JSON keeps the expression+ stable across nodes.+ """+ return ast.Call(+ name="cityHash64",+ args=[+ ast.Call(+ name="JSONExtractString",+ args=[ast.Field(chain=["e", "properties"]), ast.Constant(value="$exception_fingerprint")],+ )+ ],+ )++class ErrorTrackingQueryBuilder:"""ClickHouse-only query builder using the denormalized fingerprint table.@@ -226,10 +247,7 @@ class ErrorTrackingQueryBuilder:exprs: list[ast.Expr] = [ast.Alias(alias="fp_hash",- expr=ast.Call(- name="cityHash64",- args=[ast.Field(chain=["e", "properties", "$exception_fingerprint"])],- ),+ expr=_fingerprint_hash_expr(),),ast.Alias(alias="last_seen_fp", expr=ast.Call(name="max", args=[ast.Field(chain=["timestamp"])])),ast.Alias(alias="function_state", expr=_state(innermost_frame_attribute("$exception_functions"))),diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambrindex eb5d53fcdbe3..b7ac96d3a7fd 100644--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr@@ -18,7 +18,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -88,7 +88,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -153,7 +153,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -313,7 +313,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -366,7 +366,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -419,7 +419,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -472,7 +472,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -525,7 +525,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -645,7 +645,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -710,7 +710,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -763,7 +763,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -816,7 +816,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -874,7 +874,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -939,7 +939,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -999,7 +999,7 @@argMaxMerge(ev.source_state) AS source,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -1074,7 +1074,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -1154,7 +1154,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -1234,7 +1234,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 4))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,@@ -1304,7 +1304,7 @@and isNull(i)), ev.occ, toUInt64(0)), range(0, 3))) AS volumeRange,argMaxMerge(ev.library_state) AS libraryFROM- (SELECT cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')) AS fp_hash,+ (SELECT cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS function_state,argMaxState(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources', -1), ''), 'null'), '^"|"$', ''), toTimeZone(e.timestamp, 'UTC')) AS source_state,diff --git a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.pyindex 00a5d99ef503..154a7edaa083 100644--- a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py+++ b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py@@ -123,6 +123,12 @@ class TestErrorTrackingQueryRunner(ClickhouseTestMixin, NonAtomicBaseTestKeepIdematerialize("events", property_name, is_nullable=property_name == "$exception_issue_id")super().setUpClass()+ def test_fingerprint_grouping_key_uses_stable_json_expression(self):+ response = self._calculate()++ self.assertIn("JSONExtractString(e.properties, '$exception_fingerprint')", response["hogql"])+ self.assertNotIn("mat_$exception_fingerprint", response["hogql"])+def setUp(self):super().setUp()