From 7c5b1803e8c1fbf233d2784d8a5c29eada2d5589 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Thu, 17 Oct 2024 07:26:44 +0000 Subject: [PATCH] WIP --- sentry-rails/spec/dummy/test_rails_app/app.rb | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/sentry-rails/spec/dummy/test_rails_app/app.rb b/sentry-rails/spec/dummy/test_rails_app/app.rb index 95309fbaa..305c04c53 100644 --- a/sentry-rails/spec/dummy/test_rails_app/app.rb +++ b/sentry-rails/spec/dummy/test_rails_app/app.rb @@ -43,14 +43,19 @@ class TestApp < Rails::Application require "dummy/test_rails_app/configs/#{FILE_NAME}" def make_basic_app(&block) + start_time = Time.now run_pre_initialize_cleanup + puts "Pre-initialize cleanup took #{Time.now - start_time} seconds" + app_creation_start = Time.now app = Class.new(TestApp) do def self.name "RailsTestApp" end end + puts "App creation took #{Time.now - app_creation_start} seconds" + config_start = Time.now app.config.active_support.deprecation = :silence app.config.action_controller.view_paths = "spec/dummy/test_rails_app" app.config.hosts = nil @@ -59,15 +64,14 @@ def self.name app.config.eager_load = true app.config.active_job.queue_adapter = :test - # Eager load namespaces can be accumulated after repeated initializations and make initialization - # slower after each run - # This is especially obvious in Rails 7.2, because of https://github.com/rails/rails/pull/49987, but other constants's - # accumulation can also cause slowdown - # Because this is not necessary for the test, we can simply clear it here app.config.eager_load_namespaces.clear + puts "App configuration took #{Time.now - config_start} seconds" + configure_app_start = Time.now configure_app(app) + puts "configure_app took #{Time.now - configure_app_start} seconds" + routes_start = Time.now app.routes.append do get "/exception", to: "hello#exception" get "/view_exception", to: "hello#view_exception" @@ -83,30 +87,41 @@ def self.name get "500", to: "hello#reporting" root to: "hello#world" end + puts "Routes configuration took #{Time.now - routes_start} seconds" + sentry_init_start = Time.now app.initializer :configure_sentry do Sentry.init do |config| config.release = 'beta' config.dsn = "http://12345:67890@sentry.localdomain:3000/sentry/42" config.transport.transport_class = Sentry::DummyTransport - # for sending events synchronously config.background_worker_threads = 0 config.capture_exception_frame_locals = true yield(config, app) if block_given? end end + puts "Sentry initialization took #{Time.now - sentry_init_start} seconds" + app_init_start = Time.now app.initialize! + puts "App initialization took #{Time.now - app_init_start} seconds" Rails.application = app - # load application code for the Rails version + require_start = Time.now require "dummy/test_rails_app/apps/#{FILE_NAME}" + puts "Requiring app file took #{Time.now - require_start} seconds" - Post.all.to_a # to run the sqlte version query first + post_query_start = Time.now + Post.all.to_a + puts "Post query took #{Time.now - post_query_start} seconds" - # and then clear breadcrumbs in case the above query is recorded - Sentry.get_current_scope.clear_breadcrumbs if Sentry.initialized? + if Sentry.initialized? + clear_breadcrumbs_start = Time.now + Sentry.get_current_scope.clear_breadcrumbs + puts "Clearing breadcrumbs took #{Time.now - clear_breadcrumbs_start} seconds" + end + puts "Total time: #{Time.now - start_time} seconds" app end