templates/sentry/sentry_js.html.twig line 1

Open in your IDE?
  1. {# Sentry JavaScript integration - only load in production environment #}
  2. {% if sentry_dsn_public() and app.environment == 'prod' %}
  3. <script src="https://browser.sentry-cdn.com/9.23.0/bundle.tracing.replay.min.js" 
  4.         integrity="sha384-oFbOgfbH8J4hqJscPJNKjnPd/0mpYDMh8IvH9V4AVF8HFLdAVCjdJjUybdjedXyM" 
  5.         crossorigin="anonymous"></script>
  6. <script>
  7.     Sentry.init({
  8.         dsn: "{{ sentry_dsn_public() }}",
  9.         environment: "{{ sentry_environment() }}",
  10.         // Performance Monitoring
  11.         tracesSampleRate: 0.1,
  12.         // Release version
  13.         release: "taaka-beer-spa@{{ constant('App\\Kernel::VERSION') ?? 'unknown' }}",
  14.         // Capture Console errors
  15.         integrations: [
  16.             Sentry.browserTracingIntegration(),
  17.             Sentry.replayIntegration({
  18.                 maskAllText: true,
  19.                 blockAllMedia: true,
  20.             })
  21.         ],
  22.         // Session Replay
  23.         replaysSessionSampleRate: 0.01,
  24.         replaysOnErrorSampleRate: 1.0,
  25.         
  26.         beforeSend(event, hint) {
  27.             // Filter sensitive data
  28.             if (event.request) {
  29.                 // Remove sensitive form data
  30.                 if (event.request.data) {
  31.                     const sensitiveFields = ['password', 'credit_card', 'token', 'api_key'];
  32.                     for (const field of sensitiveFields) {
  33.                         if (event.request.data[field]) {
  34.                             event.request.data[field] = '[Filtered]';
  35.                         }
  36.                     }
  37.                 }
  38.                 
  39.                 // Remove sensitive headers
  40.                 if (event.request.headers) {
  41.                     const sensitiveHeaders = ['authorization', 'cookie', 'x-api-key'];
  42.                     for (const header of sensitiveHeaders) {
  43.                         if (event.request.headers[header]) {
  44.                             event.request.headers[header] = '[Filtered]';
  45.                         }
  46.                     }
  47.                 }
  48.             }
  49.             return event;
  50.         }
  51.     });
  52.     // Set user context if available
  53.     {% if app.user is defined and app.user %}
  54.     Sentry.setUser({
  55.         id: "{{ app.user.id }}",
  56.         email: "{{ app.user.email|default('') }}",
  57.         username: "{{ app.user.username|default('') }}"
  58.     });
  59.     {% endif %}
  60.     // Set additional context
  61.     Sentry.setTag("page", "{{ app.request.attributes.get('_route') ?? 'unknown' }}");
  62.     
  63.     // Global error handler for unhandled promise rejections
  64.     window.addEventListener('unhandledrejection', function(event) {
  65.         Sentry.captureException(event.reason);
  66.     });
  67. </script>
  68. {% else %}
  69. {# Sentry is disabled in development environment #}
  70. <!-- Sentry JavaScript integration is disabled (environment: {{ app.environment }}) -->
  71. {% endif %}