|
18 | 18 |
|
19 | 19 | from snuba.datasets.storages.factory import get_storage |
20 | 20 | from snuba.datasets.storages.storage_key import StorageKey |
21 | | -from snuba.web.rpc.v1.endpoint_trace_item_details import EndpointTraceItemDetails |
| 21 | +from snuba.web.rpc.v1.endpoint_trace_item_details import ( |
| 22 | + EndpointTraceItemDetails, |
| 23 | + _convert_results, |
| 24 | +) |
22 | 25 | from snuba.web.rpc.v1.endpoint_trace_item_table import EndpointTraceItemTable |
23 | 26 | from tests.base import BaseApiTest |
24 | 27 | from tests.helpers import write_raw_unprocessed_events |
@@ -325,3 +328,36 @@ def test_endpoint_on_spans(self, setup_spans_in_db: Any) -> None: |
325 | 328 | "str_tag", |
326 | 329 | }: |
327 | 330 | assert k in attributes_returned, k |
| 331 | + |
| 332 | + |
| 333 | +def test_convert_results_dedupes() -> None: |
| 334 | + """ |
| 335 | + Makes sure that _convert_results dedupes int/bool and float |
| 336 | + attributes. We store float versions of int and bool attributes |
| 337 | + for computational reasons but we don't want to return the |
| 338 | + duplicate float attrs to the user. |
| 339 | + """ |
| 340 | + data = [ |
| 341 | + { |
| 342 | + "timestamp": 1750964400, |
| 343 | + "hex_item_id": "e70ef5b1b5bc4611840eff9964b7a767", |
| 344 | + "trace_id": "cb190d6e7d5743d5bc1494c650592cd2", |
| 345 | + "organization_id": 1, |
| 346 | + "project_id": 1, |
| 347 | + "item_type": 1, |
| 348 | + "attributes_string": { |
| 349 | + "relay_protocol_version": "3", |
| 350 | + "sentry.segment_id": "30c64b1f21b54799", |
| 351 | + }, |
| 352 | + "attributes_int": {"sentry.duration_ms": 152}, |
| 353 | + "attributes_float": {"sentry.is_segment": 1.0, "num_of_spans": 50.0}, |
| 354 | + "attributes_bool": { |
| 355 | + "my.true.bool.field": True, |
| 356 | + "sentry.is_segment": True, |
| 357 | + "my.false.bool.field": False, |
| 358 | + }, |
| 359 | + } |
| 360 | + ] |
| 361 | + _, _, attrs = _convert_results(data) |
| 362 | + is_segment_attrs = list(filter(lambda x: x.name == "sentry.is_segment", attrs)) |
| 363 | + assert len(is_segment_attrs) == 1 |
0 commit comments