@@ -57,6 +57,8 @@ class Collection
5757 # Delegate to the cluster for the next primary.
5858 def_delegators :cluster , :next_primary
5959
60+ def_delegators :client , :tracer
61+
6062 # Options that can be updated on a new Collection instance via the #with method.
6163 #
6264 # @since 2.1.0
@@ -410,21 +412,24 @@ def create(opts = {})
410412 client : client ,
411413 session : session
412414 )
413- maybe_create_qe_collections ( opts [ :encrypted_fields ] , client , session ) do |encrypted_fields |
414- Operation ::Create . new (
415- selector : operation ,
416- db_name : database . name ,
417- write_concern : write_concern ,
418- session : session ,
419- # Note that these are collection options, collation isn't
420- # taken from options passed to the create method.
421- collation : options [ :collation ] || options [ 'collation' ] ,
422- encrypted_fields : encrypted_fields ,
423- validator : options [ :validator ] ,
424- ) . execute (
425- next_primary ( nil , session ) ,
426- context : context
427- )
415+ operation = Operation ::Create . new (
416+ selector : operation ,
417+ db_name : database . name ,
418+ write_concern : write_concern ,
419+ session : session ,
420+ # Note that these are collection options, collation isn't
421+ # taken from options passed to the create method.
422+ collation : options [ :collation ] || options [ 'collation' ] ,
423+ validator : options [ :validator ] ,
424+ )
425+ tracer . trace_operation ( operation , context , op_name : 'createCollection' ) do
426+ maybe_create_qe_collections ( opts [ :encrypted_fields ] , client , session ) do |encrypted_fields |
427+ operation . encrypted_fields = encrypted_fields
428+ operation . execute (
429+ next_primary ( nil , session ) ,
430+ context : context
431+ )
432+ end
428433 end
429434 end
430435 end
@@ -453,25 +458,27 @@ def create(opts = {})
453458 # @since 2.0.0
454459 def drop ( opts = { } )
455460 client . with_session ( opts ) do |session |
456- maybe_drop_emm_collections ( opts [ :encrypted_fields ] , client , session ) do
457- temp_write_concern = write_concern
458- write_concern = if opts [ :write_concern ]
459- WriteConcern . get ( opts [ :write_concern ] )
460- else
461- temp_write_concern
461+ context = Operation ::Context . new (
462+ client : client ,
463+ session : session ,
464+ operation_timeouts : operation_timeouts ( opts )
465+ )
466+ temp_write_concern = write_concern
467+ write_concern = if opts [ :write_concern ]
468+ WriteConcern . get ( opts [ :write_concern ] )
469+ else
470+ temp_write_concern
471+ end
472+ operation = Operation ::Drop . new ( {
473+ selector : { :drop => name } ,
474+ db_name : database . name ,
475+ write_concern : write_concern ,
476+ session : session ,
477+ } )
478+ tracer . trace_operation ( operation , context , op_name : 'dropCollection' ) do
479+ maybe_drop_emm_collections ( opts [ :encrypted_fields ] , client , session ) do
480+ do_drop ( operation , session , context )
462481 end
463- context = Operation ::Context . new (
464- client : client ,
465- session : session ,
466- operation_timeouts : operation_timeouts ( opts )
467- )
468- operation = Operation ::Drop . new ( {
469- selector : { :drop => name } ,
470- db_name : database . name ,
471- write_concern : write_concern ,
472- session : session ,
473- } )
474- do_drop ( operation , session , context )
475482 end
476483 end
477484 end
@@ -865,19 +872,22 @@ def insert_one(document, opts = {})
865872 session : session ,
866873 operation_timeouts : operation_timeouts ( opts )
867874 )
868- write_with_retry ( write_concern , context : context ) do |connection , txn_num , context |
869- Operation ::Insert . new (
870- :documents => [ document ] ,
871- :db_name => database . name ,
872- :coll_name => name ,
873- :write_concern => write_concern ,
874- :bypass_document_validation => !!opts [ :bypass_document_validation ] ,
875- :options => opts ,
876- :id_generator => client . options [ :id_generator ] ,
877- :session => session ,
878- :txn_num => txn_num ,
879- :comment => opts [ :comment ]
880- ) . execute_with_connection ( connection , context : context )
875+ operation = Operation ::Insert . new (
876+ :documents => [ document ] ,
877+ :db_name => database . name ,
878+ :coll_name => name ,
879+ :write_concern => write_concern ,
880+ :bypass_document_validation => !!opts [ :bypass_document_validation ] ,
881+ :options => opts ,
882+ :id_generator => client . options [ :id_generator ] ,
883+ :session => session ,
884+ :comment => opts [ :comment ]
885+ )
886+ tracer . trace_operation ( operation , context ) do
887+ write_with_retry ( write_concern , context : context ) do |connection , txn_num , context |
888+ operation . txn_num = txn_num
889+ operation . execute_with_connection ( connection , context : context )
890+ end
881891 end
882892 end
883893 end
0 commit comments