Skip to content

ActiveSupport::Cache integration does not support multiple cache backends #3549

Closed

Description

Current behaviour
If redis-activesupport is present, then only ActiveSupport::Cache::RedisStore is patched (for methods that it has), and ActiveSupport::Cache::Store is not patched.

def patch_redis?(meth)
!Gem.loaded_specs['redis-activesupport'].nil? \
&& defined?(::ActiveSupport::Cache::RedisStore) \
&& ::ActiveSupport::Cache::RedisStore.instance_methods(false).include?(meth)
end
def cache_store_class(meth)
if patch_redis?(meth)
::ActiveSupport::Cache::RedisStore
else
super
end
end
end

Expected behaviour
ActiveSupport::Cache::Store is always patched, because it may be used with cache backends other than redis.

Steps to reproduce

  • Create an application with with redis-activesupport present
  • Create a cache using a non-redis backend (eg ActiveSupport::Cache::MemCacheStore)
  • Note that cache writes are not instrumented (because we didn't patch the :write method of ActiveSupport::Cache::Store)

One solution could be to patch multiple classes - ie if redis is present and defines the method, patch both classes, rather than one or the other.

Environment

  • ddtrace version: 1.12
  • Configuration block (Datadog.configure ...):
  • Ruby version: 3.0.6
  • Operating system: Linux
  • Relevant library versions:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugInvolves a bugcommunityWas opened by a community member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions