[PROF-15076] Fix GC profiling being disabled on Ruby 3.2.10/3.2.11#5894
Conversation
**What does this PR do?**
This PR introduces a new `RubyVersion` helper and moves profiling code
to use it.
This fixes a bug with our GC profiling logic testing using
strings directly, and `3.2.10`/`3.2.11` are unfortunately `< "3.2.3"`,
e.g.:
```ruby
if ...
(RUBY_VERSION.start_with?("3.2.") && RUBY_VERSION < "3.2.3")
logger.warn(
"Current Ruby version (#{RUBY_VERSION}) has a VM bug where enabling GC profiling would cause " \
"crashes (https://bugs.ruby-lang.org/issues/18464). GC profiling has been disabled."
)
```
**Motivation:**
Fix feature being mistakenly broken on latest Ruby patch versions.
**Additional Notes:**
I admit I knew about this footgun, but there hadn't been .10 and above
releases in a while and I kinda disliked the verboseness of doing the
check using `Gem::Version` or the like.
With the addition of the helper, we can do it correctly and cleanly.
I've also changed every other use in profiling of `RUBY_VERSION`.
**How to test the change?**
This change has test coverage.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 632246f1cc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 8f3d166 | Docs | Datadog PR Page | Give us feedback! |
eregon
left a comment
There was a problem hiding this comment.
Good cleanup but I'm not very fond of ~> it's quite verbose (needs an extra digit when most cases want to check e.g. >= A.B) and error-prone (e.g. when forgetting to add the extra digit) and probably quite slow.
I'd prefer something like if RubyVersion >= 3.4/if RubyVersion >= [3, 4]/if RubyVersion >= "3.4"
|
Thinking out loud, for cases like if RubyVersion.between?("3.1.0", "3.1.2") # There is Comparable#between? which we might be able to reuse
if RubyVersion.in?("3.1.0".."3.1.2")Though just this is fine too: if RubyVersion >= "3.1.0" && RubyVersion <= "3.1.2"((or (ab)use the fact such checks are typically single-digits and |
I agree; yet, when I looked at it, I think we have less than 5? 10? of those, so having the extra helper didn't seem worth the extra code. |
Co-authored-by: Benoit Daloze <[email protected]>
BenchmarksBenchmark execution time: 2026-06-15 16:42:52 Comparing candidate commit b7af24e in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 1 unstable metrics.
|
**What does this PR do?** In #5894 we added a new `RubyVersion` helper to have a short and always-correct way of guarding code that needs to behave differently across Ruby versions. In that PR I deliberately did not touch code outside of profiling, and this is the follow-up that adds the helper to the rest of dd-trace-rb. **Motivation:** Standardize on `RubyVersion` as the common way of testing `RUBY_VERSION`. **Additional Notes:** N/A **How to test the change?** This change is covered by the existing tests.
What does this PR do?
This PR introduces a new
RubyVersionhelper and moves profiling code to use it.This fixes a bug with our GC profiling logic testing using strings directly, and
3.2.10/3.2.11are unfortunately< "3.2.3", e.g.:Motivation:
Fix feature being mistakenly broken on latest Ruby patch versions.
Change log entry
Yes. Fix GC profiling being disabled on Ruby 3.2.10/3.2.11
Additional Notes:
I admit I knew about this footgun, but there hadn't been .10 and above releases in a while and I kinda disliked the verboseness of doing the check using
Gem::Versionor the like.With the addition of the helper, we can do it correctly and cleanly.
I've also changed every other use in profiling of
RUBY_VERSION.I'm preparing a follow-up PR to change this in more places in dd-trace-rb, but wanted to get this out as a smaller fix first.
Finally, I've split the change into step-by-step commits, and I recommend reviewing commit-by-commit.
How to test the change?
This change has test coverage.