test_sourcemap.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import os.path
  2. import pytest
  3. from sentry.models import File, Release, ReleaseFile
  4. from sentry.testutils import RelayStoreHelper, TransactionTestCase
  5. from sentry.testutils.helpers.datetime import before_now, iso_format
  6. from tests.symbolicator import insta_snapshot_javascript_stacktrace_data
  7. # IMPORTANT:
  8. # For these tests to run, write `symbolicator.enabled: true` into your
  9. # `~/.sentry/config.yml` and run `sentry devservices up`
  10. # NOTE:
  11. # Run with `pytest --reuse-db tests/symbolicator/test_sourcemap.py -s` until DB issues are resolved.
  12. def get_fixture_path(name):
  13. return os.path.join(os.path.dirname(__file__), "fixtures", name)
  14. class SymbolicatorSourceMapIntegrationTest(RelayStoreHelper, TransactionTestCase):
  15. @pytest.fixture(autouse=True)
  16. def initialize(self, live_server):
  17. with self.options(
  18. {
  19. "system.internal-url-prefix": live_server.url,
  20. "symbolicator.sourcemaps-processing-sample-rate": 1,
  21. }
  22. ):
  23. # Run test case:
  24. yield
  25. @pytest.mark.skip(
  26. reason="Used for development only until Symbolicator with SourceMaps support is deployed."
  27. )
  28. def test_symbolicator_roundtrip(self):
  29. project = self.project
  30. release_id = "abc"
  31. release = Release.objects.create(
  32. organization_id=project.organization_id, version=release_id
  33. )
  34. release.add_project(project)
  35. for file in ["test.min.js", "test.js", "test.map"]:
  36. with open(get_fixture_path(file), "rb") as f:
  37. f_minified = File.objects.create(
  38. name=file,
  39. type="release.file",
  40. headers={"Content-Type": "application/json"},
  41. )
  42. f_minified.putfile(f)
  43. ReleaseFile.objects.create(
  44. name=f"~/{f_minified.name}",
  45. release_id=release.id,
  46. organization_id=project.organization_id,
  47. file=f_minified,
  48. )
  49. event_data = {
  50. "timestamp": iso_format(before_now(minutes=1)),
  51. "message": "hello",
  52. "platform": "javascript",
  53. "release": release_id,
  54. "exception": {
  55. "values": [
  56. {
  57. "type": "Error",
  58. "stacktrace": {
  59. "frames": [
  60. {
  61. "abs_path": "http://example.com/test.min.js",
  62. "filename": "test.min.js",
  63. "lineno": 1,
  64. "colno": 64,
  65. "function": "e",
  66. },
  67. {
  68. "abs_path": "http://example.com/test.min.js",
  69. "filename": "test.min.js",
  70. "lineno": 1,
  71. "colno": 136,
  72. "function": "r",
  73. },
  74. {
  75. "abs_path": "http://example.com/test.min.js",
  76. "filename": "test.min.js",
  77. "lineno": 1,
  78. "colno": 183,
  79. "function": "i",
  80. },
  81. {
  82. "abs_path": "http://example.com/index.html",
  83. "filename": "index.html",
  84. "lineno": 6,
  85. "colno": 7,
  86. "function": "produceStack",
  87. },
  88. ]
  89. },
  90. },
  91. ]
  92. },
  93. }
  94. event = self.post_and_retrieve_event(event_data)
  95. insta_snapshot_javascript_stacktrace_data(self, event.data)