Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow vendor_path to be configured #544

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Enhancements

* Add configurable `vendor_path` to configure what file paths are out of project stacktrace.
| [#544](https://github.com/bugsnag/bugsnag-ruby/pull/544)

## 6.12.1 (05 Sep 2019)

### Fixes
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 = /^(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