Browse Source

Fixes #14 logging event support

David Burke 4 years ago
parent
commit
c0ce33d09c

+ 1 - 0
event_store/serializers.py

@@ -17,6 +17,7 @@ class StoreDefaultSerializer(serializers.Serializer):
     event_id = serializers.UUIDField()
     extra = serializers.JSONField(required=False)
     level = serializers.CharField()
+    logentry = serializers.JSONField(required=False)
     message = serializers.CharField(required=False)
     platform = serializers.CharField()
     release = serializers.CharField(required=False)

+ 80 - 0
event_store/test_data/incoming_events/python_logging.json

@@ -0,0 +1,80 @@
+{
+  "level": "warning",
+  "logger": "errors.views",
+  "logentry": { "message": "This is a warning", "params": [] },
+  "extra": { "sys.argv": ["./manage.py", "runserver", "0.0.0.0:8001"] },
+  "event_id": "78d24ed7495c46fc8dbde72c1f20679b",
+  "timestamp": "2020-04-24T18:23:02.950832Z",
+  "breadcrumbs": [],
+  "transaction": "/warning/",
+  "contexts": {
+    "trace": {
+      "trace_id": "1022e5e9d8e44d2ebafddfa839b58c5f",
+      "span_id": "9d329137b651e5ce",
+      "parent_span_id": "b18a82b300d6699d",
+      "op": "django.middleware",
+      "description": "django.middleware.clickjacking.XFrameOptionsMiddleware.__call__"
+    },
+    "runtime": {
+      "name": "CPython",
+      "version": "3.8.2",
+      "build": "3.8.2 (default, Feb 26 2020, 15:09:34) \n[GCC 8.3.0]"
+    }
+  },
+  "modules": {
+    "wheel": "0.34.2",
+    "webencodings": "0.5.1",
+    "wcwidth": "0.1.8",
+    "urllib3": "1.25.8",
+    "typed-ast": "1.4.1",
+    "traitlets": "4.3.3",
+    "tomlkit": "0.5.11",
+    "toml": "0.10.0",
+    "sqlparse": "0.3.1",
+    "six": "1.14.0",
+    "appdirs": "1.4.3"
+  },
+  "request": {
+    "url": "http://localhost:8001/warning/",
+    "query_string": "",
+    "method": "GET",
+    "env": { "SERVER_NAME": "5949a3cc0cd4", "SERVER_PORT": "8001" },
+    "headers": {
+      "Content-Length": "",
+      "Content-Type": "text/plain",
+      "Host": "localhost:8001",
+      "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0",
+      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
+      "Accept-Language": "en-US,en;q=0.5",
+      "Accept-Encoding": "gzip, deflate",
+      "Referer": "http://localhost:8001/",
+      "Connection": "keep-alive",
+      "Cookie": "",
+      "Upgrade-Insecure-Requests": "1",
+      "Cache-Control": "max-age=0"
+    }
+  },
+  "server_name": "5949a3cc0cd4",
+  "sdk": {
+    "name": "sentry.python",
+    "version": "0.14.2",
+    "packages": [{ "name": "pypi:sentry-sdk", "version": "0.14.2" }],
+    "integrations": [
+      "argv",
+      "atexit",
+      "dedupe",
+      "django",
+      "excepthook",
+      "logging",
+      "modules",
+      "stdlib",
+      "threading"
+    ]
+  },
+  "platform": "python",
+  "_meta": {
+    "request": {
+      "headers": { "Cookie": { "": { "rem": [["!config", "x", 0, 1110]] } } }
+    }
+  }
+}

+ 1 - 1
event_store/test_data/oss_sentry_events/dotnet_error.json

@@ -2,7 +2,7 @@
   "eventID": "8a4042d4de914977a966a0106f2e03bd",
   "dist": null,
   "userReport": null,
-  "projectID": "3",
+  "projectID": "1",
   "previousEventID": null,
   "message": "An unhandled exception has occurred while executing the request.",
   "id": "2050",

+ 120 - 0
event_store/test_data/oss_sentry_events/python_logging.json

