-
Notifications
You must be signed in to change notification settings - Fork 174
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
Conversation
This allows developers to set the vendor path regular expression, used to determine whether or not a line in the stacktrace appears in the project stacktrace or the full trace. ```ruby Bugsnag.configure do |config| config.vendor_path = /(^(vendor\/|\.bundle\/|extensions\/|private_gems\/))/ end ``` By default, lines within `vendor/` or `.bundle/` are consider “out of project”. This is a good default for most Rails projects but there are other directories we’d also like to ignore. For example, patches to gems or the framework. If left as “in project”, these lines cause multiple issues to be grouped together because the first line in the stacktrace always points to the same patch line. Right now, we’ve side stepped this by reaching into the gem and redefining `Bugsnag::Stacktrace::VENDOR_PATH` but it would be wonderful if this was a configurable option like any other.
7659168
to
b7fae15
Compare
CI failure seems unrelated to this changeset:
The last time master was built, it used redis 4.1.1. Since then redis 4.1.2 has been released, which explictly drops support for Ruby 2.2. |
I fixed the Ruby 2.2 + redis gem issue in #546 so you can merge master into your branch to fix it if you want. However, new features go into the |
lib/bugsnag/configuration.rb
Outdated
@@ -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 within the project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if an @return
comment makes sense for an attr_writer
.
However, you can change the next line to attr_accessor
(so an @return
comment would be fine), and in #initialize
set @vendor_path
to the default regular expression.
lib/bugsnag/configuration.rb
Outdated
## | ||
# Regex used to mark stacktrace lines as within the project. Lines marked | ||
# as "out of project" will only appear in the full trace. | ||
def vendor_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an @return
comment (or not if you choose to use attr_accessor
instead and set it to the default in initialize)
lib/bugsnag/configuration.rb
Outdated
# Regex used to mark stacktrace lines as within the project. Lines marked | ||
# as "out of project" will only appear in the full trace. | ||
def vendor_path | ||
@vendor_path || Bugsnag::Stacktrace::VENDOR_PATH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving/renaming Bugsnag::Stacktrace::VENDOR_PATH
to Bugsnag::Configuration::DEFAULT_VENDOR_PATH
, as it is now a default, and it might be easier for users to find/discover this constant in Bugsnag::Configuration
in case they need to use this regular expression to add to it for a new vendor path regular expression (maybe using something like Regexp.union
).
spec/configuration_spec.rb
Outdated
@@ -396,4 +396,15 @@ def debug(name, &block) | |||
expect(second_array).to eq([1, 2]) | |||
end | |||
end | |||
|
|||
describe "vendor_path" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#vendor_path
(with the #
since it is an instance method)
spec/stacktrace_spec.rb
Outdated
@@ -87,4 +87,43 @@ | |||
}) | |||
} | |||
end | |||
|
|||
describe "#vendor_cache" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this doc string, as there isn't a vendor_cache
instance method, and the tests don't appear to be related to caching.
spec/configuration_spec.rb
Outdated
@@ -396,4 +396,15 @@ def debug(name, &block) | |||
expect(second_array).to eq([1, 2]) | |||
end | |||
end | |||
|
|||
describe "vendor_path" do | |||
it "should have the default vendor path" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to avoid "should" in doc strings (https://github.com/rubocop-hq/rspec-style-guide#should-in-example-docstrings), mainly to avoid repeating it a lot (similar comment for line 405)
CHANGELOG.md
Outdated
|
||
### Enhancements | ||
|
||
* Add option to configure what file paths are included in the project stacktrace (`vendor_path`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem clear, as all the file paths are usually included in the stacktrace. I would reword this to something like "Add option (vendor_path
) to adjust filename matching for marking stackframes as in-project".
I updated the next branch and changed the base branch of this pull request to next. @jnraine Can you update this when you get the chance? |
This option was present in 5.5 and was removed without giving any reason. #253. It used to allow arrays, and I believe it still should since you can have more than 1 vendor path. |
@tedyangx / @mctaylorpants, can you take this to completion? It'll let you drop a monkey patch from the codebase. 😄 |
@jnraine yep we can take a look! Are you able to give us write access to your fork? |
@mctaylorpants Done! Thanks for taking a look. |
…uration (and rename it to DEFAULT_VENDOR_PATH). 2. Add `attr_accessor :vendor_path` to Bugsnag::Configuration and initialize it with DEFAULT_VENDOR_PATH.
…onfiguration::DEFAULT_VENDOR_PATH
25534d3
to
a1a9fde
Compare
@tobyhs @tomlongridge I have addressed the review comments and updated the pull request. Much appreciated if you can review this. Thanks! |
@tedyangx : I no longer work at Bugsnag, so I won't be able to merge this. |
Thank @tedyangx - we'll take a look. |
Raised separate PR with these changes - #583 - to enable CI to run. |
Goal
By default, lines within
vendor/
or.bundle/
are consider “out of project”. This is a good default for most Rails projects but there are other directories we’d also like to ignore. For example, patches to gems or the framework. If left as “in project”, these lines cause multiple issues to be grouped together because the first line in the stacktrace always points to the same patch line.Right now, we’ve side stepped this by reaching into the gem and redefining
Bugsnag::Stacktrace::VENDOR_PATH
but it would be wonderful if this was a configurable option like any other.Changeset
Added
vendor_path
can now be configured.This allows developers to set the vendor path regular expression, used to determine whether or not a line in the stacktrace appears in the project stacktrace or the full trace.
Tests
Bugsnag::Stacktrace
.Discussion
Outstanding Questions
Should the name of the configuration option be changed? Instead of
vendor_path
, perhapsproject_file_pattern
or similar.Review
For the submitter, initial self-review:
Commented on code changes inline explain the reasoning behind the approachn/aFor the pull request reviewer(s), this changeset has been reviewed for: