From 4fc38c720843c0f280eaf1133a2fe801058d0552 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 18 Aug 2023 09:52:52 +0200 Subject: [PATCH] Enable Sentry browser profiling --- app/assets/javascripts/base.js | 1 + app/controllers/application_controller.rb | 8 +++++++- app/javascript/application.js | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/base.js b/app/assets/javascripts/base.js index a2cabeec..1e6ed0b8 100644 --- a/app/assets/javascripts/base.js +++ b/app/assets/javascripts/base.js @@ -57,6 +57,7 @@ $(document).on('turbolinks:load', function() { replaysSessionSampleRate: 0.0, replaysOnErrorSampleRate: 1.0, integrations: window.SentryIntegrations(), + profilesSampleRate: 1.0, initialScope: scope =>{ const user = $('meta[name="current-user"]').attr('content'); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9c389afd..22f3b126 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,7 +13,7 @@ class ApplicationController < ActionController::Base after_action :verify_authorized, except: %i[welcome] around_action :mnemosyne_trace around_action :switch_locale - before_action :set_sentry_context, :load_embed_options + before_action :set_sentry_context, :load_embed_options, :set_document_policy protect_from_forgery(with: :exception, prepend: true) rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized rescue_from ActiveRecord::RecordNotFound, with: :render_not_found @@ -72,6 +72,12 @@ class ApplicationController < ActionController::Base end end + def set_document_policy + # Instruct browsers to capture profiling data + response.set_header('Document-Policy', 'js-profiling') + end + private :set_document_policy + def set_sentry_context return if current_user.blank? diff --git a/app/javascript/application.js b/app/javascript/application.js index 5310cb64..312c7310 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -29,6 +29,7 @@ window.SentryIntegrations = function() { // Publish sentry integration in global new SentryIntegration.ReportingObserver(), new SentryIntegration.ExtraErrorData(), new SentryIntegration.HttpClient(), + new Sentry.BrowserProfilingIntegration(), new Sentry.BrowserTracing(), new Sentry.Replay(), ]