Skip to content

Commit

Permalink
Instrument cache store name
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Oct 21, 2020
1 parent 7cc2b57 commit 6fa747f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/cache.rb
Expand Up @@ -715,7 +715,7 @@ def instrument(operation, key, options = nil)
logger.debug "Cache #{operation}: #{normalize_key(key, options)}#{options.blank? ? "" : " (#{options.inspect})"}"
end

payload = { key: key }
payload = { key: key, store: self.class.name }
payload.merge!(options) if options.is_a?(Hash)
ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload) { yield(payload) }
end
Expand Down
Expand Up @@ -32,6 +32,7 @@ def test_instrumentation_with_fetch_multi_as_super_operation
assert_equal :fetch_multi, events[0].payload[:super_operation]
assert_equal ["a", "b"], events[0].payload[:key]
assert_equal ["b"], events[0].payload[:hits]
assert_equal @cache.class.name, events[0].payload[:store]
end

def test_instrumentation_empty_fetch_multi
Expand All @@ -43,6 +44,7 @@ def test_instrumentation_empty_fetch_multi
assert_equal :fetch_multi, events[0].payload[:super_operation]
assert_equal [], events[0].payload[:key]
assert_equal [], events[0].payload[:hits]
assert_equal @cache.class.name, events[0].payload[:store]
end

def test_read_multi_instrumentation
Expand All @@ -55,6 +57,7 @@ def test_read_multi_instrumentation
assert_equal %w[ cache_read_multi.active_support ], events.map(&:name)
assert_equal ["a", "b"], events[0].payload[:key]
assert_equal ["b"], events[0].payload[:hits]
assert_equal @cache.class.name, events[0].payload[:store]
end

def test_empty_read_multi_instrumentation
Expand All @@ -65,6 +68,7 @@ def test_empty_read_multi_instrumentation
assert_equal %w[ cache_read_multi.active_support ], events.map(&:name)
assert_equal [], events[0].payload[:key]
assert_equal [], events[0].payload[:hits]
assert_equal @cache.class.name, events[0].payload[:store]
end

private
Expand Down

0 comments on commit 6fa747f

Please sign in to comment.