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

Speed up file path resolution when processing stacktraces #603

Merged
merged 1 commit into from
Jul 15, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Changelog

* Improve performance when processing stacktraces
| [#602](https://github.com/bugsnag/bugsnag-ruby/pull/602)
| [#603](https://github.com/bugsnag/bugsnag-ruby/pull/603)

### Deprecated

Expand Down
5 changes: 1 addition & 4 deletions lib/bugsnag/stacktrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ def initialize(backtrace, configuration)
next(nil) if file.nil?

# Expand relative paths
p = Pathname.new(file)
if p.relative?
file = File.realpath(file) rescue file
end
file = File.realpath(file) rescue file

# Generate the stacktrace line hash
trace_hash = {}
Expand Down
10 changes: 4 additions & 6 deletions spec/stacktrace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,11 @@
configuration = Bugsnag::Configuration.new
configuration.send_code = false

dir = File.dirname(__FILE__)

backtrace = [
"/foo/bar/app/models/user.rb:1:in `something'",
"/foo/bar/other_vendor/lib/dont.rb:2:in `to_s'",
"/foo/bar/vendor/lib/ignore_me.rb:3:in `to_s'",
"/foo/bar/.bundle/lib/ignore_me.rb:4:in `to_s'",
"#{dir}/../spec/stacktrace_spec.rb:5:in `something_else'",
]

stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a
Expand All @@ -112,7 +109,6 @@
{ file: "/foo/bar/other_vendor/lib/dont.rb", lineNumber: 2, method: "to_s" },
{ file: "/foo/bar/vendor/lib/ignore_me.rb", lineNumber: 3, method: "to_s" },
{ file: "/foo/bar/.bundle/lib/ignore_me.rb", lineNumber: 4, method: "to_s" },
{ file: "#{dir}/../spec/stacktrace_spec.rb", lineNumber: 5, method: "something_else" },
])
end

Expand Down Expand Up @@ -140,20 +136,22 @@
configuration = Bugsnag::Configuration.new
configuration.send_code = false

dir = File.dirname(__FILE__)

backtrace = [
"./spec/spec_helper.rb:1:in `something'",
"./lib/bugsnag/breadcrumbs/../configuration.rb:100:in `to_s'",
"lib/bugsnag.rb:20:in `notify'",
"#{dir}/../spec/stacktrace_spec.rb:5:in `something_else'",
]

stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a

dir = File.dirname(__FILE__)

expect(stacktrace).to eq([
{ file: "#{dir}/spec_helper.rb", lineNumber: 1, method: "something" },
{ file: "#{File.dirname(dir)}/lib/bugsnag/configuration.rb", lineNumber: 100, method: "to_s" },
{ file: "#{File.dirname(dir)}/lib/bugsnag.rb", lineNumber: 20, method: "notify" },
{ file: "#{dir}/stacktrace_spec.rb", lineNumber: 5, method: "something_else" },
])
end
end
Expand Down