-
Notifications
You must be signed in to change notification settings - Fork 534
RUBY-3714 Client metadata capture for TruffleRuby #2971
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the platform detection logic to generalize runtime identification beyond JRuby. Instead of specifically checking for JRuby, the code now identifies whether the runtime is standard Ruby (MRI) and handles all other Ruby implementations (including JRuby and TruffleRuby) generically using RUBY_ENGINE and RUBY_ENGINE_VERSION constants.
Key changes:
- Replaced JRuby-specific detection with generic Ruby engine detection
- Updated version reporting to use
RUBY_ENGINEandRUBY_ENGINE_VERSIONfor non-MRI runtimes
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| end | ||
|
|
||
| # Queries whether the current runtime is JRuby or not. | ||
| # Queries whether the current runtime is Ruby or not. |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is unclear. Since this method is always called within a Ruby runtime, it should clarify that it checks for standard Ruby/MRI specifically, not whether Ruby is running. Consider: 'Queries whether the current runtime is standard Ruby (MRI).'
| # @return [ true | false ] whether the runtime is JRuby or not. | ||
| def jruby? | ||
| BSON::Environment.jruby? | ||
| # @return [ Boolean ] whether the current runtime is Ruby |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value documentation is incomplete and unclear. It should specify 'whether the current runtime is standard Ruby (MRI)' to distinguish from other Ruby implementations.
spec/support/shared/app_metadata.rb
Outdated
| document[:client][:driver][:name].should == 'mongo-ruby-driver|' | ||
| document[:client][:driver][:version].should == "#{Mongo::VERSION}|" | ||
| document[:client][:platform].should =~ /\AJ?Ruby[^|]+\|\z/ | ||
| document[:client][:platform].should =~ /\Aj?[Rr]uby[^|]+\|\z/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this regex because the output of RUBY_ENGINE is all lowercase. Other potential solutions:
- Make this entire regex case-insensitive - decided against this because I'd prefer to tests as specific as possible
- Change "Ruby" to "ruby" in the platform metadata - would make the logging look more similar to logging for jruby and truffleruby, but seems unnecessary
- Capitalize JRuby and TruffleRuby - would look nicer, but seems unnecessary. Plus, would have to be implemented for each engine we support... for now, it's just JRuby, TruffleRuby, and standard Ruby, but in the future this list could grow
| # Queries whether the current runtime is standard Ruby or not. | ||
| # | ||
| # @return [ Boolean ] whether the current runtime is standard Ruby | ||
| def ruby? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"mri" ("matz's ruby implementation") is how the canonical implementation is usually called. It might be better to name this predicate mri? to reflect that, since ruby? is probably overly broad.
| def ruby? | |
| def mri? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
| def engine_name | ||
| case RUBY_ENGINE | ||
| when 'jruby' | ||
| 'JRuby' | ||
| when 'truffleruby' | ||
| 'TruffleRuby' | ||
| else | ||
| RUBY_ENGINE | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This absolutely works, and is valid. Another approach that is frequently used in Ruby programs is to use a Hash to store all of the known options, and query it in the method. E.g.
ENGINE_NAMES = { 'jruby' => 'JRuby', 'truffleruby' => 'TruffleRuby' }.freeze
def engine_name
ENGINE_NAMES[RUBY_ENGINE] || RUBY_ENGINE
endIt really comes down to personal preference, though. Optimize for happiness. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like the hash better! replaced : )
| let(:platform_string) do | ||
| [ | ||
| "JRuby #{JRUBY_VERSION}", | ||
| "jruby #{JRUBY_VERSION}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to teach the tests the proper case on the engine names ☝️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
jamis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
The failing tests appear to be due to infrastructure issues (Atlas not responding in time to create a cluster to test against, and another where the test seems to be hanging). Don't worry about them for now; we'll keep an eye on them in subsequent PRs and see if there's a pattern. 👍
Before this change,
mongoidlogs included only whether the engine was JRuby or not - other engines, such as truffleruby, were not specified (see https://jira.mongodb.org/browse/RUBY-3714). After this change, the Ruby engine is included in the logs. No testing has been added as of yet for this change.Below are the Ruby engines tested with the change, along with their values in the
platformfield of log metadata.truffleruby+graalvm-25.0.0:
"truffleruby 25.0.0, like Ruby 3.3.7, arm64-darwin20, arm64-unknown-darwin, A"3.2.6:
"Ruby 3.2.6, arm64-darwin25, aarch64-apple-darwin25.1.0, M"jruby-10.0.2.0:
"jruby 10.0.2.0, like Ruby 3.4.2, java, JVM 25.0.1, java21, A"