Skip to content

Commit d9de7ac

Browse files
committed
Fix mypy
1 parent 807630e commit d9de7ac

File tree

4 files changed

+69
-54
lines changed

4 files changed

+69
-54
lines changed

src/sentry/seer/endpoints/seer_rpc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
from sentry.search.events.types import SnubaParams
5757
from sentry.seer.autofix.autofix_tools import get_error_event_details, get_profile_details
5858
from sentry.seer.explorer.index_data import (
59-
get_issues_for_transaction,
60-
get_profiles_for_trace,
61-
get_trace_for_transaction,
62-
get_transactions_for_project,
59+
rpc_get_issues_for_transaction,
60+
rpc_get_profiles_for_trace,
61+
rpc_get_trace_for_transaction,
62+
rpc_get_transactions_for_project,
6363
)
6464
from sentry.seer.fetch_issues.fetch_issues import (
6565
get_issues_related_to_file_patches,
@@ -563,10 +563,10 @@ def get_github_enterprise_integration_config(
563563
"get_attribute_names": get_attribute_names,
564564
"get_attribute_values_with_substring": get_attribute_values_with_substring,
565565
"get_attributes_and_values": get_attributes_and_values,
566-
"get_transactions_for_project": get_transactions_for_project,
567-
"get_trace_for_transaction": get_trace_for_transaction,
568-
"get_profiles_for_trace": get_profiles_for_trace,
569-
"get_issues_for_transaction": get_issues_for_transaction,
566+
"get_transactions_for_project": rpc_get_transactions_for_project,
567+
"get_trace_for_transaction": rpc_get_trace_for_transaction,
568+
"get_profiles_for_trace": rpc_get_profiles_for_trace,
569+
"get_issues_for_transaction": rpc_get_issues_for_transaction,
570570
"get_github_enterprise_integration_config": get_github_enterprise_integration_config,
571571
}
572572

src/sentry/seer/explorer/index_data.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import orjson
66

77
from sentry import search
8-
from sentry.api.event_search import parse_search_query
8+
from sentry.api.event_search import SearchFilter, parse_search_query
9+
from sentry.api.issue_search import convert_query_values
910
from sentry.api.serializers.base import serialize
1011
from sentry.api.serializers.models.event import EventSerializer
1112
from sentry.eventstore import backend as eventstore
12-
from sentry.eventstore.models import GroupEvent
13+
from sentry.eventstore.models import Event, GroupEvent
1314
from sentry.models.project import Project
1415
from sentry.profiles.utils import get_from_profiling_service
1516
from sentry.search.eap.types import SearchResolverConfig
@@ -397,27 +398,19 @@ def get_issues_for_transaction(transaction_name: str, project_id: int) -> Transa
397398
start_time = end_time - timedelta(hours=24)
398399

399400
# Step 1: Search for issues using transaction filter
400-
try:
401-
parsed_terms = parse_search_query(f'transaction:"{transaction_name}"')
402-
except Exception:
403-
logger.exception(
404-
"Failed to parse transaction search query",
405-
extra={"transaction_name": transaction_name, "project_id": project_id},
406-
)
407-
return None
401+
parsed_terms = parse_search_query(f'transaction:"{transaction_name}"')
402+
converted_terms = convert_query_values(parsed_terms, [project], None, [])
403+
search_filters = [term for term in converted_terms if isinstance(term, SearchFilter)]
408404

409-
# Query for issues using the search backend
410-
query_kwargs = {
411-
"projects": [project],
412-
"date_from": start_time,
413-
"date_to": end_time,
414-
"search_filters": parsed_terms,
415-
"sort_by": "freq",
416-
"limit": 3,
417-
"environments": [],
418-
}
419-
420-
results_cursor = search.backend.query(**query_kwargs)
405+
results_cursor = search.backend.query(
406+
projects=[project],
407+
date_from=start_time,
408+
date_to=end_time,
409+
search_filters=search_filters,
410+
sort_by="freq",
411+
limit=3,
412+
environments=[],
413+
)
421414
issues = list(results_cursor)
422415

423416
if not issues:
@@ -441,7 +434,7 @@ def get_issues_for_transaction(transaction_name: str, project_id: int) -> Transa
441434
)
442435
continue
443436

