Repository: zulip/zulip

Issue:
Support more sources of Sentry exceptions
We currently support some of the Sentry backends:
https://github.com/zulip/zulip/blob/03a0a7abc65a572655d8c0e235fc8a622ce22932/zerver/webhooks/sentry/view.py#L73-L80

We should add support for more of them, like Vue and Rails.  As part of this, we should probably limit the `version` check:
https://github.com/zulip/zulip/blob/03a0a7abc65a572655d8c0e235fc8a622ce22932/zerver/webhooks/sentry/view.py#L96-L98
...to only Python, since other platforms don't seem to include it.

Sentry exception payloads are not standardized, so doing this will probably require building some toy applications in each of the platforms (the Sentry docs probably provide examples) to capture fixtures of the current payloads.


Discussion:
Hello @zulip/server-integrations members, this issue was labeled with the "area: integrations" label, so you may want to check it out!

<!-- areaLabelAddition -->

Thanks for assigning this issue to me. :heart_decoration: 

I will look into this and will try to fix this as soon as possible.

Resolving patch:
diff --git a/zerver/webhooks/sentry/view.py b/zerver/webhooks/sentry/view.py
--- a/zerver/webhooks/sentry/view.py
+++ b/zerver/webhooks/sentry/view.py
@@ -77,6 +77,7 @@
     "javascript": "javascript",
     "node": "javascript",
     "python": "python3",
+    "ruby": "ruby",
 }
 
 
@@ -93,9 +94,6 @@ def convert_lines_to_traceback_string(lines: Optional[List[str]]) -> str:
 
 def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
     """Handle either an exception type event or a message type event payload."""
-    # We shouldn't support the officially deprecated Raven series of SDKs.
-    if int(event["version"]) < 7:
-        raise UnsupportedWebhookEventTypeError("Raven SDK")
 
     subject = event["title"]
     platform_name = event["platform"]
@@ -103,6 +101,14 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
     if syntax_highlight_as == "":  # nocoverage
         logging.info("Unknown Sentry platform: %s", platform_name)
 
+    # We shouldn't support the officially deprecated Raven series of
+    # Python SDKs.
+    if platform_name == "python" and int(event["version"]) < 7:
+        # The sample event is still an old "version" -- accept it even
+        # though we don't accept events from the old Python SDK.
+        tags = event.get("tags", [])
+        if ["sample_event", "yes"] not in tags:
+            raise UnsupportedWebhookEventTypeError("Raven SDK")
     context = {
         "title": subject,
         "level": event["level"],


Test patch:
diff --git a/zerver/webhooks/sentry/tests.py b/zerver/webhooks/sentry/tests.py
--- a/zerver/webhooks/sentry/tests.py
+++ b/zerver/webhooks/sentry/tests.py
@@ -82,6 +82,46 @@ def test_event_for_exception_python(self) -> None:
 ```"""
         self.check_webhook("event_for_exception_python", expected_topic, expected_message)
 
+    def test_event_for_exception_rails(self) -> None:
+        expected_topic = "ZeroDivisionError: divided by 0"
+        expected_message = """\
+**New exception:** [ZeroDivisionError: divided by 0](https://sentry.io/organizations/nitk-46/issues/4213933362/events/49b528e13e45497ab9adc3173fd2ed34/)
+```quote
+**level:** error
+**timestamp:** 2023-05-29 10:12:33
+**filename:** app/controllers/articles_controller.rb
+```
+
+Traceback:
+```ruby
+     class ArticlesController < ApplicationController
+
+       def index
+
+         begin
+
+--->       132312 / 0
+
+         rescue ZeroDivisionError => exception
+
+           Sentry.capture_exception(exception)
+
+         end
+
+```"""
+        self.check_webhook("event_for_exception_rails", expected_topic, expected_message)
+
+    def test_event_for_exception_vue(self) -> None:
+        expected_topic = "TypeError: Cannot read properties of null (reading 'inser..."
+        expected_message = """\
+**New exception:** [TypeError: Cannot read properties of null (reading 'insertBefore')](https://sentry.io/organizations/nitk-46/issues/4214010673/events/292f78454e774e62999506f759ad791d/)
+```quote
+**level:** error
+**timestamp:** 2023-05-29 11:08:30
+**filename:** /node_modules/.vite/deps/chunk-G4DFXOZZ.js
+```"""
+        self.check_webhook("event_for_exception_vue", expected_topic, expected_message)
+
     def test_webhook_event_for_exception_python(self) -> None:
         expected_topic = "ValueError: new sentry error."
         expected_message = """\
@@ -210,3 +250,13 @@ def test_deprecated_exception_message(self) -> None:
 This is an example python exception
 ```"""
         self.check_webhook("deprecated_exception_message", expected_topic, expected_message)
+
+    def test_sample_event(self) -> None:
+        expected_topic = "This is an example Python exception"
+        expected_message = """\
+**New message event:** [This is an example Python exception](https://sentry.io/organizations/nitk-46/issues/4218258981/events/b6eff1a49b1f4132850b1238d968da70/)
+```quote
+**level:** error
+**timestamp:** 2023-05-31 11:06:16
+```"""
+        self.check_webhook("sample_event", expected_topic, expected_message)