-
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
[rails] Redis instrumentation follows users settings #86
Conversation
df585ec
to
d3dcc88
Compare
faae17b
to
b9496a8
Compare
assert_equal(true, Rails.cache.respond_to?(:data), "cache '#{Rails.cache}' has no data") | ||
pin = Datadog::Pin.get_from(Rails.cache.data) | ||
|
||
# get the Redis pin accessing private methods (only Rails 3.x) |
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.
it's reasonable to do that in a test
::Rails.cache.is_a?(::ActiveSupport::Cache::RedisStore) | ||
Datadog::Tracer.log.debug('Enabling auto-instrumentation for redis-rails connector') | ||
|
||
# backward compatibility: Rails 3.x doesn't have `cache=` method |
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.
Rails 3.x relies in a RAILS_CACHE
global; Rails > 3 deprecated this global in favor of a plain Rails.cache
…ld in early versions
@@ -1,15 +0,0 @@ | |||
module RedisStoreDataAccessor |
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.
had to remove this one because it was obfuscating how Rails 3.x works with cache. Think it should be fine now 👍
# We include 'redis-rails' here if it's available, doing it later | ||
# (typically in initialize callback) does not work, it does not | ||
# get loaded in the right context. | ||
require 'redis-rails' |
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.
we don't need to import that here, because it will be available after cache initialization (if present)
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.
LGTM! This should indeed be much less error-prone than the previous impl.
What it does
In the previous implementation Redis is automatically instrumented despite users settings. This caused many issues when the
Rails
module is available but you're running external components (i.e.rake
orSidekiq
).before_configuration
hookafter_initialize
hook, so users' settings defined in the tracing initializer are honoreddebug
logRelated to