{# Sentry JavaScript integration - only load in production environment #}
{% if sentry_dsn_public() and app.environment == 'prod' %}
<script src="https://browser.sentry-cdn.com/9.23.0/bundle.tracing.replay.min.js"
integrity="sha384-oFbOgfbH8J4hqJscPJNKjnPd/0mpYDMh8IvH9V4AVF8HFLdAVCjdJjUybdjedXyM"
crossorigin="anonymous"></script>
<script>
Sentry.init({
dsn: "{{ sentry_dsn_public() }}",
environment: "{{ sentry_environment() }}",
// Performance Monitoring
tracesSampleRate: 0.1,
// Release version
release: "taaka-beer-spa@{{ constant('App\\Kernel::VERSION') ?? 'unknown' }}",
// Capture Console errors
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration({
maskAllText: true,
blockAllMedia: true,
})
],
// Session Replay
replaysSessionSampleRate: 0.01,
replaysOnErrorSampleRate: 1.0,
beforeSend(event, hint) {
// Filter sensitive data
if (event.request) {
// Remove sensitive form data
if (event.request.data) {
const sensitiveFields = ['password', 'credit_card', 'token', 'api_key'];
for (const field of sensitiveFields) {
if (event.request.data[field]) {
event.request.data[field] = '[Filtered]';
}
}
}
// Remove sensitive headers
if (event.request.headers) {
const sensitiveHeaders = ['authorization', 'cookie', 'x-api-key'];
for (const header of sensitiveHeaders) {
if (event.request.headers[header]) {
event.request.headers[header] = '[Filtered]';
}
}
}
}
return event;
}
});
// Set user context if available
{% if app.user is defined and app.user %}
Sentry.setUser({
id: "{{ app.user.id }}",
email: "{{ app.user.email|default('') }}",
username: "{{ app.user.username|default('') }}"
});
{% endif %}
// Set additional context
Sentry.setTag("page", "{{ app.request.attributes.get('_route') ?? 'unknown' }}");
// Global error handler for unhandled promise rejections
window.addEventListener('unhandledrejection', function(event) {
Sentry.captureException(event.reason);
});
</script>
{% else %}
{# Sentry is disabled in development environment #}
<!-- Sentry JavaScript integration is disabled (environment: {{ app.environment }}) -->
{% endif %}