From d8497b36c98f0d18effb5a0f3b16a55a47e7f1da Mon Sep 17 00:00:00 2001 From: Steve Kirkland Date: Sat, 25 Jan 2020 22:13:19 +0000 Subject: [PATCH 1/8] fix: Resolve Ruby deprecation warning (in Ruby 2.7)/error (in 3.0) Fixes #580 --- lib/bugsnag/cleaner.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index 6c851542e..e4b6240af 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -2,7 +2,6 @@ module Bugsnag class Cleaner - ENCODING_OPTIONS = {:invalid => :replace, :undef => :replace}.freeze FILTERED = '[FILTERED]'.freeze RECURSION = '[RECURSION]'.freeze OBJECT = '[OBJECT]'.freeze @@ -60,9 +59,9 @@ def traverse_object(obj, seen, scope) def clean_string(str) if defined?(str.encoding) && defined?(Encoding::UTF_8) if str.encoding == Encoding::UTF_8 - str.valid_encoding? ? str : str.encode('utf-16', ENCODING_OPTIONS).encode('utf-8') + str.valid_encoding? ? str : str.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8') else - str.encode('utf-8', ENCODING_OPTIONS) + str.encode('utf-8', invalid: :replace, undef: :replace) end elsif defined?(Iconv) Iconv.conv('UTF-8//IGNORE', 'UTF-8', str) || str From e74492fd299be59a544a0a77f18d11cfa38b75ef Mon Sep 17 00:00:00 2001 From: Jordan Raine Date: Mon, 10 Jun 2019 07:58:31 -0700 Subject: [PATCH 2/8] Allow vendor_path to be configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows developers to set the vendor path regular expression, used to determine whether or not a line in the stacktrace appears in the project stacktrace or the full trace. ```ruby Bugsnag.configure do |config| config.vendor_path = /(^(vendor\/|\.bundle\/|extensions\/|private_gems\/))/ end ``` By default, lines within `vendor/` or `.bundle/` are consider “out of project”. This is a good default for most Rails projects but there are other directories we’d also like to ignore. For example, patches to gems or the framework. If left as “in project”, these lines cause multiple issues to be grouped together because the first line in the stacktrace always points to the same patch line. Right now, we’ve side stepped this by reaching into the gem and redefining `Bugsnag::Stacktrace::VENDOR_PATH` but it would be wonderful if this was a configurable option like any other. --- CHANGELOG.md | 7 +++++++ lib/bugsnag/configuration.rb | 11 ++++++++++ lib/bugsnag/stacktrace.rb | 2 +- spec/configuration_spec.rb | 11 ++++++++++ spec/stacktrace_spec.rb | 39 ++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0868d12e..94cff297f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +## TBD + +### Enhancements + +* Add option to configure what file paths are included in the project stacktrace (`vendor_path`) + | [#544](https://github.com/bugsnag/bugsnag-ruby/pull/544) + ## 6.12.2 (24 Oct 2019) ### Fixes diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index e317e43c9..85620e671 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -63,6 +63,10 @@ class Configuration # @return [Integer] the maximum allowable amount of breadcrumbs per thread attr_reader :max_breadcrumbs + ## + # @return [Regexp] matching file paths within the project + attr_writer :vendor_path + API_KEY_REGEX = /[0-9a-f]{32}/i THREAD_LOCAL_NAME = "bugsnag_req_data" @@ -176,6 +180,13 @@ def should_notify_release_stage? @release_stage.nil? || @notify_release_stages.nil? || @notify_release_stages.include?(@release_stage) end + ## + # Regex used to mark stacktrace lines as within the project. Lines marked + # as "out of project" will only appear in the full trace. + def vendor_path + @vendor_path || Bugsnag::Stacktrace::VENDOR_PATH + end + ## # Tests whether the configured API key is valid. def valid_api_key? diff --git a/lib/bugsnag/stacktrace.rb b/lib/bugsnag/stacktrace.rb index 42a82461d..b9b22769d 100644 --- a/lib/bugsnag/stacktrace.rb +++ b/lib/bugsnag/stacktrace.rb @@ -46,7 +46,7 @@ def initialize(backtrace, configuration) if defined?(@configuration.project_root) && @configuration.project_root.to_s != '' trace_hash[:inProject] = true if file.start_with?(@configuration.project_root.to_s) file.sub!(/#{@configuration.project_root}\//, "") - trace_hash.delete(:inProject) if file.match(VENDOR_PATH) + trace_hash.delete(:inProject) if file.match(@configuration.vendor_path) end diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index ae3690db2..296a18de7 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -427,4 +427,15 @@ def debug(name, &block) expect(second_array).to eq([1, 2]) end end + + describe "vendor_path" do + it "should have the default vendor path" do + expect(subject.vendor_path).to eq(Bugsnag::Stacktrace::VENDOR_PATH) + end + + it "should have the defined vendor path" do + subject.vendor_path = /foo/ + expect(subject.vendor_path).to eq(/foo/) + end + end end diff --git a/spec/stacktrace_spec.rb b/spec/stacktrace_spec.rb index 57895f2b2..7ad0c8170 100644 --- a/spec/stacktrace_spec.rb +++ b/spec/stacktrace_spec.rb @@ -87,4 +87,43 @@ }) } end + + describe "#vendor_cache" do + let(:configuration) do + configuration = Bugsnag::Configuration.new + configuration.project_root = "/foo/bar" + configuration + end + + let(:backtrace) do + [ + "/foo/bar/app/models/user.rb:1:in `something'", + "/foo/bar/other_vendor/lib/dont.rb:1:in `to_s'", + "/foo/bar/vendor/lib/ignore_me.rb:1:in `to_s'", + "/foo/bar/.bundle/lib/ignore_me.rb:1:in `to_s'", + ] + end + + def out_project_trace(stacktrace) + stacktrace.to_a.map do |trace_line| + trace_line[:file] if !trace_line[:inProject] + end.compact + end + + it "marks vendor/ and .bundle/ as out-project by default" do + stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration) + + expect(out_project_trace(stacktrace)).to eq([ + "vendor/lib/ignore_me.rb", + ".bundle/lib/ignore_me.rb", + ]) + end + + it "allows vendor_path to be configured" do + configuration.vendor_path = /other_vendor\// + stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration) + + expect(out_project_trace(stacktrace)).to eq(["other_vendor/lib/dont.rb"]) + end + end end From 0abbd8e52f923e6e0cdc85b7756a4d33384e0c57 Mon Sep 17 00:00:00 2001 From: Ted Yang Date: Fri, 24 Jan 2020 15:08:19 -0800 Subject: [PATCH 3/8] 1. Move the `VENDOR_PATH` from Bugsnag::Stacktrace to Bugsnag::Configuration (and rename it to DEFAULT_VENDOR_PATH). 2. Add `attr_accessor :vendor_path` to Bugsnag::Configuration and initialize it with DEFAULT_VENDOR_PATH. --- lib/bugsnag/configuration.rb | 19 ++++++++++--------- lib/bugsnag/stacktrace.rb | 3 --- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index 85620e671..db2ab5748 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -64,8 +64,8 @@ class Configuration attr_reader :max_breadcrumbs ## - # @return [Regexp] matching file paths within the project - attr_writer :vendor_path + # @return [Regexp] matching file paths out of project + attr_accessor :vendor_path API_KEY_REGEX = /[0-9a-f]{32}/i THREAD_LOCAL_NAME = "bugsnag_req_data" @@ -85,6 +85,9 @@ class Configuration DEFAULT_MAX_BREADCRUMBS = 25 + # Path to vendored code. Used to mark file paths as out of project. + DEFAULT_VENDOR_PATH = /^(vendor\/|\.bundle\/)/ + alias :track_sessions :auto_capture_sessions alias :track_sessions= :auto_capture_sessions= @@ -129,6 +132,11 @@ def initialize parse_proxy(proxy_uri) end + # Set up vendor_path regex to mark stacktrace file paths as out of project. + # Stacktrace lines that matches regex will be marked as "out of project" + # will only appear in the full trace. + self.vendor_path = DEFAULT_VENDOR_PATH + # Set up logging self.logger = Logger.new(STDOUT) self.logger.level = Logger::INFO @@ -180,13 +188,6 @@ def should_notify_release_stage? @release_stage.nil? || @notify_release_stages.nil? || @notify_release_stages.include?(@release_stage) end - ## - # Regex used to mark stacktrace lines as within the project. Lines marked - # as "out of project" will only appear in the full trace. - def vendor_path - @vendor_path || Bugsnag::Stacktrace::VENDOR_PATH - end - ## # Tests whether the configured API key is valid. def valid_api_key? diff --git a/lib/bugsnag/stacktrace.rb b/lib/bugsnag/stacktrace.rb index b9b22769d..1eb0259e0 100644 --- a/lib/bugsnag/stacktrace.rb +++ b/lib/bugsnag/stacktrace.rb @@ -7,9 +7,6 @@ class Stacktrace # e.g. "org.jruby.Ruby.runScript(Ruby.java:807)" JAVA_BACKTRACE_REGEX = /^(.*)\((.*)(?::([0-9]+))?\)$/ - # Path to vendored code. Used to mark file paths as out of project. - VENDOR_PATH = /^(vendor\/|\.bundle\/)/ - ## # Process a backtrace and the configuration into a parsed stacktrace. def initialize(backtrace, configuration) From 37e7b39e68d595225f5c5fb974f728038bb3eb80 Mon Sep 17 00:00:00 2001 From: Ted Yang Date: Fri, 24 Jan 2020 15:12:56 -0800 Subject: [PATCH 4/8] Update spec since Bugsnag::Stacktrace::VENDOR_PATH becomes Bugsnag::Configuration::DEFAULT_VENDOR_PATH --- spec/configuration_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 296a18de7..5db5e5f23 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -428,12 +428,12 @@ def debug(name, &block) end end - describe "vendor_path" do - it "should have the default vendor path" do - expect(subject.vendor_path).to eq(Bugsnag::Stacktrace::VENDOR_PATH) + describe "#vendor_path" do + it "returns the default vendor path" do + expect(subject.vendor_path).to eq(Bugsnag::Configuration::DEFAULT_VENDOR_PATH) end - it "should have the defined vendor path" do + it "returns the defined vendor path" do subject.vendor_path = /foo/ expect(subject.vendor_path).to eq(/foo/) end From 7ba05317f6751d102b0c6b12122dd0ec5c110fe1 Mon Sep 17 00:00:00 2001 From: Ted Yang Date: Fri, 24 Jan 2020 15:24:12 -0800 Subject: [PATCH 5/8] Update specs to be more descriptive --- spec/stacktrace_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/stacktrace_spec.rb b/spec/stacktrace_spec.rb index 7ad0c8170..f17b2dff3 100644 --- a/spec/stacktrace_spec.rb +++ b/spec/stacktrace_spec.rb @@ -88,7 +88,7 @@ } end - describe "#vendor_cache" do + context "with configurable vendor_path" do let(:configuration) do configuration = Bugsnag::Configuration.new configuration.project_root = "/foo/bar" @@ -119,7 +119,7 @@ def out_project_trace(stacktrace) ]) end - it "allows vendor_path to be configured" do + it "allows vendor_path to be configured and filters out backtrace file paths" do configuration.vendor_path = /other_vendor\// stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration) From b52d255af85c0c7bc3cba90aeefa5533f7a2e9dc Mon Sep 17 00:00:00 2001 From: Ted Yang Date: Fri, 24 Jan 2020 15:29:16 -0800 Subject: [PATCH 6/8] Add Changelog message --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94cff297f..cfd4e354b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ Changelog ### Enhancements -* Add option to configure what file paths are included in the project stacktrace (`vendor_path`) +* Add configurable `vendor_path` to configure which file paths are out of project stacktrace. | [#544](https://github.com/bugsnag/bugsnag-ruby/pull/544) ## 6.12.2 (24 Oct 2019) From eb685866b4e901ff4c7d7f9b262c4bdb78a23035 Mon Sep 17 00:00:00 2001 From: Tom Longridge Date: Tue, 28 Jan 2020 12:56:12 +0000 Subject: [PATCH 7/8] Fixed rubocop style violation in regex --- .rubocop_todo.yml | 2 +- lib/bugsnag/configuration.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a1e491717..4715394ab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -568,7 +568,7 @@ Style/RedundantSelf: - 'lib/bugsnag/configuration.rb' - 'lib/bugsnag/integrations/railtie.rb' -# Offense count: 3 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index db2ab5748..90a3fa2fb 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -86,7 +86,7 @@ class Configuration DEFAULT_MAX_BREADCRUMBS = 25 # Path to vendored code. Used to mark file paths as out of project. - DEFAULT_VENDOR_PATH = /^(vendor\/|\.bundle\/)/ + DEFAULT_VENDOR_PATH = %r{^(vendor\/|\.bundle\/)} alias :track_sessions :auto_capture_sessions alias :track_sessions= :auto_capture_sessions= From ea395ca87c64b8d64fd13b59471cc8486e2cf507 Mon Sep 17 00:00:00 2001 From: Tom Longridge Date: Thu, 30 Jan 2020 16:07:30 +0000 Subject: [PATCH 8/8] Release v6.13.0 --- CHANGELOG.md | 7 ++++++- VERSION | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd4e354b..fc258397c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,18 @@ Changelog ========= -## TBD +## 6.13.0 (30 Jan 2020) ### Enhancements * Add configurable `vendor_path` to configure which file paths are out of project stacktrace. | [#544](https://github.com/bugsnag/bugsnag-ruby/pull/544) +### Fixes + +* Resolve Ruby deprecation warning for keyword parameters + | [#580](https://github.com/bugsnag/bugsnag-ruby/pull/582) + ## 6.12.2 (24 Oct 2019) ### Fixes diff --git a/VERSION b/VERSION index f867e2993..5917993c0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.12.2 +6.13.0