444-
full_event: GroupEvent | None = eventstore.get_event_by_id(
437+
full_event: Event | GroupEvent | None = eventstore.get_event_by_id(
445438
project_id=group.project_id,
446439
event_id=recommended_event.event_id,
447440
group_id=group.id,
@@ -479,3 +472,27 @@ def get_issues_for_transaction(transaction_name: str, project_id: int) -> Transa
479472
project_id=project_id,
480473
issues=issue_data_list,
481474
)
475+
476+
477+
# RPC wrappers
478+
479+
480+
def rpc_get_transactions_for_project(project_id: int) -> dict[str, Any]:
481+
transactions = get_transactions_for_project(project_id)
482+
transaction_dicts = [transaction.dict() for transaction in transactions]
483+
return {"transactions": transaction_dicts}
484+
485+
486+
def rpc_get_trace_for_transaction(transaction_name: str, project_id: int) -> dict[str, Any]:
487+
trace = get_trace_for_transaction(transaction_name, project_id)
488+
return trace.dict() if trace else {}
489+
490+
491+
def rpc_get_profiles_for_trace(trace_id: str, project_id: int) -> dict[str, Any]:
492+
profiles = get_profiles_for_trace(trace_id, project_id)
493+
return profiles.dict() if profiles else {}
494+
495+
496+
def rpc_get_issues_for_transaction(transaction_name: str, project_id: int) -> dict[str, Any]:
497+
issues = get_issues_for_transaction(transaction_name, project_id)
498+
return issues.dict() if issues else {}

tests/sentry/seer/explorer/test_explorer_utils.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
from sentry.seer.explorer.utils import convert_profile_to_execution_tree, normalize_description
24

35

@@ -14,11 +16,6 @@ def test_normalize_description_empty_string(self):
1416
result = normalize_description("")
1517
assert result == ""
1618

17-
def test_normalize_description_none_input(self):
18-
"""Test with None input."""
19-
result = normalize_description(None)
20-
assert result == ""
21-
2219
def test_normalize_description_uuid_with_dashes(self):
2320
"""Test UUID normalization with dashes."""
2421
result = normalize_description(
@@ -116,7 +113,7 @@ def test_convert_profile_no_profile_key(self):
116113

117114
def test_convert_profile_missing_required_fields(self):
118115
"""Test with missing required fields in profile."""
119-
profile_data = {"profile": {"frames": []}}
116+
profile_data: dict[str, Any] = {"profile": {"frames": []}}
120117
result = convert_profile_to_execution_tree(profile_data)
121118
assert result == []
122119

@@ -126,7 +123,7 @@ def test_convert_profile_missing_required_fields(self):
126123

127124
def test_convert_profile_empty_profile_data(self):
128125
"""Test with empty but valid profile structure."""
129-
profile_data = {
126+
profile_data: dict[str, Any] = {
130127
"profile": {
131128
"frames": [],
132129
"stacks": [],
@@ -139,7 +136,7 @@ def test_convert_profile_empty_profile_data(self):
139136

140137
def test_convert_profile_single_frame_single_sample(self):
141138
"""Test with minimal valid profile data."""
142-
profile_data = {
139+
profile_data: dict[str, Any] = {
143140
"profile": {
144141
"frames": [
145142
{
@@ -179,7 +176,7 @@ def test_convert_profile_single_frame_single_sample(self):
179176

180177
def test_convert_profile_nested_call_stack(self):
181178
"""Test with nested call stack."""
182-
profile_data = {
179+
profile_data: dict[str, Any] = {
183180
"profile": {
184181
"frames": [
185182
{
@@ -233,7 +230,7 @@ def test_convert_profile_nested_call_stack(self):
233230

234231
def test_convert_profile_multiple_samples_duration_calculation(self):
235232
"""Test duration calculation with multiple samples."""
236-
profile_data = {
233+
profile_data: dict[str, Any] = {
237234
"profile": {
238235
"frames": [
239236
{
@@ -278,7 +275,7 @@ def test_convert_profile_multiple_samples_duration_calculation(self):
278275

279276
def test_convert_profile_filters_non_app_frames(self):
280277
"""Test that non-app frames are filtered out."""
281-
profile_data = {
278+
profile_data: dict[str, Any] = {
282279
"profile": {
283280
"frames": [
284281
{
@@ -326,7 +323,7 @@ def test_convert_profile_filters_non_app_frames(self):
326323

327324
def test_convert_profile_filters_generated_frames(self):
328325
"""Test that generated frames (with <filename>) are filtered out."""
329-
profile_data = {
326+
profile_data: dict[str, Any] = {
330327
"profile": {
331328
"frames": [
332329
{
@@ -366,7 +363,7 @@ def test_convert_profile_filters_generated_frames(self):
366363

367364
def test_convert_profile_single_thread_fallback(self):
368365
"""Test fallback to single thread when no MainThread is found."""
369-
profile_data = {
366+
profile_data: dict[str, Any] = {
370367
"profile": {
371368
"frames": [
372369
{
@@ -395,7 +392,7 @@ def test_convert_profile_single_thread_fallback(self):
395392

396393
def test_convert_profile_ignores_other_threads(self):
397394
"""Test that samples from other threads are ignored."""
398-
profile_data = {
395+
profile_data: dict[str, Any] = {
399396
"profile": {
400397
"frames": [
401398
{
@@ -442,7 +439,7 @@ def test_convert_profile_ignores_other_threads(self):
442439

443440
def test_convert_profile_complex_call_patterns(self):
444441
"""Test complex call patterns with function entries and exits."""
445-
profile_data = {
442+
profile_data: dict[str, Any] = {
446443
"profile": {
447444
"frames": [
448445
{
@@ -508,7 +505,7 @@ def test_convert_profile_complex_call_patterns(self):
508505

509506
def test_convert_profile_duration_calculation_accuracy(self):
510507
"""Test that duration calculations are reasonable."""
511-
profile_data = {
508+
profile_data: dict[str, Any] = {
512509
"profile": {
513510
"frames": [
514511
{

tests/sentry/seer/explorer/test_index_data.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ def test_get_trace_for_transaction(self):
126126
assert len(result.spans) == 5
127127

128128
# Verify all spans have correct structure and belong to the chosen trace
129-
for span in result.spans:
130-
assert hasattr(span, "span_id")
131-
assert hasattr(span, "span_description")
132-
assert hasattr(span, "parent_span_id")
133-
assert hasattr(span, "span_op")
134-
assert span.span_description.startswith("span-")
135-
assert "trace-medium" in span.span_description # Should be from the median trace
129+
for result_span in result.spans:
130+
assert hasattr(result_span, "span_id")
131+
assert hasattr(result_span, "span_description")
132+
assert hasattr(result_span, "parent_span_id")
133+
assert hasattr(result_span, "span_op")
134+
assert result_span.span_description is not None
135+
assert result_span.span_description.startswith("span-")
136+
assert "trace-medium" in result_span.span_description # Should be from the median trace
136137

137138
# Verify parent-child relationships are preserved
138139
root_spans = [s for s in result.spans if s.parent_span_id is None]

0 commit comments

Comments
 (0)