diff --git a/.env b/.env index 23f3406..5ca542a 100644 --- a/.env +++ b/.env @@ -61,6 +61,7 @@ NTFY_DSN= ###> sentry/sentry-symfony ### SENTRY_DSN= +SENTRY_JS_URL= ###< sentry/sentry-symfony ### # TMDB 'with_original_language' option diff --git a/config/packages/sentry.yaml b/config/packages/sentry.yaml index b0e4cb8..e8b0366 100644 --- a/config/packages/sentry.yaml +++ b/config/packages/sentry.yaml @@ -5,18 +5,18 @@ when@prod: options: release: '%app.version%' - traces_sample_rate: 0 - profiles_sample_rate: 0 + traces_sample_rate: 1 + profiles_sample_rate: 1 attach_stacktrace: true -# tracing: -# enabled: true -# dbal: # DB queries -# enabled: true -# cache: # cache pools -# enabled: true -# twig: # templating engine -# enabled: true + tracing: + enabled: true + dbal: # DB queries + enabled: true + cache: # cache pools + enabled: true + twig: # templating engine + enabled: true services: # (Optionally) Configure the breadcrumb handler as a service (needed for the breadcrumb Monolog handler) diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 0937f94..bb9539b 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -1,6 +1,7 @@ twig: globals: version: '%app.version%' + sentry_javascript_url: '%sentry.javascript_url%' file_name_pattern: '*.twig' date: format: 'm/d/Y' diff --git a/config/services.yaml b/config/services.yaml index b0cb080..572da57 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -48,6 +48,10 @@ parameters: notification.transport: '%env(NOTIFICATION_TRANSPORT)%' notification.ntfy.dsn: '%env(NTFY_DSN)%' + # Sentry + sentry.dsn: '%env(SENTRY_DSN)%' + sentry.javascript_url: '%env(SENTRY_JS_URL)%' + services: # default configuration for services in *this* file _defaults: diff --git a/src/Base/ConfigResolver.php b/src/Base/ConfigResolver.php index 3ea1f10..92b4ddb 100644 --- a/src/Base/ConfigResolver.php +++ b/src/Base/ConfigResolver.php @@ -53,6 +53,15 @@ final class ConfigResolver #[Autowire(param: 'notification.ntfy.dsn')] private ?string $notificationNtfyDsn = null, + + #[Autowire(param: 'sentry.dsn')] + private ?string $sentryDsn = null, + + #[Autowire(param: 'sentry.environment')] + private ?string $sentryEnvironment = null, + + #[Autowire(param: 'sentry.javascript_url')] + private ?string $sentryJavascriptUrl = null, ) {} public function validate(): bool @@ -120,4 +129,13 @@ final class ConfigResolver ] ]; } + + public function getSentryConfig() + { + return [ + 'dsn' => $this->sentryDsn, + 'environment' => $this->sentryEnvironment, + 'javascript_url' => $this->sentryJavascriptUrl, + ]; + } } diff --git a/src/Twig/Extensions/UtilExtension.php b/src/Twig/Extensions/UtilExtension.php index 5e8799a..cf04255 100644 --- a/src/Twig/Extensions/UtilExtension.php +++ b/src/Twig/Extensions/UtilExtension.php @@ -112,4 +112,12 @@ class UtilExtension return new EpisodeIdDto($season, $episode); } + + #[AsTwigFunction('sentry_enabled')] + public function sentryEnabled(): bool + { + $sentryConfig = $this->config->getSentryConfig(); + return $sentryConfig['javascript_url'] !== null && + $sentryConfig['javascript_url'] !== ''; + } } diff --git a/templates/bare.html.twig b/templates/bare.html.twig index 1133f69..adfaa89 100644 --- a/templates/bare.html.twig +++ b/templates/bare.html.twig @@ -12,6 +12,7 @@ {% block javascripts %} {% block importmap %}{{ importmap('app') }}{% endblock %} + {% endblock %}
diff --git a/templates/base.html.twig b/templates/base.html.twig index 5342818..de33183 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -12,6 +12,10 @@ {% block javascripts %} {% block importmap %}{{ importmap('app') }}{% endblock %} + + {% if sentry_enabled() %} + + {% endif %} {% endblock %}