Skip to content

Commit 2575556

Browse files
authored
ref(explorer): change transactions ranking (#102966)
Instead of picking the top transactions for a project by volume, pick them by total time spent. This mirrors what's done on the Insights page and seems to select the more meaningful parts of the app (rather than stuff like health checks and middleware for example).
1 parent 0f1c61d commit 2575556

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/sentry/seer/explorer/index_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_transactions_for_project(
4343
project_id: int, limit: int = 500, start_time_delta: dict[str, int] | None = None
4444
) -> list[Transaction]:
4545
"""
46-
Get a list of transactions for a project using EAP, sorted by volume/traffic.
46+
Get a list of transactions for a project using EAP, sorted by total time spent.
4747
4848
Args:
4949
project_id: The ID of the project to fetch transactions for
@@ -75,15 +75,15 @@ def get_transactions_for_project(
7575
auto_fields=True,
7676
)
7777

78-
# Query EAP for transactions with volume metrics
78+
# Query EAP for most important transactions (highest total time spent)
7979
result = Spans.run_table_query(
8080
params=snuba_params,
81-
query_string=f"is_transaction:true project.id:{project_id}",
81+
query_string="is_transaction:true",
8282
selected_columns=[
8383
"transaction",
84-
"count()",
84+
"sum(span.duration)",
8585
],
86-
orderby=["-count()"], # Sort by count descending (highest volume first)
86+
orderby=["-sum(span.duration)"],
8787
offset=0,
8888
limit=limit,
8989
referrer=Referrer.SEER_RPC,

tests/sentry/seer/explorer/test_index_data.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ def setUp(self) -> None:
2323

2424
def test_get_transactions_for_project(self) -> None:
2525
"""Test the full end-to-end happy path for get_transactions_for_project."""
26-
# Create spans for different transactions with varying volumes
26+
# Create spans for different transactions with varying total time spent
27+
# Format: (transaction_name, count, avg_duration_ms)
2728
transactions_data = [
28-
("api/users/profile", 5), # High volume
29-
("api/posts/create", 3), # Medium volume
30-
("api/health", 1), # Low volume
29+
("api/users/profile", 5, 100.0), # 5 * 100 = 500ms total (highest)
30+
("api/posts/create", 3, 150.0), # 3 * 150 = 450ms total (middle)
31+
("api/health", 10, 10.0), # 10 * 10 = 100ms total (lowest, despite high count)
3132
]
3233

33-
# Store transaction spans with different volumes
34+
# Store transaction spans with different volumes and durations
3435
spans = []
35-
for transaction_name, count in transactions_data:
36+
for transaction_name, count, duration_ms in transactions_data:
3637
for i in range(count):
3738
span = self.create_span(
3839
{
3940
"description": f"transaction-span-{i}",
4041
"sentry_tags": {"transaction": transaction_name},
4142
"is_segment": True, # This marks it as a transaction span
43+
"duration_ms": duration_ms,
4244
},
4345
start_ts=self.ten_mins_ago + timedelta(minutes=i),
4446
)
@@ -51,6 +53,7 @@ def test_get_transactions_for_project(self) -> None:
5153
"description": f"regular-span-{i}",
5254
"sentry_tags": {"transaction": transaction_name},
5355
"is_segment": False, # This marks it as a regular span
56+
"duration_ms": 50.0,
5457
},
5558
start_ts=self.ten_mins_ago + timedelta(minutes=i, seconds=30),
5659
)
@@ -64,11 +67,11 @@ def test_get_transactions_for_project(self) -> None:
6467
# Verify basic structure and data
6568
assert len(result) == 3
6669

67-
# Should be sorted by volume (count) descending - only transaction spans count
70+
# Should be sorted by total time spent (sum of duration) descending
6871
transaction_names = [t.name for t in result]
69-
assert transaction_names[0] == "api/users/profile" # Highest count (5 transaction spans)
70-
assert transaction_names[1] == "api/posts/create" # Medium count (3 transaction spans)
71-
assert transaction_names[2] == "api/health" # Lowest count (1 transaction span)
72+
assert transaction_names[0] == "api/users/profile" # 500ms total (highest)
73+
assert transaction_names[1] == "api/posts/create" # 450ms total (middle)
74+
assert transaction_names[2] == "api/health" # 100ms total (lowest despite high count)
7275

7376
# Verify all transactions have correct project_id and structure
7477
for transaction in result:

0 commit comments

Comments
 (0)