diff --git a/lib/mongo/client.rb b/lib/mongo/client.rb index 1b8df236f0..1a398b6317 100644 --- a/lib/mongo/client.rb +++ b/lib/mongo/client.rb @@ -48,6 +48,7 @@ class Client :min_pool_size, :monitoring, :password, + :platform, :read, :read_retry_interval, :replica_set, @@ -200,10 +201,10 @@ def hash # certification authority certifications used to validate certs passed from the # other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or # :ssl_ca_cert_object (in order of priority) is required for :ssl_verify. - # @option options [ Array ] :ssl_ca_cert_object An array of OpenSSL::X509::Certificate - # reprenting the certification authority certifications used to validate certs passed from the - # other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or - # :ssl_ca_cert_object (in order of priority) is required for :ssl_verify. + # @option options [ Array ] :ssl_ca_cert_object An array of + # OpenSSL::X509::Certificate representing the certification authority certifications used + # to validate certs passed from the other end of the connection. One of :ssl_ca_cert, + # :ssl_ca_cert_string or :ssl_ca_cert_object (in order of priority) is required for :ssl_verify. # @option options [ Float ] :socket_timeout The timeout, in seconds, to # execute operations on a socket. # @option options [ String ] :user The user name. @@ -222,6 +223,8 @@ def hash # for documents. Must respond to #generate. # @option options [ String, Symbol ] :app_name Application name that is printed to the # mongod logs upon establishing a connection in server versions >= 3.4. + # @option options [ String ] :platform Platform information to include in the + # metadata printed to the mongod logs upon establishing a connection in server versions >= 3.4. # # @since 2.0.0 def initialize(addresses_or_uri, options = Options::Redacted.new) diff --git a/lib/mongo/cluster/app_metadata.rb b/lib/mongo/cluster/app_metadata.rb index 0feacb01b7..38db8e30e4 100644 --- a/lib/mongo/cluster/app_metadata.rb +++ b/lib/mongo/cluster/app_metadata.rb @@ -53,6 +53,7 @@ class AppMetadata # @since 2.4.0 def initialize(cluster) @app_name = cluster.options[:app_name] + @platform = cluster.options[:platform] end # Get the bytes of the ismaster message including this metadata. @@ -133,7 +134,12 @@ def architecture end def platform - [RUBY_VERSION, RUBY_PLATFORM, RbConfig::CONFIG['build']].join(', ') + [ + @platform, + RUBY_VERSION, + RUBY_PLATFORM, + RbConfig::CONFIG['build'] + ].compact.join(', ') end end end diff --git a/spec/mongo/client_spec.rb b/spec/mongo/client_spec.rb index dbf2995184..10c441b29c 100644 --- a/spec/mongo/client_spec.rb +++ b/spec/mongo/client_spec.rb @@ -271,6 +271,44 @@ expect(client.cluster.options[:heartbeat_frequency]).to eq(client.options[:heartbeat_frequency]) end end + + context 'when platform details are specified' do + + let(:app_metadata) do + client.cluster.app_metadata + end + + let(:client) do + described_class.new(['127.0.0.1:27017'], :platform => 'mongoid-6.0.2') + end + + it 'includes the platform info in the app metadata' do + expect(app_metadata.send(:full_client_document)[:platform]).to match(/mongoid-6\.0\.2/) + end + end + + context 'when platform details are not specified' do + + let(:app_metadata) do + client.cluster.app_metadata + end + + let(:client) do + described_class.new(['127.0.0.1:27017']) + end + + let(:platform_string) do + [ + RUBY_VERSION, + RUBY_PLATFORM, + RbConfig::CONFIG['build'] + ].join(', ') + end + + it 'does not include the platform info in the app metadata' do + expect(app_metadata.send(:full_client_document)[:platform]).to eq(platform_string) + end + end end context 'when providing a connection string' do