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(rpc): Validate trace_id queries on INs #86052

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion src/sentry/search/eap/span_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
from sentry.search.utils import DEVICE_CLASS
from sentry.utils.validators import is_event_id, is_span_id


def validate_event_id(value: str | list[str]) -> bool:
if isinstance(value, list):
return all([is_event_id(item) for item in value])
else:
return is_event_id(value)


SPAN_ATTRIBUTE_DEFINITIONS = {
column.public_alias: column
for column in COMMON_COLUMNS
Expand Down Expand Up @@ -109,7 +117,7 @@
public_alias="trace",
internal_name="sentry.trace_id",
search_type="string",
validator=is_event_id,
validator=validate_event_id,
),
ResolvedColumn(
public_alias="transaction",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2582,3 +2582,43 @@ def test_unit_aggregate_filtering(self):
},
]
assert meta["dataset"] == self.dataset

def test_trace_id_in_filter(self):
spans = [
self.create_span(
{"description": "bar", "trace_id": "1" * 32},
start_ts=self.ten_mins_ago,
),
self.create_span(
{"description": "foo", "trace_id": "2" * 32},
start_ts=self.ten_mins_ago,
),
]
self.store_spans(spans, is_eap=self.is_eap)
response = self.do_request(
{
"field": ["description"],
"query": f"trace:[{'1' * 32}, {'2' * 32}]",
"orderby": "description",
"project": self.project.id,
"dataset": self.dataset,
}
)

assert response.status_code == 200, response.content
data = response.data["data"]
meta = response.data["meta"]
assert len(data) == 2
assert data == [
{
"description": "bar",
"id": mock.ANY,
"project.name": self.project.slug,
},
{
"description": "foo",
"id": mock.ANY,
"project.name": self.project.slug,
},
]
assert meta["dataset"] == self.dataset
Loading