From c4724600124fe5768a6f0852630e24d709c347e8 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Thu, 17 Oct 2024 08:23:50 +0300 Subject: [PATCH 1/2] UHF-9982: Overwrite sentry DSN for js tracking --- helfi_api_base.module | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/helfi_api_base.module b/helfi_api_base.module index 178a129..7774a17 100644 --- a/helfi_api_base.module +++ b/helfi_api_base.module @@ -7,6 +7,7 @@ declare(strict_types=1); +use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\helfi_api_base\Features\FeatureManager; @@ -123,3 +124,14 @@ function helfi_api_base_template_preprocess_default_variables_alter(array &$vari $variables['lang_attributes']['fallback_dir'] = $attributes['dir']; } } + +/** + * Implements hook_js_settings_alter(). + */ +function helfi_api_base_js_settings_alter(array &$settings, AttachedAssetsInterface $assets): void { + // Raven sets DSN from SENTRY_DSN environment variable, which we use for + // PHP tracking. + if (isset($settings['raven']['options']['dsn'])) { + $settings['raven']['options']['dsn'] = getenv('SENTRY_DSN_PUBLIC'); + } +} From f81752fe65130a734ff06508630f514c3bdffabc Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Thu, 17 Oct 2024 12:30:24 +0300 Subject: [PATCH 2/2] UHF-9982: Configure sentry browser tracking --- helfi_api_base.install | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/helfi_api_base.install b/helfi_api_base.install index 1b8b238..27be033 100644 --- a/helfi_api_base.install +++ b/helfi_api_base.install @@ -39,6 +39,7 @@ function helfi_api_base_install(bool $is_syncing = FALSE) : void { ->set('drush_error_handler', TRUE) ->set('request_tracing', TRUE) ->set('traces_sample_rate', 0.2) + ->set('browser_traces_sample_rate', 0.2) ->set('database_tracing', TRUE) ->set('twig_tracing', TRUE) ->save(); @@ -188,3 +189,14 @@ function helfi_api_base_update_9019(): void { \Drupal::configFactory()->getEditable('rest.resource.helfi_debug_data') ->delete(); } + +/** + * UHF-9982: Configure sentry browser tracking. + */ +function helfi_api_base_update_9020(): void { + if (Drupal::moduleHandler()->moduleExists('raven')) { + Drupal::configFactory()->getEditable('raven.settings') + ->set('browser_traces_sample_rate', 0.2) + ->save(); + } +}