Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eap-api): return normalized fields for GetTraceEndpoint #6856

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_get_trace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from datetime import datetime
from operator import attrgetter
from typing import Any, Dict, Iterable

Expand Down Expand Up @@ -86,6 +87,32 @@ def _build_query(request: GetTraceRequest) -> Query:
),
),
]
selected_columns.extend(
[
SelectedExpression(
name=col_name, expression=column(col_name, alias=col_name)
)
for col_name in [
"organization_id",
"project_id",
"service",
"trace_id",
"span_id",
"parent_span_id",
"segment_id",
"segment_name",
"is_segment",
"_sort_timestamp",
"start_timestamp",
"end_timestamp",
"duration_micro",
"exclusive_time_micro",
"name",
"sampling_factor",
"sampling_weight",
]
]
)

entity = Entity(
key=EntityKey("eap_spans"),
Expand Down Expand Up @@ -168,14 +195,14 @@ def _value_to_attribute(key: str, value: Any) -> tuple[AttributeKey, AttributeVa
val_double=value,
),
)
elif isinstance(value, str):
elif isinstance(value, str) or isinstance(value, datetime):
return (
AttributeKey(
name=key,
type=AttributeKey.Type.TYPE_STRING,
),
AttributeValue(
val_str=value,
val_str=str(value),
),
)
else:
Expand Down
35 changes: 34 additions & 1 deletion tests/web/rpc/v1/test_endpoint_get_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@
) - timedelta(minutes=180)
_SPAN_COUNT = 120
_REQUEST_ID = uuid.uuid4().hex
_NORMALIZED_FIELDS = [
"organization_id",
"project_id",
"service",
"trace_id",
"span_id",
"parent_span_id",
"segment_id",
"segment_name",
"is_segment",
"_sort_timestamp",
"start_timestamp",
"end_timestamp",
"duration_micro",
"exclusive_time_micro",
"name",
"sampling_factor",
"sampling_weight",
]


def gen_message(
Expand Down Expand Up @@ -266,7 +285,21 @@ def test_with_data(self, setup_teardown: Any) -> None:
),
],
)
assert MessageToDict(response) == MessageToDict(expected_response)

assert list(
[
attribute
for attribute in response.item_groups[0].items[0].attributes
if attribute.key.name not in _NORMALIZED_FIELDS
]
) == list(expected_response.item_groups[0].items[0].attributes)
assert set(
[
attribute.key.name
for attribute in response.item_groups[0].items[0].attributes
if attribute.key.name in _NORMALIZED_FIELDS
]
) == set(_NORMALIZED_FIELDS)

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