Skip to content

Conversation

@kyleburgess2025
Copy link
Contributor

@kyleburgess2025 kyleburgess2025 commented Dec 8, 2025

Before this change, mongoid logs 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 platform field 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"

@kyleburgess2025 kyleburgess2025 requested a review from a team as a code owner December 8, 2025 15:23
@kyleburgess2025 kyleburgess2025 marked this pull request as draft December 8, 2025 15:23
Copy link

Copilot AI left a 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_ENGINE and RUBY_ENGINE_VERSION for 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.
Copy link

Copilot AI Dec 8, 2025

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).'

Copilot uses AI. Check for mistakes.
# @return [ true | false ] whether the runtime is JRuby or not.
def jruby?
BSON::Environment.jruby?
# @return [ Boolean ] whether the current runtime is Ruby
Copy link

Copilot AI Dec 8, 2025

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.

Copilot uses AI. Check for mistakes.
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/
Copy link
Contributor Author

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

@kyleburgess2025 kyleburgess2025 marked this pull request as ready for review December 8, 2025 22:01
@kyleburgess2025 kyleburgess2025 requested a review from jamis December 8, 2025 22:01
@comandeo-mongo comandeo-mongo changed the title RUBY-3714Client metadata capture for TruffleRuby RUBY-3714 Client metadata capture for TruffleRuby Dec 9, 2025
# Queries whether the current runtime is standard Ruby or not.
#
# @return [ Boolean ] whether the current runtime is standard Ruby
def ruby?
Copy link
Contributor

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.

Suggested change
def ruby?
def mri?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

Comment on lines 54 to 62
def engine_name
case RUBY_ENGINE
when 'jruby'
'JRuby'
when 'truffleruby'
'TruffleRuby'
else
RUBY_ENGINE
end
Copy link
Contributor

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
end

It really comes down to personal preference, though. Optimize for happiness. :D

Copy link
Contributor Author

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}",
Copy link
Contributor

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 ☝️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@kyleburgess2025 kyleburgess2025 requested a review from jamis December 9, 2025 16:17
Copy link
Contributor

@jamis jamis left a 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. 👍

@kyleburgess2025 kyleburgess2025 merged commit ed49a89 into mongodb:master Dec 9, 2025
164 of 167 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants