Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations: Add support for sample events in Sentry Integration.

Satyam Bansal16563a32172f
diff --git a/zerver/webhooks/sentry/fixtures/sample_event.json b/zerver/webhooks/sentry/fixtures/sample_event.json
new file mode 100644
index 00000000000..44f52f90bda
--- /dev/null
+++ b/zerver/webhooks/sentry/fixtures/sample_event.json
@@ -0,0 +1,479 @@
+{
+ "action": "triggered",
+ "installation": {
+ "uuid": "be1b14f8-ffad-41af-8e97-24a9c32ebc26"
+ },
+ "data": {
+ "event": {
+ "event_id": "b6eff1a49b1f4132850b1238d968da70",
+ "project": 4505278293147648,
+ "release": null,
+ "dist": null,
+ "platform": "python",
+ "message": "This is an example Python exception",
+ "datetime": "2023-05-31T11:06:16.247000Z",
+ "tags": [
+ [
+ "browser",
+ "Chrome 28.0.1500"
+ ],
+ [
+ "browser.name",
+ "Chrome"
+ ],
+ [
+ "client_os",
+ "Windows 8"
+ ],
+ [
+ "client_os.name",
+ "Windows"
+ ],
+ [
+ "environment",
+ "prod"
+ ],
+ [
+ "level",
+ "error"
+ ],
+ [
+ "sample_event",
+ "yes"
+ ],
+ [
+ "user",
+ "id:1"
+ ],
+ [
+ "server_name",
+ "web01.example.org"
+ ],
+ [
+ "url",
+ "http://example.com/foo"
+ ]
+ ],
+ "_metrics": {
+ "bytes.stored.event": 8070
+ },
+ "_ref": 4505278293147648,
+ "_ref_version": 2,
+ "contexts": {
+ "browser": {
+ "name": "Chrome",
+ "version": "28.0.1500",
+ "type": "browser"
+ },
+ "client_os": {
+ "name": "Windows",
+ "version": "8",
+ "type": "os"
+ }
+ },
+ "culprit": "raven.scripts.runner in main",
+ "environment": "prod",
+ "extra": {
+ "emptyList": [],
+ "emptyMap": {},
+ "length": 10837790,
+ "results": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ ],
+ "session": {
+ "foo": "bar"
+ },
+ "unauthorized": false,
+ "url": "http://example.org/foo/bar/"
+ },
+ "fingerprint": [
+ "{{ default }}"
+ ],
+ "hashes": [
+ "3a2b45089d0211943e5a6645fb4cea3f"
+ ],
+ "level": "error",
+ "location": null,
+ "logentry": {
+ "formatted": "This is an example Python exception",
+ "message": null,
+ "params": null
+ },
+ "logger": "",
+ "metadata": {
+ "title": "This is an example Python exception"
+ },
+ "modules": {
+ "my.package": "1.0.0"
+ },
+ "nodestore_insert": 1685531237.009953,
+ "received": 1685531236.249363,
+ "request": {
+ "url": "http://example.com/foo",
+ "method": "GET",
+ "data": {
+ "hello": "world"
+ },
+ "query_string": [
+ [
+ "foo",
+ "bar"
+ ]
+ ],
+ "cookies": [
+ [
+ "foo",
+ "bar"
+ ],
+ [
+ "biz",
+ "baz"
+ ]
+ ],
+ "headers": [
+ [
+ "Content-Type",
+ "application/json"
+ ],
+ [
+ "Referer",
+ "http://example.com"
+ ],
+ [
+ "User-Agent",
+ "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
+ ]
+ ],
+ "env": {
+ "ENV": "prod"
+ },
+ "inferred_content_type": "application/json",
+ "fragment": null
+ },
+ "stacktrace": {
+ "frames": [
+ {
+ "function": "build_msg",
+ "module": "raven.base",
+ "filename": "raven/base.py",
+ "abs_path": "/home/ubuntu/.virtualenvs/getsentry/src/raven/raven/base.py",
+ "lineno": 303,
+ "pre_context": [
+ " frames = stack",
+ "",
+ " data.update({",
+ " 'sentry.interfaces.Stacktrace': {",
+ " 'frames': get_stack_info(frames,"
+ ],
+ "context_line": " transformer=self.transform)",
+ "post_context": [
+ " },",
+ " })",
+ "",
+ " if 'sentry.interfaces.Stacktrace' in data:",
+ " if self.include_paths:"
+ ],
+ "in_app": false,
+ "vars": {
+ "'culprit'": null,
+ "'data'": {
+ "'message'": "u'This is a test message generated using ``raven test``'",
+ "'sentry.interfaces.Message'": {
+ "'message'": "u'This is a test message generated using ``raven test``'",
+ "'params'": []
+ }
+ },
+ "'date'": "datetime.datetime(2013, 8, 13, 3, 8, 24, 880386)",
+ "'event_id'": "'54a322436e1b47b88e239b78998ae742'",
+ "'event_type'": "'raven.events.Message'",
+ "'extra'": {
+ "'go_deeper'": [
+ [
+ "{\"'bar'\":[\"'baz'\"],\"'foo'\":\"'bar'\"}"
+ ]
+ ],
+ "'loadavg'": [
+ 0.37255859375,
+ 0.5341796875,
+ 0.62939453125
+ ],
+ "'user'": "'dcramer'"
+ },
+ "'frames'": "<generator object iter_stack_frames at 0x107bcc3c0>",
+ "'handler'": "<raven.events.Message object at 0x107bd0890>",
+ "'k'": "'sentry.interfaces.Message'",
+ "'kwargs'": {
+ "'level'": 20,
+ "'message'": "'This is a test message generated using ``raven test``'"
+ },
+ "'public_key'": null,
+ "'result'": {
+ "'message'": "u'This is a test message generated using ``raven test``'",
+ "'sentry.interfaces.Message'": {
+ "'message'": "u'This is a test message generated using ``raven test``'",
+ "'params'": []
+ }
+ },
+ "'self'": "<raven.base.Client object at 0x107bb8210>",
+ "'stack'": true,
+ "'tags'": null,
+ "'time_spent'": null,
+ "'v'": {
+ "'message'": "u'This is a test message generated using ``raven test``'",
+ "'params'": []
+ }
+ },
+ "colno": null,
+ "data": null,
+ "errors": null,
+ "raw_function": null,
+ "image_addr": null,
+ "instruction_addr": null,
+ "addr_mode": null,
+ "package": null,
+ "platform": null,
+ "symbol": null,
+ "symbol_addr": null,
+ "trust": null,
+ "snapshot": null
+ },
+ {
+ "function": "capture",
+ "module": "raven.base",
+ "filename": "raven/base.py",
+ "abs_path": "/home/ubuntu/.virtualenvs/getsentry/src/raven/raven/base.py",
+ "lineno": 459,
+ "pre_context": [
+ " if not self.is_enabled():",
+ " return",
+ "",
+ " data = self.build_msg(",
+ " event_type, data, date, time_spent, extra, stack, tags=tags,"
+ ],
+ "context_line": " **kwargs)",
+ "post_context": [
+ "",
+ " self.send(**data)",
+ "",
+ " return (data.get('event_id'),)",
+ ""
+ ],
+ "in_app": false,
+ "vars": {
+ "'data'": null,
+ "'date'": null,
+ "'event_type'": "'raven.events.Message'",
+ "'extra'": {
+ "'go_deeper'": [
+ [
+ "{\"'bar'\":[\"'baz'\"],\"'foo'\":\"'bar'\"}"
+ ]
+ ],
+ "'loadavg'": [
+ 0.37255859375,
+ 0.5341796875,
+ 0.62939453125
+ ],
+ "'user'": "'dcramer'"
+ },
+ "'kwargs'": {
+ "'level'": 20,
+ "'message'": "'This is a test message generated using ``raven test``'"
+ },
+ "'self'": "<raven.base.Client object at 0x107bb8210>",
+ "'stack'": true,
+ "'tags'": null,
+ "'time_spent'": null
+ },
+ "colno": null,
+ "data": null,
+ "errors": null,
+ "raw_function": null,
+ "image_addr": null,
+ "instruction_addr": null,
+ "addr_mode": null,
+ "package": null,
+ "platform": null,
+ "symbol": null,
+ "symbol_addr": null,
+ "trust": null,
+ "snapshot": null
+ },
+ {
+ "function": "captureMessage",
+ "module": "raven.base",
+ "filename": "raven/base.py",
+ "abs_path": "/home/ubuntu/.virtualenvs/getsentry/src/raven/raven/base.py",
+ "lineno": 577,
+ "pre_context": [
+ " \"\"\"",
+ " Creates an event from ``message``.",
+ "",
+ " >>> client.captureMessage('My event just happened!')",
+ " \"\"\""
+ ],
+ "context_line": " return self.capture('raven.events.Message', message=message, **kwargs)",
+ "post_context": [
+ "",
+ " def captureException(self, exc_info=None, **kwargs):",
+ " \"\"\"",
+ " Creates an event from an exception.",
+ ""
+ ],
+ "in_app": false,
+ "vars": {
+ "'kwargs'": {
+ "'data'": null,
+ "'extra'": {
+ "'go_deeper'": [
+ "[{\"'bar'\":[\"'baz'\"],\"'foo'\":\"'bar'\"}]"
+ ],
+ "'loadavg'": [
+ 0.37255859375,
+ 0.5341796875,
+ 0.62939453125
+ ],
+ "'user'": "'dcramer'"
+ },
+ "'level'": 20,
+ "'stack'": true,
+ "'tags'": null
+ },
+ "'message'": "'This is a test message generated using ``raven test``'",
+ "'self'": "<raven.base.Client object at 0x107bb8210>"
+ },
+ "colno": null,
+ "data": null,
+ "errors": null,
+ "raw_function": null,
+ "image_addr": null,
+ "instruction_addr": null,
+ "addr_mode": null,
+ "package": null,
+ "platform": null,
+ "symbol": null,
+ "symbol_addr": null,
+ "trust": null,
+ "snapshot": null
+ },
+ {
+ "function": "send_test_message",
+ "module": "raven.scripts.runner",
+ "filename": "raven/scripts/runner.py",
+ "abs_path": "/home/ubuntu/.virtualenvs/getsentry/src/raven/raven/scripts/runner.py",
+ "lineno": 77,
+ "pre_context": [
+ " level=logging.INFO,",
+ " stack=True,",
+ " tags=options.get('tags', {}),",
+ " extra={",
+ " 'user': get_uid(),"
+ ],
+ "context_line": " 'loadavg': get_loadavg(),",
+ "post_context": [
+ " },",
+ " ))",
+ "",
+ " if client.state.did_fail():",
+ " print('error!')"
+ ],
+ "in_app": false,
+ "vars": {
+ "'client'": "<raven.base.Client object at 0x107bb8210>",
+ "'data'": null,
+ "'k'": "'secret_key'",
+ "'options'": {
+ "'data'": null,
+ "'tags'": null
+ }
+ },
+ "colno": null,
+ "data": null,
+ "errors": null,
+ "raw_function": null,
+ "image_addr": null,
+ "instruction_addr": null,
+ "addr_mode": null,
+ "package": null,
+ "platform": null,
+ "symbol": null,
+ "symbol_addr": null,
+ "trust": null,
+ "snapshot": null
+ },
+ {
+ "function": "main",
+ "module": "raven.scripts.runner",
+ "filename": "raven/scripts/runner.py",
+ "abs_path": "/home/ubuntu/.virtualenvs/getsentry/src/raven/raven/scripts/runner.py",
+ "lineno": 112,
+ "pre_context": [
+ " print(\"Using DSN configuration:\")",
+ " print(\" \", dsn)",
+ " print()",
+ "",
+ " client = Client(dsn, include_paths=['raven'])"
+ ],
+ "context_line": " send_test_message(client, opts.__dict__)",
+ "in_app": false,
+ "vars": {
+ "'args'": [
+ "'test'",
+ "'https://ebc35f33e151401f9deac549978bda11:[email protected]/1'"
+ ],
+ "'client'": "<raven.base.Client object at 0x107bb8210>",
+ "'dsn'": "'https://ebc35f33e151401f9deac549978bda11:[email protected]/1'",
+ "'opts'": "<Values at 0x107ba3b00: {'data': None, 'tags': None}>",
+ "'parser'": "<optparse.OptionParser instance at 0x107ba3368>",
+ "'root'": "<logging.Logger object at 0x107ba5b10>"
+ },
+ "colno": null,
+ "data": null,
+ "errors": null,
+ "raw_function": null,
+ "image_addr": null,
+ "instruction_addr": null,
+ "addr_mode": null,
+ "package": null,
+ "platform": null,
+ "post_context": null,
+ "symbol": null,
+ "symbol_addr": null,
+ "trust": null,
+ "snapshot": null
+ }
+ ]
+ },
+ "timestamp": 1685531176.247,
+ "title": "This is an example Python exception",
+ "type": "default",
+ "user": {
+ "id": "1",
+ "email": "[email protected]",
+ "ip_address": "127.0.0.1",
+ "username": "sentry",
+ "name": "Sentry",
+ "geo": {
+ "country_code": "AU",
+ "city": "Melbourne",
+ "region": "VIC"
+ }
+ },
+ "version": "5",
+ "url": "https://sentry.io/api/0/projects/nitk-46/python/events/b6eff1a49b1f4132850b1238d968da70/",
+ "web_url": "https://sentry.io/organizations/nitk-46/issues/4218258981/events/b6eff1a49b1f4132850b1238d968da70/",
+ "issue_url": "https://sentry.io/api/0/issues/4218258981/",
+ "issue_id": "4218258981"
+ },
+ "triggered_rule": ""
+ },
+ "actor": {
+ "type": "application",
+ "id": "sentry",
+ "name": "Sentry"
+ }
+}
diff --git a/zerver/webhooks/sentry/tests.py b/zerver/webhooks/sentry/tests.py
index c32265038de..22d886eeff7 100644
--- a/zerver/webhooks/sentry/tests.py
+++ b/zerver/webhooks/sentry/tests.py
@@ -250,3 +250,13 @@ New [issue](https://sentry.io/zulip/zulip/issues/156699934/) (level: ERROR):
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)
diff --git a/zerver/webhooks/sentry/view.py b/zerver/webhooks/sentry/view.py
index 144f1314da8..bbe924949dc 100644
--- a/zerver/webhooks/sentry/view.py
+++ b/zerver/webhooks/sentry/view.py
@@ -104,7 +104,11 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
# We shouldn't support the officially deprecated Raven series of
# Python SDKs.
if platform_name == "python" and int(event["version"]) < 7:
- raise UnsupportedWebhookEventTypeError("Raven SDK")
+ # 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"],