: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(tracing): coerce duration filter to integer nanoseconds (#66853)
posthog[bot]423b9a4fa4d1
diff --git a/products/tracing/backend/logic.py b/products/tracing/backend/logic.pyindex 676c9d9e5841..f8d2bafa0195 100644--- a/products/tracing/backend/logic.py+++ b/products/tracing/backend/logic.py@@ -167,10 +167,10 @@ def translate_span_filter(span_filter: SpanPropertyFilter) -> None:span_filter.key = "duration_nano"if isinstance(span_filter.value, list):span_filter.value = [- str(decimal.Decimal(str(v)) * 1000000) for v in span_filter.value if _is_number(str(v))+ str(int(decimal.Decimal(str(v)) * 1000000)) for v in span_filter.value if _is_number(str(v))]elif _is_number(str(span_filter.value)):- span_filter.value = str(decimal.Decimal(str(span_filter.value)) * 1000000)+ span_filter.value = str(int(decimal.Decimal(str(span_filter.value)) * 1000000))if span_filter.key == "kind" and span_filter.value is not None:values: list = span_filter.value if isinstance(span_filter.value, list) else [span_filter.value]diff --git a/products/tracing/backend/tests/test_logic.py b/products/tracing/backend/tests/test_logic.pyindex 1e45585cce72..e1ca725de4c8 100644--- a/products/tracing/backend/tests/test_logic.py+++ b/products/tracing/backend/tests/test_logic.py@@ -40,6 +40,29 @@ class TestTranslateSpanFilter(SimpleTestCase):translate_span_filter(span_filter)self.assertEqual(span_filter.value, expected)+ @parameterized.expand(+ [+ # Duration is given in seconds and converted to nanoseconds. The result must be an+ # integer string — a `.0`-suffixed value can't be cast to the UInt64 `duration_nano`+ # column and makes ClickHouse throw. Floats (e.g. the slider max) are the regression.+ ("duration_int", 2, "2000000"),+ ("duration_float", 2000000000.0, "2000000000000000"),+ ("duration_float_string", "2000000000.0", "2000000000000000"),+ ("duration_int_string", "2", "2000000"),+ ]+ )+ def test_duration_converts_to_integer_nanoseconds(self, _name, value, expected):+ span_filter = _span_filter("duration", value)+ translate_span_filter(span_filter)+ self.assertEqual(span_filter.key, "duration_nano")+ self.assertEqual(span_filter.value, expected)++ def test_duration_list_converts_to_integer_nanoseconds(self):+ span_filter = _span_filter("duration", [1.0, 2000000000.0])+ translate_span_filter(span_filter)+ self.assertEqual(span_filter.key, "duration_nano")+ self.assertEqual(span_filter.value, ["1000000", "2000000000000000"])+@parameterized.expand([("status_code", "status_code", 2, ["2"]),