Skip to content

Commit

Permalink
Fix instrumentation of custom cache stores (#3206)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco Costa <[email protected]>
Co-authored-by: marcotc <[email protected]>
  • Loading branch information
3 people authored and ekump committed Oct 25, 2023
1 parent 9be8eae commit f467dc7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def dd_store_name

# DEV: String#underscore is available through ActiveSupport, and is
# DEV: the exact reverse operation to `#camelize`.
@store_name = self.class.name.underscore.match(%r{active_support/cache/(.*)})[1]
# DEV: String#demodulize is available through ActiveSupport, and is
# DEV: used to remove the module ('*::') part of a constant name.
@store_name = self.class.name.demodulize.underscore
end
end

Expand Down
20 changes: 20 additions & 0 deletions spec/datadog/tracing/contrib/rails/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
end
end

context 'with a cache not in the ActiveSupport::Cache:: namespace' do
let(:cache_class) { stub_const('My::CustomCache', Class.new(ActiveSupport::Cache::MemoryStore)) }
let(:cache) { cache_class.new }

it 'returns the matching backend type' do
subject
expect(spans[0].get_tag('rails.cache.backend')).to eq('custom_cache')
end
end

context 'with an unnamespaced cache class' do
let(:cache_class) { stub_const('CustomCache', Class.new(ActiveSupport::Cache::MemoryStore)) }
let(:cache) { cache_class.new }

it 'returns the matching backend type' do
subject
expect(spans[0].get_tag('rails.cache.backend')).to eq('custom_cache')
end
end

it_behaves_like 'measured span for integration', false do
before { subject }
let(:span) { spans[0] }
Expand Down

0 comments on commit f467dc7

Please sign in to comment.