The ugliest thing that could get a stacktrace on screen

This commit is contained in:
Klaas van Schelven
2023-11-04 21:02:04 +01:00
parent 8657e82aee
commit 1a5bf7d56c
19 changed files with 105 additions and 1 deletions

0
events/__init__.py Normal file
View File

3
events/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
events/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class EventsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'events'

View File

3
events/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@@ -0,0 +1,34 @@
<html>
{% for exception in exceptions %}
<h1>{{ exception.type }}: {{ exception.value }}</h1>
<b>{{ parsed_data.request.url }}</b><br>
{% for frame in exception.stacktrace.frames %}
<p>
<br>
<b>{{ frame.filename }} line {{ frame.lineno }}, in {{ frame.function }}.</b><br>
<pre>
{% for line in frame.pre_context %}{{ line }}
{% endfor %}<b>{{ frame.context_line }}</b>
{% for line in frame.post_context %}{{ line }}
{% endfor %}
</pre>
{% for var, value in frame.vars.items %}
<b>{{ var }}</b>: <i>{{ value }}</i></br>
{% endfor %}
</p>
{% endfor %}
{% if not forloop.last %}While handling the above exception, yad yad<br>{% endif %}
{% endfor %}
</html>

3
events/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

8
events/urls.py Normal file
View File

@@ -0,0 +1,8 @@
from django.urls import path
from .views import decompressed_event_detail
urlpatterns = [
path('event/<uuid:pk>/', decompressed_event_detail),
]

21
events/views.py Normal file
View File

@@ -0,0 +1,21 @@
import json
from django.shortcuts import render, get_object_or_404
from ingest.models import DecompressedEvent
def decompressed_event_detail(request, pk):
# this view is misplaced "by nature" (it mixes ingested stuff and rendering); until we create a pipeline for that.
obj = get_object_or_404(DecompressedEvent, pk=pk)
parsed_data = json.loads(obj.data)
# NOTE: instead of values, this may also just be a flat list; TODO implement this
exceptions = parsed_data["exception"]["values"]
return render(request, "events/event_detail.html", {
"obj": obj,
"parsed_data": parsed_data,
"exceptions": exceptions,
})

View File

@@ -11,3 +11,7 @@ class DecompressedEvent(models.Model):
project = models.ForeignKey(Project, blank=False, null=True, on_delete=models.SET_NULL) # SET_NULL: cleanup 'later'
data = models.TextField(blank=False, null=False)
timestamp = models.DateTimeField(null=False, auto_now_add=True, help_text="Server-side timestamp")
def get_absolute_url(self):
# same note about misplacement as the view this is pointing to
return "/events/event/%s/" % self.id

0
issues/__init__.py Normal file
View File

3
issues/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
issues/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class IssuesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'issues'

View File

3
issues/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
issues/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
issues/views.py Normal file
View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -30,6 +30,8 @@ INSTALLED_APPS = [
'projects',
'ingest',
'issues',
'events',
]
MIDDLEWARE = [

View File

@@ -7,7 +7,9 @@ from .views import trigger_error
urlpatterns = [
path('api/', include('ingest.urls')),
path('api/', include('ingest.urls')),
path('events/', include('events.urls')),
path('admin/', admin.site.urls),
]