Skip to content

Commit f36abaf

Browse files
committed
increase limit, introduce randomness
1 parent 7d243a7 commit f36abaf

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/sentry/tasks/llm_issue_detection/trace_data.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,27 @@ def get_project_top_transaction_traces_for_llm_detection(
3333
logger.exception("Project does not exist", extra={"project_id": project_id})
3434
return []
3535

36-
random_offset = random.randint(1, 8)
3736
end_time = datetime.now(UTC)
3837
start_time = end_time - timedelta(minutes=start_time_delta_minutes)
39-
40-
# use for both queries to ensure they are searching the same time window
41-
snuba_params = SnubaParams(
42-
start=start_time,
43-
end=end_time,
44-
projects=[project],
45-
organization=project.organization,
46-
)
4738
config = SearchResolverConfig(auto_fields=True)
4839

49-
# Step 1: Get top transactions by total time in time window
40+
def _build_snuba_params(start: datetime) -> SnubaParams:
41+
"""
42+
Both queries have different start times and the same end time.
43+
"""
44+
return SnubaParams(
45+
start=start,
46+
end=end_time,
47+
projects=[project],
48+
organization=project.organization,
49+
)
50+
51+
transaction_snuba_params = _build_snuba_params(start_time)
52+
random_offset = random.randint(1, 8)
53+
trace_snuba_params = _build_snuba_params(end_time - timedelta(minutes=30 - random_offset))
54+
5055
transactions_result = Spans.run_table_query(
51-
params=snuba_params,
56+
params=transaction_snuba_params,
5257
query_string="is_transaction:true",
5358
selected_columns=[
5459
"transaction",
@@ -74,10 +79,9 @@ def get_project_top_transaction_traces_for_llm_detection(
7479
if normalized_name in seen_names:
7580
continue
7681

77-
# Step 2: Get ONE trace for this transaction from THE SAME time window
7882
escaped_transaction_name = UNESCAPED_QUOTE_RE.sub('\\"', transaction_name)
7983
trace_result = Spans.run_table_query(
80-
params=snuba_params,
84+
params=trace_snuba_params,
8185
query_string=f'is_transaction:true transaction:"{escaped_transaction_name}"',
8286
selected_columns=["trace", "precise.start_ts"],
8387
orderby=["precise.start_ts"], # First trace in the window

tests/sentry/tasks/test_llm_issue_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_returns_deduped_transaction_traces(self) -> None:
308308
self.store_spans([span1, span2, span3], is_eap=True)
309309

310310
evidence_traces = get_project_top_transaction_traces_for_llm_detection(
311-
self.project.id, limit=50, start_time_delta_minutes=30
311+
self.project.id, limit=100, start_time_delta_minutes=30
312312
)
313313

314314
assert len(evidence_traces) == 2

0 commit comments

Comments
 (0)