Skip to content

Commit 2230bd5

Browse files
committed
Fix the search_type order for renaming
1 parent 2b94237 commit 2230bd5

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

src/sentry/data_export/utils.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,30 @@
88
from google.protobuf.timestamp_pb2 import Timestamp
99
from sentry_protos.snuba.v1.endpoint_trace_items_pb2 import ExportTraceItemsResponse
1010
from sentry_protos.snuba.v1.trace_item_pb2 import AnyValue, TraceItem
11+
1112
from sentry.data_export.base import ExportError
1213
from sentry.search.eap.types import SupportedTraceItemType
13-
from sentry.search.eap.utils import (
14-
INTERNAL_TO_PUBLIC_ALIAS_MAPPINGS,
15-
can_expose_attribute,
16-
translate_internal_to_public_alias,
17-
)
14+
from sentry.search.eap.utils import can_expose_attribute, translate_internal_to_public_alias
1815
from sentry.search.events.constants import TIMEOUT_ERROR_MESSAGE
1916
from sentry.snuba import discover
2017
from sentry.utils import metrics, snuba
2118
from sentry.utils.sdk import capture_exception
2219
from sentry.utils.snuba_rpc import SnubaRPCRateLimitExceeded
2320

21+
_SCALAR_SEARCH_TYPES: list[Literal["string", "number", "boolean"]] = [
22+
"string",
23+
"number",
24+
"boolean",
25+
]
2426

27+
PROTOBUF_TYPE_TO_SEARCH_TYPE: dict[str, Literal["string", "number", "boolean"]] = {
28+
"string_value": "string",
29+
"bytes_value": "string",
30+
"bool_value": "boolean",
31+
"int_value": "number",
32+
"double_value": "number",
33+
}
2534

26-
def eap_storage_scalar_type_from_protobuf(
27-
which: str | None,
28-
) -> Literal["string", "number", "boolean"] | None:
29-
if which is None:
30-
return None
31-
if which in ("string_value", "bytes_value"):
32-
return "string"
33-
if which == "bool_value":
34-
return "boolean"
35-
if which in ("int_value", "double_value"):
36-
return "number"
37-
if which in ("array_value", "kvlist_value"):
38-
return None
39-
return None
4035

4136
# Adapted into decorator from 'src/sentry/api/endpoints/organization_events.py'
4237
def handle_snuba_errors(
@@ -138,23 +133,15 @@ def _export_column_name_for_scalar_trace_attribute(
138133
eap_storage_type: Literal["string", "number", "boolean"],
139134
item_type: SupportedTraceItemType,
140135
) -> str:
141-
# eap_storage_type is not same as search_type used in translate_internal_to_public_alias
142-
per_type = INTERNAL_TO_PUBLIC_ALIAS_MAPPINGS.get(item_type)
143-
if per_type is not None:
144-
for typ in ("string", "number", "boolean"):
145-
if internal_key in per_type.get(typ, {}):
146-
public_alias, public_name, _ = translate_internal_to_public_alias(
147-
internal_key, typ, item_type
148-
)
149-
if public_alias is not None and public_name is not None:
150-
return public_name
151-
break
152-
# column_to_alias still needs a type; use storage type.
153-
public_alias, public_name, _ = translate_internal_to_public_alias(
154-
internal_key, eap_storage_type, item_type
155-
)
156-
if public_alias is not None and public_name is not None:
157-
return public_name
136+
"""Map a scalar trace item attribute to its public export column name."""
137+
for storage_type in [eap_storage_type] + [
138+
t for t in _SCALAR_SEARCH_TYPES if t != eap_storage_type
139+
]:
140+
public_alias, public_name, _ = translate_internal_to_public_alias(
141+
internal_key, storage_type, item_type
142+
)
143+
if public_alias is not None and public_name is not None:
144+
return public_name
158145
return internal_key
159146

160147

@@ -174,7 +161,7 @@ def trace_item_to_row(
174161
continue
175162
which = av.WhichOneof("value")
176163
value = None if which is None else anyvalue_to_python(av)
177-
eap_storage_type = eap_storage_scalar_type_from_protobuf(which)
164+
eap_storage_type = PROTOBUF_TYPE_TO_SEARCH_TYPE.get(which) if which is not None else None
178165
if eap_storage_type is None:
179166
new_key = internal_key
180167
else:

0 commit comments

Comments
 (0)