Skip to content
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

Fix instrumentation of custom cache stores #3206

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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