@@ -504,19 +504,19 @@ private void connectionPoolCreated(final ConnectionPoolListener connectionPoolLi
504504 * Send both current and deprecated events in order to preserve backwards compatibility.
505505 * Must not throw {@link Exception}s.
506506 *
507- * @return A {@link TimePoint} after executing {@link ConnectionPoolListener#connectionCreated(ConnectionCreatedEvent)},
508- * {@link ConnectionPoolListener#connectionCreated(ConnectionCreatedEvent)}.
509- * This order is required by
507+ * @return A {@link TimePoint} before executing {@link ConnectionPoolListener#connectionCreated(ConnectionCreatedEvent)}
508+ * and logging the event. This order is required by
510509 * <a href="https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#events">CMAP</a>
511510 * and {@link ConnectionReadyEvent#getElapsedTime(TimeUnit)}.
512511 */
513512 private TimePoint connectionCreated (final ConnectionPoolListener connectionPoolListener , final ConnectionId connectionId ) {
513+ TimePoint openStart = TimePoint .now ();
514514 logEventMessage ("Connection created" ,
515515 "Connection created: address={}:{}, driver-generated ID={}" ,
516516 connectionId .getLocalValue ());
517517
518518 connectionPoolListener .connectionCreated (new ConnectionCreatedEvent (connectionId ));
519- return TimePoint . now () ;
519+ return openStart ;
520520 }
521521
522522 /**
@@ -562,16 +562,18 @@ private void connectionCheckedOut(
562562 }
563563
564564 /**
565- * @return A {@link TimePoint} after executing {@link ConnectionPoolListener#connectionCheckOutStarted(ConnectionCheckOutStartedEvent)}.
565+ * @return A {@link TimePoint} before executing
566+ * {@link ConnectionPoolListener#connectionCheckOutStarted(ConnectionCheckOutStartedEvent)} and logging the event.
566567 * This order is required by
567568 * <a href="https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#events">CMAP</a>
568569 * and {@link ConnectionCheckedOutEvent#getElapsedTime(TimeUnit)}, {@link ConnectionCheckOutFailedEvent#getElapsedTime(TimeUnit)}.
569570 */
570571 private TimePoint connectionCheckoutStarted (final OperationContext operationContext ) {
572+ TimePoint checkoutStart = TimePoint .now ();
571573 logEventMessage ("Connection checkout started" , "Checkout started for connection to {}:{}" );
572574
573575 connectionPoolListener .connectionCheckOutStarted (new ConnectionCheckOutStartedEvent (serverId , operationContext .getId ()));
574- return TimePoint . now () ;
576+ return checkoutStart ;
575577 }
576578
577579 /**
0 commit comments