Skip to content

Commit c36bdc3

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

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/sentry/tasks/llm_issue_detection/trace_data.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,26 @@ def get_project_top_transaction_traces_for_llm_detection(
3636
random_offset = random.randint(1, 8)
3737
end_time = datetime.now(UTC)
3838
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-
)
4739
config = SearchResolverConfig(auto_fields=True)
4840

41+
def _build_snuba_params(start: datetime) -> SnubaParams:
42+
"""
43+
Both queries have different start times and the same end time.
44+
"""
45+
return SnubaParams(
46+
start=start,
47+
end=end_time,
48+
projects=[project],
49+
organization=project.organization,
50+
)
51+
52+
transaction_snuba_params = _build_snuba_params(start_time)
53+
random_offset = random.randint(1, 8)
54+
trace_snuba_params = _build_snuba_params(end_time - timedelta(minutes=30 - random_offset))
55+
4956
# Step 1: Get top transactions by total time in time window
5057
transactions_result = Spans.run_table_query(
51-
params=snuba_params,
58+
params=transaction_snuba_params,
5259
query_string="is_transaction:true",
5360
selected_columns=[
5461
"transaction",
@@ -77,7 +84,7 @@ def get_project_top_transaction_traces_for_llm_detection(
7784
# Step 2: Get ONE trace for this transaction from THE SAME time window
7885
escaped_transaction_name = UNESCAPED_QUOTE_RE.sub('\\"', transaction_name)
7986
trace_result = Spans.run_table_query(
80-
params=snuba_params,
87+
params=trace_snuba_params,
8188
query_string=f'is_transaction:true transaction:"{escaped_transaction_name}"',
8289
selected_columns=["trace", "precise.start_ts"],
8390
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)