from django.http import HttpRequest, HttpResponse from django_components import Component, register, types from .component import analytics_events, error_rate class AnalyticsPage(Component): class Media: js = ("https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,container-queries",) template: types.django_html = """ {% load component_tags %}
Track component errors or success rates to send them to Sentry or other services.
{# NOTE: Intentionally hidden so we focus on the events tracking #} {% component "captured_events" / %}This component only logs events when an error occurs.
{% component "error_fallback" %} {% component "sentry_error_tracker" %} {% component "api_widget" simulate_error=True / %} {% endcomponent %} {% endcomponent %} {% component "sentry_error_tracker" %} {% component "api_widget" simulate_error=False / %} {% endcomponent %}This component logs both successful and failed renders.
{% component "error_fallback" %} {% component "success_rate_tracker" %} {% component "api_widget" simulate_error=True / %} {% endcomponent %} {% endcomponent %} {% component "success_rate_tracker" %} {% component "api_widget" simulate_error=False / %} {% endcomponent %}
{% for event in events %}
{{ event }}
{% endfor %}
{{ error_rate }}
{{ error_rate.error }} errors out of {{ error_rate.success }} calls.