Skip to content

[IGNORE] PR 6181 - #6206

Draft
vpellan wants to merge 7 commits into
masterfrom
community/pr-6181
Draft

[IGNORE] PR 6181#6206
vpellan wants to merge 7 commits into
masterfrom
community/pr-6181

Conversation

@vpellan

@vpellan vpellan commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

PLEASE DO NOT MERGE

jonthedecepticon and others added 7 commits August 12, 2026 11:58
`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)`.
@dd-octo-sts

dd-octo-sts Bot commented Aug 18, 2026

Copy link
Copy Markdown
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

@dd-octo-sts dd-octo-sts Bot added integrations Involves tracing integrations tracing labels Aug 18, 2026
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Aug 18, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 98.02%
Overall Coverage: 90.29% (+0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 97be35d | Docs | View more details | Give us feedback!

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.

3 participants