Skip to content

Commit

Permalink
Merge pull request #584 from bugsnag/next
Browse files Browse the repository at this point in the history
Release 6.13.0
  • Loading branch information
tomlongridge authored Jan 30, 2020
2 parents 9b9a639 + ea395ca commit d474fbf
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
=========

## 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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.12.2
6.13.0
5 changes: 2 additions & 3 deletions lib/bugsnag/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Bugsnag
class Cleaner
ENCODING_OPTIONS = {:invalid => :replace, :undef => :replace}.freeze
FILTERED = '[FILTERED]'.freeze
RECURSION = '[RECURSION]'.freeze
OBJECT = '[OBJECT]'.freeze
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/bugsnag/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 out of project
attr_accessor :vendor_path

API_KEY_REGEX = /[0-9a-f]{32}/i
THREAD_LOCAL_NAME = "bugsnag_req_data"

Expand All @@ -81,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 = %r{^(vendor\/|\.bundle\/)}

alias :track_sessions :auto_capture_sessions
alias :track_sessions= :auto_capture_sessions=

Expand Down Expand Up @@ -125,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
Expand Down
5 changes: 1 addition & 4 deletions lib/bugsnag/stacktrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -46,7 +43,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


Expand Down
11 changes: 11 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,15 @@ def debug(name, &block)
expect(second_array).to eq([1, 2])
end
end

describe "#vendor_path" do
it "returns the default vendor path" do
expect(subject.vendor_path).to eq(Bugsnag::Configuration::DEFAULT_VENDOR_PATH)
end

it "returns the defined vendor path" do
subject.vendor_path = /foo/
expect(subject.vendor_path).to eq(/foo/)
end
end
end
39 changes: 39 additions & 0 deletions spec/stacktrace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,43 @@
})
}
end

context "with configurable vendor_path" 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 and filters out backtrace file paths" 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

0 comments on commit d474fbf

Please sign in to comment.