Browse Source

ref(stacktrace-link): Add automatically generated to the serializer (#43104)

This is one of a series of small improvements to the code.
Armen Zambrano G 2 years ago
parent
commit
78f53abf41

+ 5 - 7
src/sentry/api/endpoints/project_stacktrace_link.py

@@ -196,7 +196,6 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):  # type: ignore
         except Exception:
             logger.exception("There was a failure sorting the code mappings")
 
-        derived = False
         current_config = None
         with configure_scope() as scope:
             set_top_tags(scope, project, ctx, len(configs) > 0)
@@ -206,11 +205,6 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):  # type: ignore
                     # Later on, if there are matching code mappings this will be overwritten
                     result["error"] = "stack_root_mismatch"
                     continue
-                if (
-                    filepath.startswith(config.stack_root)
-                    and config.automatically_generated is True
-                ):
-                    derived = True
 
                 outcome = {}
                 munging_outcome = {}
@@ -233,6 +227,7 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):  # type: ignore
                     scope.set_tag("stacktrace_link.munged", True)
 
                 current_config = {"config": serialize(config, request.user), "outcome": outcome}
+
                 # use the provider key to be able to split up stacktrace
                 # link metrics by integration type
                 provider = current_config["config"]["provider"]["key"]
@@ -246,11 +241,14 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):  # type: ignore
             # Post-processing before exiting scope context
             found: bool = result["sourceUrl"] is not None
             scope.set_tag("stacktrace_link.found", found)
-            scope.set_tag("stacktrace_link.auto_derived", derived)
             scope.set_tag("stacktrace_link.source_url", result.get("sourceUrl"))
             scope.set_tag("stacktrace_link.tried_url", result.get("attemptedUrl"))
             if current_config:
                 result["config"] = current_config["config"]
+                scope.set_tag(
+                    "stacktrace_link.auto_derived",
+                    result["config"]["automaticallyGenerated"] is True,
+                )
                 scope.set_tag("stacktrace_link.empty_root", result["config"]["stackRoot"] == "")
                 if not found:
                     result["error"] = current_config["outcome"]["error"]

+ 1 - 0
src/sentry/api/serializers/models/repository_project_path_config.py

@@ -24,4 +24,5 @@ class RepositoryProjectPathConfigSerializer(Serializer):
             "stackRoot": obj.stack_root,
             "sourceRoot": obj.source_root,
             "defaultBranch": obj.default_branch,
+            "automaticallyGenerated": obj.automatically_generated,
         }

+ 4 - 0
tests/sentry/api/endpoints/test_organization_code_mappings.py

@@ -73,6 +73,7 @@ class OrganizationCodeMappingsTest(APITestCase):
         assert response.status_code == 200, response.content
 
         assert response.data[0] == {
+            "automaticallyGenerated": False,
             "id": str(path_config1.id),
             "projectId": str(self.project1.id),
             "projectSlug": self.project1.slug,
@@ -94,6 +95,7 @@ class OrganizationCodeMappingsTest(APITestCase):
         }
 
         assert response.data[1] == {
+            "automaticallyGenerated": False,
             "id": str(path_config2.id),
             "projectId": str(self.project2.id),
             "projectSlug": self.project2.slug,
@@ -129,6 +131,7 @@ class OrganizationCodeMappingsTest(APITestCase):
         assert response.status_code == 200, response.content
 
         assert response.data[0] == {
+            "automaticallyGenerated": False,
             "id": str(path_config1.id),
             "projectId": str(self.project1.id),
             "projectSlug": self.project1.slug,
@@ -212,6 +215,7 @@ class OrganizationCodeMappingsTest(APITestCase):
         response = self.make_post()
         assert response.status_code == 201, response.content
         assert response.data == {
+            "automaticallyGenerated": False,
             "id": str(response.data["id"]),
             "projectId": str(self.project1.id),
             "projectSlug": self.project1.slug,

+ 1 - 0
tests/sentry/api/endpoints/test_organization_derive_code_mappings.py

@@ -103,6 +103,7 @@ class OrganizationDeriveCodeMappingsTest(APITestCase):
         repo = Repository.objects.get(name="getsentry/codemap")
         assert response.status_code == 201, response.content
         assert response.data == {
+            "automaticallyGenerated": True,
             "id": str(response.data["id"]),
             "projectId": str(self.project.id),
             "projectSlug": self.project.slug,

+ 1 - 0
tests/sentry/api/endpoints/test_project_stacktrace_link.py

@@ -57,6 +57,7 @@ class BaseProjectStacktraceLink(APITestCase):
 
     def expected_configurations(self, code_mapping) -> Mapping[str, Any]:
         return {
+            "automaticallyGenerated": code_mapping.automatically_generated,
             "defaultBranch": "master",
             "id": str(code_mapping.id),
             "integrationId": str(self.integration.id),