@@ -0,0 +1,120 @@
+{
+  "eventID": "78d24ed7495c46fc8dbde72c1f20679b",
+  "dist": null,
+  "userReport": null,
+  "projectID": "1",
+  "previousEventID": null,
+  "message": "This is a warning",
+  "id": "2087",
+  "size": 2436,
+  "errors": [],
+  "culprit": "/warning/",
+  "title": "This is a warning",
+  "platform": "python",
+  "location": null,
+  "nextEventID": null,
+  "type": "default",
+  "metadata": { "title": "This is a warning" },
+  "groupingConfig": { "id": "legacy:2019-03-12" },
+  "crashFile": null,
+  "tags": [
+    { "value": "Firefox 75.0", "key": "browser", "_meta": null },
+    { "value": "Firefox", "key": "browser.name", "_meta": null },
+    { "value": "warning", "key": "level", "_meta": null },
+    { "value": "errors.views", "key": "logger", "_meta": null },
+    { "value": "Ubuntu", "key": "os.name", "_meta": null },
+    { "value": "CPython 3.8.2", "key": "runtime", "_meta": null },
+    { "value": "CPython", "key": "runtime.name", "_meta": null },
+    { "value": "5949a3cc0cd4", "key": "server_name", "_meta": null },
+    { "value": "/warning/", "key": "transaction", "_meta": null },
+    { "value": "http://localhost:8001/warning/", "key": "url", "_meta": null }
+  ],
+  "dateCreated": "2020-04-24T18:23:02.951Z",
+  "dateReceived": "2020-04-24T18:25:05.149Z",
+  "user": null,
+  "entries": [
+    { "type": "message", "data": { "formatted": "This is a warning" } },
+    {
+      "type": "request",
+      "data": {
+        "fragment": "",
+        "cookies": [],
+        "inferredContentType": "text/plain",
+        "env": { "SERVER_NAME": "5949a3cc0cd4", "SERVER_PORT": "8001" },
+        "headers": [
+          [
+            "Accept",
+            "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
+          ],
+          ["Accept-Encoding", "gzip, deflate"],
+          ["Accept-Language", "en-US,en;q=0.5"],
+          ["Cache-Control", "max-age=0"],
+          ["Connection", "keep-alive"],
+          ["Content-Length", ""],
+          ["Content-Type", "text/plain"],
+          ["Host", "localhost:8001"],
+          ["Referer", "http://localhost:8001/"],
+          ["Upgrade-Insecure-Requests", "1"],
+          [
+            "User-Agent",
+            "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0"
+          ]
+        ],
+        "url": "http://localhost:8001/warning/",
+        "query": [],
+        "data": null,
+        "method": "GET"
+      }
+    }
+  ],
+  "packages": {
+    "wheel": "0.34.2",
+    "sqlparse": "0.3.1",
+    "typed-ast": "1.4.1",
+    "six": "1.14.0",
+    "urllib3": "1.25.8",
+    "wcwidth": "0.1.8",
+    "traitlets": "4.3.3",
+    "toml": "0.10.0",
+    "webencodings": "0.5.1",
+    "tomlkit": "0.5.11",
+    "appdirs": "1.4.3"
+  },
+  "sdk": {
+    "version": "0.14.2",
+    "name": "sentry.python",
+    "upstream": { "url": null, "isNewer": false, "name": "sentry.python" }
+  },
+  "_meta": {
+    "user": null,
+    "context": null,
+    "entries": {},
+    "contexts": null,
+    "message": null,
+    "packages": null,
+    "tags": {},
+    "sdk": null
+  },
+  "contexts": {
+    "runtime": {
+      "version": "3.8.2",
+      "type": "runtime",
+      "build": "3.8.2 (default, Feb 26 2020, 15:09:34) \n[GCC 8.3.0]",
+      "name": "CPython"
+    },
+    "os": { "type": "os", "name": "Ubuntu" },
+    "trace": {
+      "description": "django.middleware.clickjacking.XFrameOptionsMiddleware.__call__",
+      "parent_span_id": "b18a82b300d6699d",
+      "trace_id": "1022e5e9d8e44d2ebafddfa839b58c5f",
+      "span_id": "9d329137b651e5ce",
+      "type": "default",
+      "op": "django.middleware"
+    },
+    "browser": { "version": "75.0", "type": "browser", "name": "Firefox" }
+  },
+  "fingerprints": ["6f8498b9fd52b3c93a8a4672aac43e76"],
+  "context": { "sys.argv": ["./manage.py", "runserver", "0.0.0.0:8001"] },
+  "release": null,
+  "groupID": "56"
+}

+ 22 - 0
issues/tests/test_sentry_api_compat.py

@@ -177,3 +177,25 @@ class SentryAPICompatTestCase(APITestCase):
             data,
             ["title", "culprit", "type", "metadata", "platform", "packages"],
         )
+
+    def test_python_logging(self):
+        """ Test Sentry SDK logging integration based event """
+        sdk_error = self.get_json_data(
+            "event_store/test_data/incoming_events/python_logging.json"
+        )
+        res = self.client.post(self.event_store_url, sdk_error, format="json")
+        self.assertEqual(res.status_code, 200)
+        self.assertEqual(Event.objects.count(), 1)
+        event_id = res.data["id"]
+
+        sentry_data = self.get_json_data(
+            "event_store/test_data/oss_sentry_events/python_logging.json"
+        )
+        url = self.get_project_events_detail(event_id)
+        res = self.client.get(url)
+        self.assertEqual(res.status_code, 200)
+        self.assertCompareData(
+            res.data,
+            sentry_data,
+            ["title", "culprit", "type", "metadata", "platform", "packages"],
+        )

+ 5 - 1
sentry/eventtypes/base.py

@@ -21,7 +21,11 @@ class DefaultEvent(BaseEvent):
     key = "default"
 
     def get_metadata(self, data):
-        message = strip(get_path(data, "message"))
+        message = strip(
+            get_path(data, "logentry", "formatted")
+            or get_path(data, "logentry", "message")
+            or get_path(data, "message")
+        )
 
         if message:
             title = truncatechars(message.splitlines()[0], 100)