Skip to content

Commit 061a7de

Browse files
authored
fix(ourlogs): Add some missing aliases (#97632)
### Summary Adds aliases for precise and observed timestamp, which should be emitted.
1 parent 2a3a36a commit 061a7de

File tree

5 files changed

+95
-4
lines changed

5 files changed

+95
-4
lines changed

src/sentry/search/eap/ourlogs/attributes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@
4242
search_type="string",
4343
validator=is_event_id_or_list,
4444
),
45+
ResolvedAttribute(
46+
public_alias="timestamp_precise",
47+
internal_name="sentry.timestamp_precise",
48+
search_type="number",
49+
),
50+
ResolvedAttribute(
51+
public_alias="observed_timestamp",
52+
internal_name="sentry.observed_timestamp_nanos",
53+
internal_type=constants.STRING, # Stored as string, but we want to search as a number.
54+
search_type="number",
55+
),
56+
ResolvedAttribute(
57+
public_alias="payload_size",
58+
internal_name="sentry.payload_size_bytes",
59+
search_type="byte",
60+
),
4561
simple_sentry_field("browser.name"),
4662
simple_sentry_field("browser.version"),
4763
simple_sentry_field("environment"),

src/sentry/snuba/rpc_dataset_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def get_table_rpc_request(cls, query: TableQuery) -> TableRequest:
157157
query.selected_columns,
158158
has_aggregates=any(equation for equation in equations if equation.is_aggregate),
159159
)
160+
160161
all_columns = columns + equations
161162
contexts = resolver.resolve_contexts(query_contexts + column_contexts)
162163
# We allow orderby function_aliases if they're a selected_column

tests/sentry/search/eap/test_ourlogs.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,50 @@ def test_monoid_functions(function_name, proto_function) -> None:
279279
extrapolation_mode=ExtrapolationMode.EXTRAPOLATION_MODE_SAMPLE_WEIGHTED,
280280
)
281281
assert virtual_context is None
282+
283+
284+
@pytest.mark.parametrize(
285+
"test_case",
286+
[
287+
{
288+
"attribute_definition": OURLOG_DEFINITIONS.columns["observed_timestamp"],
289+
"search_term": 1234567890,
290+
"expected_value": AttributeValue(val_str="1234567890.0"),
291+
"expected_search_proto_type": AttributeKey.Type.TYPE_STRING,
292+
},
293+
{
294+
"attribute_definition": OURLOG_DEFINITIONS.columns["observed_timestamp"],
295+
"search_term": "1111111111",
296+
"expected_value": AttributeValue(val_str="1111111111.0"),
297+
"expected_search_proto_type": AttributeKey.Type.TYPE_STRING,
298+
},
299+
{
300+
"attribute_definition": OURLOG_DEFINITIONS.columns["payload_size"],
301+
"search_term": 1337,
302+
"expected_value": AttributeValue(val_double=1337),
303+
"expected_search_proto_type": AttributeKey.Type.TYPE_DOUBLE,
304+
},
305+
],
306+
)
307+
def test_attribute_search(test_case) -> None:
308+
attribute_definition = test_case["attribute_definition"]
309+
search_term = test_case["search_term"]
310+
expected_value = test_case["expected_value"]
311+
expected_search_proto_type = test_case["expected_search_proto_type"]
312+
attribute_alias = attribute_definition.public_alias
313+
resolver = SearchResolver(
314+
params=SnubaParams(), config=SearchResolverConfig(), definitions=OURLOG_DEFINITIONS
315+
)
316+
query = f"{attribute_alias}:{search_term}"
317+
where, having, _ = resolver.resolve_query(query)
318+
319+
assert where == TraceItemFilter(
320+
comparison_filter=ComparisonFilter(
321+
key=AttributeKey(
322+
name=attribute_definition.internal_name, type=expected_search_proto_type
323+
),
324+
op=ComparisonFilter.OP_EQUALS,
325+
value=expected_value,
326+
)
327+
)
328+
assert having is None

tests/snuba/api/endpoints/test_organization_events_ourlogs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,33 @@ def test_count_meta_type_is_integer(self) -> None:
301301
assert response.data["data"] == [{"message": "foo", "count()": 1}]
302302
assert response.data["meta"]["fields"]["count()"] == "integer"
303303

304+
def test_payload_bytes_meta_type_is_byte(self) -> None:
305+
one_day_ago = before_now(days=1).replace(microsecond=0)
306+
307+
log1 = self.create_ourlog(
308+
{"body": "foo"},
309+
attributes={"sentry.payload_size_bytes": 1234567},
310+
timestamp=one_day_ago,
311+
)
312+
self.store_ourlogs([log1])
313+
314+
request = {
315+
"field": ["message", "payload_size"],
316+
"project": self.project.id,
317+
"dataset": self.dataset,
318+
}
319+
320+
response = self.do_request(
321+
{
322+
**request,
323+
"query": "message:foo payload_size:1234567",
324+
}
325+
)
326+
assert response.status_code == 200, response.content
327+
assert response.data["data"] == [{"message": "foo", "payload_size": 1234567}]
328+
assert response.data["meta"]["fields"]["payload_size"] == "size"
329+
assert response.data["meta"]["units"]["payload_size"] == "byte"
330+
304331
def test_pagelimit(self) -> None:
305332
log = self.create_ourlog(
306333
{"body": "test"},

tests/snuba/api/endpoints/test_project_trace_item_details.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_simple(self) -> None:
7777
"value": str(timestamp_nanos),
7878
},
7979
{
80-
"name": "tags[sentry.timestamp_precise,number]",
80+
"name": "timestamp_precise",
8181
"type": "int",
8282
"value": str(timestamp_nanos),
8383
},
@@ -133,7 +133,7 @@ def test_simple_using_logs_item_type(self) -> None:
133133
"value": str(timestamp_nanos),
134134
},
135135
{
136-
"name": "tags[sentry.timestamp_precise,number]",
136+
"name": "timestamp_precise",
137137
"type": "int",
138138
"value": str(timestamp_nanos),
139139
},
@@ -328,7 +328,7 @@ def test_logs_with_a_meta_key(self) -> None:
328328
"value": str(timestamp_nanos),
329329
},
330330
{
331-
"name": "tags[sentry.timestamp_precise,number]",
331+
"name": "timestamp_precise",
332332
"type": "int",
333333
"value": str(timestamp_nanos),
334334
},
@@ -377,7 +377,7 @@ def test_user_attributes_collide_with_sentry_attributes(self) -> None:
377377
"value": str(timestamp_nanos),
378378
},
379379
{
380-
"name": "tags[sentry.timestamp_precise,number]",
380+
"name": "timestamp_precise",
381381
"type": "int",
382382
"value": str(timestamp_nanos),
383383
},

0 commit comments

Comments
 (0)