-
Notifications
You must be signed in to change notification settings - Fork 375
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
Change the Redis client patch to use prepend #1743
Change the Redis client patch to use prepend #1743
Conversation
The current Redis patch uses alias_method which can cause conflicts with other libraries that use prepend to patch the same methods. This change moves the existing implementation to a separate Implementation module and uses prepend to patch methods instead of alias_method. Fixes #1686
end | ||
|
||
# InstanceMethods - implementing instrumentation | ||
module InstanceMethods |
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.
The code in this module was moved verbatim from the patcher module except for the changes:
- replaced "without" method calls with super
- removed calls to alias_method and remove_method
module Contrib | ||
module Redis | ||
# Instrumentation for Redis | ||
module Instrumentation |
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.
The pattern for this module and the patcher module are copied from the http patcher.
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 should be fine.
|
||
RSpec.describe Datadog::Contrib::Redis::Patcher do | ||
describe '.patch' do | ||
it 'adds Instrumentation methods to ancestors of Redis class' 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.
This spec pattern is from the ethon patch
Codecov Report
@@ Coverage Diff @@
## master #1743 +/- ##
==========================================
- Coverage 98.18% 98.18% -0.01%
==========================================
Files 934 935 +1
Lines 45196 45191 -5
==========================================
- Hits 44374 44369 -5
Misses 822 822
Continue to review full report at Codecov.
|
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.
Seems like a pretty straightforward change. Mirrors our other prepend
implementations, tests are passing. Looks fine to me!
Thanks for sharing this!
module Contrib | ||
module Redis | ||
# Instrumentation for Redis | ||
module Instrumentation |
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 should be fine.
Thank you again, @justinhoward! 🙇 |
👋 Thank you again @justinhoward, https://github.com/DataDog/dd-trace-rb/releases/tag/v0.54.0 was just released, including this change. |
The current Redis patch uses alias_method which can cause conflicts with other libraries that use prepend to patch the same methods. This change moves the existing implementation to a separate Implementation module and uses prepend to patch methods instead of alias_method.
Fixes #1686