Skip to content

Commit

Permalink
Set default app dirs pattern (#2390)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
st0012 authored Sep 1, 2024
1 parent 4db5f74 commit 5980531
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions sentry-ruby/lib/sentry/backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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|
Expand Down
6 changes: 5 additions & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry/backtrace/lines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 5980531

Please sign in to comment.