Skip to content

Add Rails cache store instrumentation filter #4693

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented May 28, 2025

What does this PR do?

This PR introduces a new :cache_store configuration option to the ActiveSupport integration. This option allows users to specify which cache stores should be instrumented by Datadog tracing.

Motivation:

This is important for very fast backends, like MemoryStore, which might not provide useful spans.

Change log entry
Yes. Add :cache_store option to ActiveSupport integration to allow tracing only specified cache backends.

Additional Notes:

  • The option accepts both strings and symbols (e.g., ['file_store', :memory_store]).
  • The default remains unchanged: all cache stores are traced unless this option is set.

How to test the change?

  • Run the test suite, especially the integration tests for ActiveSupport cache instrumentation.
  • Tests cover scenarios where :cache_store includes, excludes, or is unset for various backends.
  • Manual validation: configure Datadog.configure { |c| c.tracing.instrument :active_support, cache_store: [:file_store] } and verify that only the specified store is traced.

@marcotc marcotc self-assigned this May 28, 2025
@marcotc marcotc requested review from a team as code owners May 28, 2025 19:31
@github-actions github-actions bot added integrations Involves tracing integrations tracing labels May 28, 2025
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.64%. Comparing base (b76fbae) to head (c1ef3f8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4693   +/-   ##
=======================================
  Coverage   97.64%   97.64%           
=======================================
  Files        1470     1470           
  Lines       87707    87742   +35     
  Branches     4547     4551    +4     
=======================================
+ Hits        85644    85680   +36     
+ Misses       2063     2062    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1
Copy link
Contributor

Datadog Report

Branch report: mem-store
Commit report: c1ef3f8
Test service: dd-trace-rb

✅ 0 Failed, 21505 Passed, 1298 Skipped, 4m 7.22s Total Time

Copy link

@drichards-87 drichards-87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a suggestion from Docs and approved the PR.

@@ -552,6 +552,7 @@ cache.read('city')
| --------------- | - | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| `enabled` | `DD_TRACE_ACTIVE_SUPPORT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` |
| `cache_service` | | `String` | Name of application running the `active_support` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `active_support-cache` |
| `cache_store` | | `Array` | Specifies which cache stores to instrument. Accepts a list of store names (e.g. `memory_store`, `file_store`, or symbols like `:file_store`). If set, only the listed stores will be traced. By default (`nil`), it traces all stores. | `nil` |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `cache_store` | | `Array` | Specifies which cache stores to instrument. Accepts a list of store names (e.g. `memory_store`, `file_store`, or symbols like `:file_store`). If set, only the listed stores will be traced. By default (`nil`), it traces all stores. | `nil` |
| `cache_store` | | `Array` | Specifies which cache stores to instrument. Accepts an array of store names such as `memory_store`, `file_store`, or symbols like `:file_store`. If set, only the listed stores are traced. Defaults to `nil`, which traces all stores. | `nil` |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the option be in plural, i.e. cache_stores?

@pr-commenter
Copy link

pr-commenter bot commented May 28, 2025

Benchmarks

Benchmark execution time: 2025-05-28 19:56:58

Comparing candidate commit c1ef3f8 in PR branch mem-store with baseline commit b76fbae in branch master.

Found 1 performance improvements and 2 performance regressions! Performance is the same for 37 metrics, 5 unstable metrics.

scenario:profiling - Allocations ()

  • 🟥 throughput [-228345.230op/s; -214478.555op/s] or [-6.843%; -6.428%]

scenario:tracing - Propagation - Trace Context

  • 🟩 throughput [+3965.800op/s; +4080.838op/s] or [+11.843%; +12.187%]

scenario:tracing - Tracing.log_correlation

  • 🟥 throughput [-10132.400op/s; -9842.014op/s] or [-9.217%; -8.952%]

@@ -552,6 +552,7 @@ cache.read('city')
| --------------- | - | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| `enabled` | `DD_TRACE_ACTIVE_SUPPORT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` |
| `cache_service` | | `String` | Name of application running the `active_support` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `active_support-cache` |
| `cache_store` | | `Array` | Specifies which cache stores to instrument. Accepts a list of store names (e.g. `memory_store`, `file_store`, or symbols like `:file_store`). If set, only the listed stores will be traced. By default (`nil`), it traces all stores. | `nil` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the option be in plural, i.e. cache_stores?

o.type :array, nilable: true
o.default nil
o.after_set do |stores|
stores&.map!(&:to_s) # Convert symbols to strings to match the Rails configuration format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the customer-supplied array duped during assignment? Otherwise this would mutate their data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants