File tree Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ class Client
4747 :max_read_retries ,
4848 :min_pool_size ,
4949 :monitoring ,
50+ :odm_name ,
51+ :odm_version ,
5052 :password ,
5153 :read ,
5254 :read_retry_interval ,
@@ -222,6 +224,11 @@ def hash
222224 # for documents. Must respond to #generate.
223225 # @option options [ String, Symbol ] :app_name Application name that is printed to the
224226 # mongod logs upon establishing a connection in server versions >= 3.4.
227+ # @option options [ String, Symbol ] :odm_name ODM name that is printed to the
228+ # mongod logs upon establishing a connection in server versions >= 3.4.
229+ # @option options [ String, Symbol ] :odm_version ODM version that is printed to the
230+ # mongod logs upon establishing a connection in server versions >= 3.4. Note that the
231+ # ODM version will only be included if an ODM name is also provided.
225232 #
226233 # @since 2.0.0
227234 def initialize ( addresses_or_uri , options = Options ::Redacted . new )
Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ class AppMetadata
5353 # @since 2.4.0
5454 def initialize ( cluster )
5555 @app_name = cluster . options [ :app_name ]
56+ @odm_name = cluster . options [ :odm_name ]
57+ @odm_version = cluster . options [ :odm_version ]
5658 end
5759
5860 # Get the bytes of the ismaster message including this metadata.
@@ -108,7 +110,16 @@ def driver_doc
108110 {
109111 name : DRIVER_NAME ,
110112 version : Mongo ::VERSION
111- }
113+ } . tap do |doc |
114+ doc . merge! ( odm : odm_doc ) if odm_doc
115+ end
116+ end
117+
118+ def odm_doc
119+ @odm_doc ||= if @odm_name
120+ doc = { name : @odm_name }
121+ @odm_version ? doc . merge! ( version : @odm_version ) : doc
122+ end
112123 end
113124
114125 def os_doc
Original file line number Diff line number Diff line change 271271 expect ( client . cluster . options [ :heartbeat_frequency ] ) . to eq ( client . options [ :heartbeat_frequency ] )
272272 end
273273 end
274+
275+ context 'when odm details are specified' do
276+
277+ let ( :app_metadata ) do
278+ client . cluster . app_metadata
279+ end
280+
281+ context 'when there is an odm name provided' do
282+
283+ let ( :client ) do
284+ described_class . new ( [ '127.0.0.1:27017' ] , :odm_name => 'mongoid' )
285+ end
286+
287+ it 'includes the odm name in the app metadata' do
288+ expect ( app_metadata . send ( :full_client_document ) [ :driver ] [ :odm ] [ :name ] ) . to eq ( 'mongoid' )
289+ end
290+
291+ context 'when there is an odm version provided' do
292+
293+ let ( :client ) do
294+ described_class . new ( [ '127.0.0.1:27017' ] , odm_name : 'mongoid' , odm_version : '6.0.2' )
295+ end
296+
297+ it 'includes the odm name and version in the app metadata' do
298+ expect ( app_metadata . send ( :full_client_document ) [ :driver ] [ :odm ] [ :version ] ) . to eq ( '6.0.2' )
299+ expect ( app_metadata . send ( :full_client_document ) [ :driver ] [ :odm ] [ :name ] ) . to eq ( 'mongoid' )
300+ end
301+ end
302+ end
303+
304+ context 'when there is no odm name provided' do
305+
306+ let ( :client ) do
307+ described_class . new ( [ '127.0.0.1:27017' ] )
308+ end
309+
310+ it 'does not include an odm name in the app metadata' do
311+ expect ( app_metadata . send ( :full_client_document ) [ :driver ] [ :odm ] ) . to be_nil
312+ end
313+
314+ context 'when there is an odm version provided' do
315+
316+ let ( :client ) do
317+ described_class . new ( [ '127.0.0.1:27017' ] , odm_version : '6.0.2' )
318+ end
319+
320+ it 'does not include an odm doc in the app metadata' do
321+ expect ( app_metadata . send ( :full_client_document ) [ :driver ] [ :odm ] ) . to be_nil
322+ end
323+ end
324+ end
325+ end
274326 end
275327
276328 context 'when providing a connection string' do
You can’t perform that action at this time.
0 commit comments