Skip to content

Commit

Permalink
Fix instrumentation of custom cache stores (#3206) (#3227)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Griffith <[email protected]>
Co-authored-by: Marco Costa <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2023
1 parent 423c123 commit 43e1864
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 43e1864

Please sign in to comment.