[IGNORE] PR 6181 - #6206
Draft
vpellan wants to merge 7 commits into
Draft
Conversation
`rails.cache.key` carries the key the user supplied, before Rails prefixes the store namespace onto it while normalizing. For a store configured with a namespace the tag is therefore ambiguous: `Rails.cache` with `namespace: "my_model"` reports `key: 123` for a key that is really `my_model:123`. Add a `rails.cache.namespace` tag, set from the same options Rails resolves the namespace from, on both the event-based and the legacy monkey-patched paths. Callable namespaces are resolved, and options passed to the call take precedence over the ones the store was configured with, matching `ActiveSupport::Cache::Store#namespace_key`. ActiveSupport only forwards the call options to the `delete` event since Rails 8, so the namespace is backfilled from the store on older versions to keep the tag consistent across the supported range.
Do not resolve callable namespaces. Rails resolves them while normalizing the key, and instrumentation was calling them a second time, in the legacy paths before Rails did. A callable namespace is now left untagged. Read the namespace of a `read_multi` call from its trailing options hash, which Rails accepts alongside the keyword form. It was being left in the keys while the tag fell back to the namespace of the store. Carry the namespace of a `delete` call from `#delete` itself on Rails < 8, where the event payload has neither the store options nor the ones given to the call. The backfill reported the namespace of the store even when the call overrode it or disabled it with `namespace: nil`.
Record what ActiveSupport resolves the namespace to while normalizing the key, so a callable namespace is reported without instrumentation invoking it. `#namespace_key`, present since Rails 5.2, is the single place the namespace is applied, so the resolved value is the prefix it adds. `#delete` on Rails < 8 is the one operation left out: its event carries no options, and putting the callable in the payload would let Rails' debug logging invoke it a second time.
`Layout/EmptyLinesAroundAccessModifier` wants a blank line before `private` when a comment precedes it. Move the note into the module doc instead.
Rename `tag_cache_key` to `cache_key_enabled` and `set_cache_namespace` to
`set_cache_namespace_tag`, so both names describe what they actually hold and do.
Drop the comments that restate the code, keeping only the note on how
`#namespace_key` makes the resolved namespace recoverable.
Type the two thread-local keys as `String` and `Cache.on_finish` as `void`.
Inline the callable namespace setup back into each spec context, and assert the
absence of the tag with `change {}.from(nil)`.
Contributor
|
👋 Hey @DataDog/ruby-guild, please fill "Change log entry" section in the pull request description. If changes need to be present in CHANGELOG.md you can state it this way **Change log entry**
Yes. A brief summary to be placed into the CHANGELOG.md(possible answers Yes/Yep/Yeah) Or you can opt out like that **Change log entry**
None.(possible answers No/Nope/None) Visited at: 2026-08-18 13:39:19 UTC |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 97be35d | Docs | View more details | Give us feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PLEASE DO NOT MERGE