From 5980531cf582797046a21f3d1e91fcaa4c1b56e3 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sun, 1 Sep 2024 22:54:45 +0100 Subject: [PATCH] Set default app dirs pattern (#2390) * Set default app dirs pattern Instead of falling back to the default app dirs pattern when `config.app_dirs_pattern` is `nil`, we can simply set it to `APP_DIRS_PATTERN` by default. This means we don't need to always check if `config.app_dirs_pattern` is set and can simply use it. * Update changelog --- CHANGELOG.md | 1 + sentry-ruby/lib/sentry/backtrace.rb | 4 +--- sentry-ruby/lib/sentry/configuration.rb | 6 +++++- sentry-ruby/lib/sentry/profiler.rb | 2 +- sentry-ruby/spec/sentry/backtrace/lines_spec.rb | 2 +- sentry-ruby/spec/sentry/transport_spec.rb | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4430e9fb7..01ca61028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add support for $SENTRY_DEBUG and $SENTRY_SPOTLIGHT ([#2374](https://github.com/getsentry/sentry-ruby/pull/2374)) - Support human readable intervals in `sidekiq-cron` ([#2387](https://github.com/getsentry/sentry-ruby/pull/2387)) +- Set default app dirs pattern ([#2390](https://github.com/getsentry/sentry-ruby/pull/2390)) ## 5.19.0 diff --git a/sentry-ruby/lib/sentry/backtrace.rb b/sentry-ruby/lib/sentry/backtrace.rb index b7ebb2159..c5ab16d39 100644 --- a/sentry-ruby/lib/sentry/backtrace.rb +++ b/sentry-ruby/lib/sentry/backtrace.rb @@ -80,8 +80,6 @@ def inspect end end - APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test|spec)/.freeze - # holder for an Array of Backtrace::Line instances attr_reader :lines @@ -91,7 +89,7 @@ def self.parse(backtrace, project_root, app_dirs_pattern, &backtrace_cleanup_cal ruby_lines = backtrace_cleanup_callback.call(ruby_lines) if backtrace_cleanup_callback in_app_pattern ||= begin - Regexp.new("^(#{project_root}/)?#{app_dirs_pattern || APP_DIRS_PATTERN}") + Regexp.new("^(#{project_root}/)?#{app_dirs_pattern}") end lines = ruby_lines.to_a.map do |unparsed_line| diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index 4fb927cb4..9b119b508 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -23,6 +23,8 @@ class Configuration # have an `engines` dir at the root of your project, you may want # to set this to something like /(app|config|engines|lib)/ # + # The default is value is /(bin|exe|app|config|lib|test|spec)/ + # # @return [Regexp, nil] attr_accessor :app_dirs_pattern @@ -336,6 +338,8 @@ def capture_exception_frame_locals=(value) DEFAULT_PATCHES = %i[redis puma http].freeze + APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test|spec)/.freeze + class << self # Post initialization callbacks are called at the end of initialization process # allowing extending the configuration of sentry-ruby by multiple extensions @@ -350,7 +354,7 @@ def add_post_initialization_callback(&block) end def initialize - self.app_dirs_pattern = nil + self.app_dirs_pattern = APP_DIRS_PATTERN self.debug = Sentry::Utils::EnvHelper.env_to_bool(ENV["SENTRY_DEBUG"]) self.background_worker_threads = (processor_count / 2.0).ceil self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE diff --git a/sentry-ruby/lib/sentry/profiler.rb b/sentry-ruby/lib/sentry/profiler.rb index cec7c70ce..ee6590357 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -21,7 +21,7 @@ def initialize(configuration) @profiling_enabled = defined?(StackProf) && configuration.profiling_enabled? @profiles_sample_rate = configuration.profiles_sample_rate @project_root = configuration.project_root - @app_dirs_pattern = configuration.app_dirs_pattern || Backtrace::APP_DIRS_PATTERN + @app_dirs_pattern = configuration.app_dirs_pattern @in_app_pattern = Regexp.new("^(#{@project_root}/)?#{@app_dirs_pattern}") end diff --git a/sentry-ruby/spec/sentry/backtrace/lines_spec.rb b/sentry-ruby/spec/sentry/backtrace/lines_spec.rb index cdcb9809d..92dc48e6d 100644 --- a/sentry-ruby/spec/sentry/backtrace/lines_spec.rb +++ b/sentry-ruby/spec/sentry/backtrace/lines_spec.rb @@ -13,7 +13,7 @@ let(:in_app_pattern) do project_root = Sentry.configuration.project_root&.to_s - Regexp.new("^(#{project_root}/)?#{Sentry::Backtrace::APP_DIRS_PATTERN}") + Regexp.new("^(#{project_root}/)?#{Sentry::Configuration::APP_DIRS_PATTERN}") end describe ".parse" do diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index b78dc7878..9eb5de9dc 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -250,7 +250,7 @@ let(:in_app_pattern) do project_root = "/fake/project_root" - Regexp.new("^(#{project_root}/)?#{Sentry::Backtrace::APP_DIRS_PATTERN}") + Regexp.new("^(#{project_root}/)?#{Sentry::Configuration::APP_DIRS_PATTERN}") end let(:frame_list_limit) { 500 } let(:frame_list_size) { frame_list_limit * 20 }