diff --git a/src/sentry/issues/auto_source_code_config/code_mapping.py b/src/sentry/issues/auto_source_code_config/code_mapping.py index 0a66a1f88543e0..15508dfcd30804 100644 --- a/src/sentry/issues/auto_source_code_config/code_mapping.py +++ b/src/sentry/issues/auto_source_code_config/code_mapping.py @@ -54,6 +54,7 @@ class NeedsExtension(Exception): def derive_code_mappings( organization: Organization, frame: Mapping[str, Any], + platform: str | None = None, ) -> list[dict[str, str]]: installation = get_installation(organization) if not isinstance(installation, RepoTreesIntegration): @@ -61,7 +62,7 @@ def derive_code_mappings( trees = installation.get_trees_for_org() trees_helper = CodeMappingTreesHelper(trees) try: - frame_filename = FrameInfo(frame) + frame_filename = FrameInfo(frame, platform) return trees_helper.list_file_matches(frame_filename) except NeedsExtension: logger.warning("Needs extension: %s", frame.get("filename")) @@ -71,8 +72,8 @@ def derive_code_mappings( # XXX: Look at sentry.interfaces.stacktrace and maybe use that class FrameInfo: - def __init__(self, frame: Mapping[str, Any]) -> None: - # XXX: In the next PR, we will use more than just the filename + def __init__(self, frame: Mapping[str, Any], platform: str | None = None) -> None: + # XXX: platform will be used in a following PR frame_file_path = frame["filename"] frame_file_path = self.transformations(frame_file_path) @@ -102,11 +103,13 @@ def __init__(self, frame: Mapping[str, Any]) -> None: def transformations(self, frame_file_path: str) -> str: self.raw_path = frame_file_path + is_windows_path = False if "\\" in frame_file_path: is_windows_path = True frame_file_path = frame_file_path.replace("\\", "/") + # Remove leading slash if it exists if frame_file_path[0] == "/" or frame_file_path[0] == "\\": frame_file_path = frame_file_path[1:] @@ -131,15 +134,21 @@ def __eq__(self, other: object) -> bool: # call generate_code_mappings() after you initialize CodeMappingTreesHelper class CodeMappingTreesHelper: + platform: str | None = None + def __init__(self, trees: Mapping[str, RepoTree]): self.trees = trees self.code_mappings: dict[str, CodeMapping] = {} - def generate_code_mappings(self, frames: Sequence[Mapping[str, Any]]) -> list[CodeMapping]: + def generate_code_mappings( + self, frames: Sequence[Mapping[str, Any]], platform: str | None = None + ) -> list[CodeMapping]: """Generate code mappings based on the initial trees object and the list of stack traces""" # We need to make sure that calling this method with a new list of stack traces # should always start with a clean slate self.code_mappings = {} + self.platform = platform + buckets: dict[str, list[FrameInfo]] = self._stacktrace_buckets(frames) # We reprocess stackframes until we are told that no code mappings were produced @@ -200,7 +209,7 @@ def _stacktrace_buckets( buckets: defaultdict[str, list[FrameInfo]] = defaultdict(list) for frame in frames: try: - frame_filename = FrameInfo(frame) + frame_filename = FrameInfo(frame, self.platform) # Any files without a top directory will be grouped together buckets[frame_filename.stack_root].append(frame_filename) except UnsupportedFrameInfo: diff --git a/src/sentry/issues/auto_source_code_config/stacktraces.py b/src/sentry/issues/auto_source_code_config/stacktraces.py index 6065c2596cfe3d..423ef09afc0533 100644 --- a/src/sentry/issues/auto_source_code_config/stacktraces.py +++ b/src/sentry/issues/auto_source_code_config/stacktraces.py @@ -37,9 +37,6 @@ def get_stacktraces(data: NodeData | dict[str, Any]) -> list[dict[str, Any]]: if exceptions: return [e["stacktrace"] for e in exceptions if get_path(e, "stacktrace", "frames")] - stacktrace = data.get("stacktrace") - if stacktrace and stacktrace.get("frames"): - logger.warning("Investigate if we use this code path in production.") - return [stacktrace] - - return [] + # This section is only used as part of the tests + # Ideally, we should fix the tests to pass the correct data + return [data["stacktrace"]] diff --git a/src/sentry/issues/auto_source_code_config/task.py b/src/sentry/issues/auto_source_code_config/task.py index ba284da3436245..4c810fc067ba2d 100644 --- a/src/sentry/issues/auto_source_code_config/task.py +++ b/src/sentry/issues/auto_source_code_config/task.py @@ -65,11 +65,12 @@ def process_event(project_id: int, group_id: int, event_id: str) -> list[CodeMap logger.error("Event not found.", extra=extra) return [] - platform = event.data["platform"] + platform = event.platform + assert platform is not None if not supported_platform(platform): return [] - frames_to_process = get_frames_to_process(event.data, event.platform) + frames_to_process = get_frames_to_process(event.data, platform) if not frames_to_process: return [] @@ -78,7 +79,7 @@ def process_event(project_id: int, group_id: int, event_id: str) -> list[CodeMap installation = get_installation(org) trees = get_trees_for_org(installation, org, extra) trees_helper = CodeMappingTreesHelper(trees) - code_mappings = trees_helper.generate_code_mappings(frames_to_process) + code_mappings = trees_helper.generate_code_mappings(frames_to_process, platform) if platform not in DRY_RUN_PLATFORMS: set_project_codemappings(code_mappings, installation, project, platform) except (InstallationNotFoundError, InstallationCannotGetTreesError): diff --git a/src/sentry/issues/endpoints/organization_derive_code_mappings.py b/src/sentry/issues/endpoints/organization_derive_code_mappings.py index b1ef0d8ab857d4..de008cbb7e2244 100644 --- a/src/sentry/issues/endpoints/organization_derive_code_mappings.py +++ b/src/sentry/issues/endpoints/organization_derive_code_mappings.py @@ -45,10 +45,12 @@ def get(self, request: Request, organization: Organization) -> Response: :param organization: :param string stacktraceFilename: + :param string platform: :auth: required """ - # XXX: Evaluate what else does the UI send us stacktrace_filename = request.GET.get("stacktraceFilename") + # XXX: The UI will need to pass the platform + platform = request.GET.get("platform") try: possible_code_mappings = [] @@ -56,7 +58,7 @@ def get(self, request: Request, organization: Organization) -> Response: if stacktrace_filename: possible_code_mappings = derive_code_mappings( - organization, {"filename": stacktrace_filename} + organization, {"filename": stacktrace_filename}, platform ) if possible_code_mappings: resp_status = status.HTTP_200_OK