Browse Source

ref(profiling): add test to check symbolicated field for javascript frames (#68591)

Francesco Vigliaturo 11 months ago
parent
commit
956b5b9c1c

+ 2 - 0
fixtures/profiles/embedded.js

@@ -0,0 +1,2 @@
+function add(a,b){return a+b}function multiply(a,b){return a*b}function divide(a,b){try{return multiply(add(a,b),a,b)/c}catch(e){Raven.captureException(e)}}
+//# sourceMappingURL=embedded.js.map

+ 1 - 0
fixtures/profiles/embedded.js.map

@@ -0,0 +1 @@
+{"version":3,"sources":["file1.js","file2.js"],"names":["add","a","b","multiply","divide","c","e","Raven","captureException"],"mappings":"AAAA,QAASA,KAAIC,EAAGC,GACf,YACA,OAAOD,GAAIC,ECFZ,QAASC,UAASF,EAAGC,GACpB,YACA,OAAOD,GAAIC,EAEZ,QAASE,QAAOH,EAAGC,GAClB,YACA,KACC,MAAOC,UAASH,IAAIC,EAAGC,GAAID,EAAGC,GAAKG,EAClC,MAAOC,GACRC,MAAMC,iBAAiBF","sourcesContent":["function add(a, b) {\n\t\"use strict\";\n\treturn a + b; // fôo\n}\n","function multiply(a, b) {\n\t\"use strict\";\n\treturn a * b;\n}\nfunction divide(a, b) {\n\t\"use strict\";\n\ttry {\n\t\treturn multiply(add(a, b), a, b) / c;\n\t} catch (e) {\n\t\tRaven.captureException(e);\n\t}\n}\n"]}

+ 41 - 0
fixtures/profiles/valid_js_profile.json

@@ -0,0 +1,41 @@
+{
+  "version": "1",
+  "environment": "testing",
+  "event_id": "961d6b96017644db895eafd391682003",
+  "profile_id": "017d59c6a6474ac3bdf59f57f1c451eb",
+  "platform": "javascript",
+  "release": null,
+  "timestamp": "2023-11-01T15:27:15.081230Z",
+  "transaction_id": "9789498b-6970-4dda-b2a1-f9cb91d1a445",
+  "trace_id": "809ff2c0-e185-4c21-8f21-6a6fef009352",
+  "transaction_name": "test_transaction",
+  "profile": {
+    "samples": [
+      {
+        "stack_id": 0,
+        "elapsed_since_start_ns": 1,
+        "thread_id": 1
+      },
+      {
+        "stack_id": 0,
+        "elapsed_since_start_ns": 2,
+        "thread_id": 1
+      }
+    ],
+    "stacks": [
+      [
+        0
+      ]
+    ],
+    "frames": [
+      {
+        "abs_path": "http://example.com/embedded.js",
+        "filename": "file.min.js",
+        "lineno": 1,
+        "colno": 39
+      }
+    ],
+    "thread_metadata": {},
+    "queue_metadata": {}
+  }
+}

+ 41 - 0
tests/sentry/profiles/test_task.py

@@ -11,7 +11,10 @@ from django.core.files.uploadedfile import SimpleUploadedFile
 from django.urls import reverse
 
 from sentry.lang.javascript.processing import _handles_frame as is_valid_javascript_frame
+from sentry.models.files.file import File
 from sentry.models.project import Project
+from sentry.models.release import Release
+from sentry.models.releasefile import ReleaseFile
 from sentry.profiles.task import (
     _calculate_profile_duration_ms,
     _deobfuscate,
@@ -19,6 +22,7 @@ from sentry.profiles.task import (
     _deobfuscate_using_symbolicator,
     _normalize,
     _process_symbolicator_results_for_sample,
+    _symbolicate_profile,
 )
 from sentry.testutils.cases import TransactionTestCase
 from sentry.testutils.factories import Factories, get_fixture_path
@@ -824,3 +828,40 @@ class DeobfuscationViaSymbolicator(TransactionTestCase):
                 "source_line": 40,
             },
         ]
+
+    @requires_symbolicator
+    @pytest.mark.symbolicator
+    def test_js_symbolication_set_symbolicated_field(self):
+        release = Release.objects.create(
+            organization_id=self.project.organization_id, version="nodeprof123"
+        )
+        release.add_project(self.project)
+
+        for file in ["embedded.js", "embedded.js.map"]:
+            with open(get_fixture_path(f"profiles/{file}"), "rb") as f:
+                f1 = File.objects.create(
+                    name=file,
+                    type="release.file",
+                    headers={},
+                )
+                f1.putfile(f)
+
+            ReleaseFile.objects.create(
+                name=f"http://example.com/{f1.name}",
+                release_id=release.id,
+                organization_id=self.project.organization_id,
+                file=f1,
+            )
+
+        js_profile = load_profile("valid_js_profile.json")
+        js_profile.update(
+            {
+                "project_id": self.project.id,
+                "event_id": js_profile["profile_id"],
+                "release": release.version,
+                "debug_meta": {"images": []},
+            }
+        )
+
+        _symbolicate_profile(js_profile, self.project)
+        assert js_profile["profile"]["frames"][0].get("data", {}).get("symbolicated", False)