Skip to content

Commit 9ad86f4

Browse files
xurui-cRachel ChenRachel Chen
authored
fix(eap-api): return normalized fields for GetTraceEndpoint (#6856)
Currently, if the user doesn't specify attributes to the GetTraceEndpoint, we won't return normalized fields; however, we should getsentry/eap-planning#187 --------- Co-authored-by: Rachel Chen <[email protected]> Co-authored-by: Rachel Chen <[email protected]>
1 parent 311ab20 commit 9ad86f4

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_get_trace.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import uuid
2+
from datetime import datetime
23
from operator import attrgetter
34
from typing import Any, Dict, Iterable
45

@@ -41,6 +42,21 @@
4142
_BUCKET_COUNT = 20
4243

4344

45+
NORMALIZED_COLUMNS_TO_INCLUDE = [
46+
col.name
47+
for col in get_entity(EntityKey("eap_spans")).get_data_model().columns
48+
if col.name
49+
not in [
50+
"retention_days",
51+
"sign",
52+
"attr_str",
53+
"attr_num",
54+
"span_id",
55+
"timestamp",
56+
]
57+
]
58+
59+
4460
def _build_query(request: GetTraceRequest) -> Query:
4561
selected_columns: list[SelectedExpression] = [
4662
SelectedExpression(
@@ -86,6 +102,14 @@ def _build_query(request: GetTraceRequest) -> Query:
86102
),
87103
),
88104
]
105+
selected_columns.extend(
106+
[
107+
SelectedExpression(
108+
name=col_name, expression=column(col_name, alias=col_name)
109+
)
110+
for col_name in NORMALIZED_COLUMNS_TO_INCLUDE
111+
]
112+
)
89113

90114
entity = Entity(
91115
key=EntityKey("eap_spans"),
@@ -178,6 +202,16 @@ def _value_to_attribute(key: str, value: Any) -> tuple[AttributeKey, AttributeVa
178202
val_str=value,
179203
),
180204
)
205+
elif isinstance(value, datetime):
206+
return (
207+
AttributeKey(
208+
name=key,
209+
type=AttributeKey.Type.TYPE_DOUBLE,
210+
),
211+
AttributeValue(
212+
val_double=value.timestamp(),
213+
),
214+
)
181215
else:
182216
raise BadSnubaRPCRequestException(f"data type unknown: {type(value)}")
183217

tests/web/rpc/v1/test_endpoint_get_trace.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
from snuba.datasets.storages.factory import get_storage
2323
from snuba.datasets.storages.storage_key import StorageKey
2424
from snuba.web.rpc.v1.endpoint_get_trace import EndpointGetTrace
25+
from snuba.web.rpc.v1.resolvers.R_eap_spans.resolver_get_trace import (
26+
NORMALIZED_COLUMNS_TO_INCLUDE,
27+
)
2528
from tests.base import BaseApiTest
2629
from tests.helpers import write_raw_unprocessed_events
2730

@@ -266,7 +269,21 @@ def test_with_data(self, setup_teardown: Any) -> None:
266269
),
267270
],
268271
)
269-
assert MessageToDict(response) == MessageToDict(expected_response)
272+
273+
assert list(
274+
[
275+
attribute
276+
for attribute in response.item_groups[0].items[0].attributes
277+
if attribute.key.name not in NORMALIZED_COLUMNS_TO_INCLUDE
278+
]
279+
) == list(expected_response.item_groups[0].items[0].attributes)
280+
assert set(
281+
[
282+
attribute.key.name
283+
for attribute in response.item_groups[0].items[0].attributes
284+
if attribute.key.name in NORMALIZED_COLUMNS_TO_INCLUDE
285+
]
286+
) == set(NORMALIZED_COLUMNS_TO_INCLUDE)
270287

271288
def test_with_specific_attributes(self, setup_teardown: Any) -> None:
272289
ts = Timestamp(seconds=int(_BASE_TIME.timestamp()))

0 commit comments

Comments
 (0)