Skip to content

Commit

Permalink
Merge pull request #253 from Shopify/configurable-vendor-paths
Browse files Browse the repository at this point in the history
Make the list of vendor paths configurable
  • Loading branch information
snmaynard committed Aug 27, 2015
2 parents a6eb35f + c09105a commit 6348306
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/bugsnag/configuration.rb
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
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
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

0 comments on commit 6348306

Please sign in to comment.