Repository: openfun/marsha

Issue:
Configure sentry in standalone site
## Feature Request

**Is your feature request related to a problem or unsupported use case? Please describe.**

Sentry is not configured in the standalone site and we have no feedback is there are errors.

**Describe the solution you'd like**

Find a solution to configure sentry. Maybe by fetching th configuration on a dedicated api endpoint




Discussion:

Resolving patch:
diff --git a/src/backend/marsha/core/api/base.py b/src/backend/marsha/core/api/base.py
--- a/src/backend/marsha/core/api/base.py
+++ b/src/backend/marsha/core/api/base.py
@@ -1,11 +1,14 @@
 """Declare API endpoints with Django RestFramework viewsets."""
-
+from django.conf import settings
+from django.http import JsonResponse
 from django.shortcuts import get_object_or_404
 
 from rest_framework.decorators import api_view
 from rest_framework.response import Response
+from waffle import switch_is_active
 
 from .. import defaults, serializers
+from ..defaults import SENTRY
 from ..models import Video
 from ..simple_jwt.tokens import ResourceAccessToken
 from ..utils.api_utils import get_uploadable_models_s3_mapping, validate_signature
@@ -153,6 +156,30 @@ def recording_slices_state(request):
     return Response(video.get_recording_slices_state())
 
 
+@api_view(["GET"])
+def get_frontend_configuration(request):
+    """View handling GET request to get the frontend configuration.
+
+    Parameters
+    ----------
+    request : Type[django.http.request.HttpRequest]
+        The request on the API endpoint.
+
+    Returns
+    -------
+    Type[rest_framework.response.Response]
+        HttpResponse containing the frontend configuration.
+
+    """
+    return JsonResponse(
+        {
+            "environment": settings.ENVIRONMENT,
+            "release": settings.RELEASE,
+            "sentry_dsn": settings.SENTRY_DSN if switch_is_active(SENTRY) else None,
+        }
+    )
+
+
 class APIViewMixin:
     """
     Mixin to enhance the base DRF APIView.
diff --git a/src/backend/marsha/urls.py b/src/backend/marsha/urls.py
--- a/src/backend/marsha/urls.py
+++ b/src/backend/marsha/urls.py
@@ -23,6 +23,7 @@
     UserViewSet,
     VideoViewSet,
     XAPIStatementView,
+    get_frontend_configuration,
     pairing_challenge,
     recording_slices_manifest,
     recording_slices_state,
@@ -131,6 +132,7 @@
         recording_slices_state,
         name="recording_slices_state",
     ),
+    path("api/config/", get_frontend_configuration, name="sentry_config"),
     path("api/", include(router.urls)),
     path(
         f"api/{models.Video.RESOURCE_NAME}/<uuid:video_id>/",


Test patch:
diff --git a/src/backend/marsha/core/tests/test_api_get_frontend_configuration.py b/src/backend/marsha/core/tests/test_api_get_frontend_configuration.py
new file mode 100644
--- /dev/null
+++ b/src/backend/marsha/core/tests/test_api_get_frontend_configuration.py
@@ -0,0 +1,55 @@
+"""Tests for the get_frontend_configuration API."""
+from django.test import TestCase, override_settings
+
+from waffle.testutils import override_switch
+
+from marsha.core.defaults import SENTRY
+
+
+@override_settings(
+    SENTRY_DSN="https://sentry.dsn",
+    ENVIRONMENT="development",
+    RELEASE="1.2.3",
+)
+class TestGetFrontendConfiguration(TestCase):
+    """Test the get_frontend_configuration API."""
+
+    maxDiff = None
+
+    @override_switch(SENTRY, active=True)
+    def test_api_get_frontend_configuration_sentry_active(self):
+        """
+        Anonymous users should be able to access the API.
+
+        With sentry active, the response should contain the sentry configuration.
+        """
+        response = self.client.get("/api/config/")
+
+        self.assertEqual(response.status_code, 200)
+        self.assertDictEqual(
+            response.json(),
+            {
+                "environment": "development",
+                "release": "1.2.3",
+                "sentry_dsn": "https://sentry.dsn",
+            },
+        )
+
+    @override_switch(SENTRY, active=False)
+    def test_api_get_frontend_configuration_sentry_inactive(self):
+        """
+        Anonymous users should be able to access the API.
+
+        With sentry inactive, the response should not contain the sentry configuration.
+        """
+        response = self.client.get("/api/config/")
+
+        self.assertEqual(response.status_code, 200)
+        self.assertDictEqual(
+            response.json(),
+            {
+                "environment": "development",
+                "release": "1.2.3",
+                "sentry_dsn": None,
+            },
+        )