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

Make the list of vendor paths configurable #253

Merged
merged 1 commit into from
Aug 27, 2015
Merged
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
2 changes: 2 additions & 0 deletions lib/bugsnag/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Configuration
attr_accessor :send_environment
attr_accessor :send_code
attr_accessor :project_root
attr_accessor :vendor_paths
attr_accessor :app_version
attr_accessor :app_type
attr_accessor :params_filters
Expand Down Expand Up @@ -79,6 +80,7 @@ def initialize
self.hostname = default_hostname
self.delivery_method = DEFAULT_DELIVERY_METHOD
self.timeout = 15
self.vendor_paths = [%r{vendor/}]

# Read the API key from the environment
self.api_key = ENV["BUGSNAG_API_KEY"]
Expand Down
13 changes: 12 additions & 1 deletion lib/bugsnag/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def stacktrace(exception)

# Generate the stacktrace line hash
trace_hash = {}
trace_hash[:inProject] = true if @configuration.project_root && file.match(/^#{@configuration.project_root}/) && !file.match(/vendor\//)
trace_hash[:inProject] = true if in_project?(file)
trace_hash[:lineNumber] = line_str.to_i

if @configuration.send_code
Expand Down Expand Up @@ -410,6 +410,17 @@ def stacktrace(exception)
end.compact
end

def in_project?(line)
return false if @configuration.vendor_paths && @configuration.vendor_paths.any? do |vendor_path|
if vendor_path.is_a?(String)
line.include?(vendor_path)
else
line =~ vendor_path
end
end
@configuration.project_root && line.start_with?(@configuration.project_root.to_s)
end

def code(file, line_number, num_lines = 7)
code_hash = {}

Expand Down
13 changes: 13 additions & 0 deletions spec/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,19 @@ def gloops
}
end

it "does not mark the top-most stacktrace line as inProject if it matches a vendor path" do
Bugsnag.configuration.project_root = File.expand_path('../../', __FILE__)
Bugsnag.configuration.vendor_paths = [File.expand_path('../', __FILE__)]

Bugsnag.notify(BugsnagTestException.new("It crashed"))

expect(Bugsnag).to have_sent_notification{ |payload|
exception = get_exception_from_payload(payload)
expect(exception["stacktrace"].size).to be >= 1
expect(exception["stacktrace"].first["inProject"]).to be_nil
}
end

it "marks the top-most stacktrace line as inProject if necessary" do
Bugsnag.configuration.project_root = File.expand_path File.dirname(__FILE__)
Bugsnag.notify(BugsnagTestException.new("It crashed"))
Expand Down