-
Notifications
You must be signed in to change notification settings - Fork 598
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
Add Roda instrumentation #2144
Add Roda instrumentation #2144
Conversation
Adds prepend and chaining options for Roda v3.19.0+
lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb
Outdated
Show resolved
Hide resolved
lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb
Outdated
Show resolved
Hide resolved
Original change not required (I didn't catch the ||), but the refactor looks great so we'll keep it.
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com> Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
NewRelic::Agent.stub(:logger, NewRelic::Agent::MemoryLogger.new) do | ||
# Have the #params call made on the request raise an exception to test | ||
# the error handling | ||
RodaTestApp::RodaRequest.any_instance.stubs(:params).raises(StandardError.new) |
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.
Following up on offline discussions on this one...
- Minitest doesn't support (and one might even infer it discourages) the stubbing of any instance
- The
any_instance
here is provided by the Mocha testing gem - Personally I think introducing Mocha to a Minitest based project detracts from the Minitest experience as much as it adds to it. Perhaps it's like adding a sidecar to a motorcycle. It's clear that the sidecar offers a distinct advantage over a motorcycle without a sidecar. But there are also fundamental changes to the motorcycling experience that could be considered as drawbacks.
- Testing any instance is well known anti-pattern given the risk of having stubbing behavior bleed over to other instances in play in a testing context where the stubbing behavior would be problematic.
- The risk is mitigated here in two ways:
- We are assured of only having one Rack request in play during the test.
- We do not (currently) make use of parallelized, concurrent tests.
- The risk is mitigated here in two ways:
- Typically the best practice is to have a handle on the specific instance under test. The need to reach for the stubbing of any instance could itself indicate complexity of code. This complexity might come from not following TDD or could indicate a focus / prioritization on performance over testability. For whatever reason, tests that require stubbing any instance might indicate difficulties in maintainability.
- We use this
any_instance
method quite a lot in this project. It is completely acceptable to use it again here from a PR approval standpoint. The maintainers may at one point decide to dissuade future usage or refactor out existing usage ofany_instance
, but for now there's a green light.- We bring in a RuboCop gem specific to Minitest, but unfortunately given that
any_instance
comes from Mocha, its usage is not flagged by any cops.
- We bring in a RuboCop gem specific to Minitest, but unfortunately given that
- Looking at the context for this exact line of code, the benefit of using
any_instance
is pretty clear. We invoke theRack::Test
get
method, which viaForwardable
goes through theRack::Test
flow of calling the user definedapp
method to get an app class. An instance of that class is instantiated and the request params object is prepped. For us to be able to get at the exact single instance of the class (as opposed to any instance) that will field the web request, we would need to change the overall flow of this test and have it be different from all the others. Perhaps we could stubnew
on the Rack app and use that stubbing for a foothold while retaining the Rack test integration style of usingget
. Alternatively, we could have this test not leverageRack::Test
and we could instead directly invoke therack_request_params
method being tested. (We'd use a unit test instead of an integration test). The benefits of having this test look and act like the others is a pretty clear advantage ofany_instance
.
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.
Thanks for the detailed thoughts—loving the motorcycle analogy. I agree it's weird to mix Mocha and Minitest. I've updated this and to go with the unit-style test— just calling rack_request_params
directly, which is going to fail since no Rack request will be in existence.
Updating our codebase to get rid of any_instance
would be a fun project. I think it would help with learning.
Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com>
lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb
Outdated
Show resolved
Hide resolved
…r.rb Co-authored-by: James Bunch <fallwith@gmail.com>
SimpleCov Report
|
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.
Great work, Hannah!
Adds instrumentation for Roda versions 3.19.0+. Roda will be automatically detected and instrumented.
closes #1783