@@ -57,44 +57,35 @@ public class MongoObservationCommandListener implements CommandListener {
5757 * @param observationRegistry must not be {@literal null}
5858 */
5959 public MongoObservationCommandListener (ObservationRegistry observationRegistry ) {
60-
61- Assert .notNull (observationRegistry , "ObservationRegistry must not be null" );
62-
63- this .observationRegistry = observationRegistry ;
64- this .connectionString = null ;
65- this .observationConvention = new DefaultMongoHandlerObservationConvention ();
60+ this (observationRegistry , null );
6661 }
6762
6863 /**
6964 * Create a new {@link MongoObservationCommandListener} to record {@link Observation}s. This constructor attaches the
7065 * {@link ConnectionString} to every {@link Observation}.
7166 *
7267 * @param observationRegistry must not be {@literal null}
73- * @param connectionString must not be {@literal null}
68+ * @param connectionString can be {@literal null}
7469 */
75- public MongoObservationCommandListener (ObservationRegistry observationRegistry , ConnectionString connectionString ) {
76-
77- Assert .notNull (observationRegistry , "ObservationRegistry must not be null" );
78- Assert .notNull (connectionString , "ConnectionString must not be null" );
79-
80- this .observationRegistry = observationRegistry ;
81- this .connectionString = connectionString ;
82- this .observationConvention = new DefaultMongoHandlerObservationConvention ();
70+ public MongoObservationCommandListener (ObservationRegistry observationRegistry ,
71+ @ Nullable ConnectionString connectionString ) {
72+ this (observationRegistry , connectionString , new DefaultMongoHandlerObservationConvention ());
8373 }
8474
8575 /**
8676 * Create a new {@link MongoObservationCommandListener} to record {@link Observation}s. This constructor attaches the
87- * {@link ConnectionString} to every {@link Observation} and uses the given {@link MongoHandlerObservationConvention}
77+ * {@link ConnectionString} to every {@link Observation} and uses the given {@link MongoHandlerObservationConvention}.
8878 *
8979 * @param observationRegistry must not be {@literal null}
90- * @param connectionString must not be {@literal null}
80+ * @param connectionString can be {@literal null}
9181 * @param observationConvention must not be {@literal null}
82+ * @since 4.3
9283 */
93- public MongoObservationCommandListener (ObservationRegistry observationRegistry , ConnectionString connectionString , MongoHandlerObservationConvention observationConvention ) {
84+ public MongoObservationCommandListener (ObservationRegistry observationRegistry ,
85+ @ Nullable ConnectionString connectionString , MongoHandlerObservationConvention observationConvention ) {
9486
9587 Assert .notNull (observationRegistry , "ObservationRegistry must not be null" );
96- Assert .notNull (connectionString , "ConnectionString must not be null" );
97- Assert .notNull (observationConvention , "MongoHandlerObservationConvention must not be null" );
88+ Assert .notNull (observationConvention , "ObservationConvention must not be null" );
9889
9990 this .observationRegistry = observationRegistry ;
10091 this .connectionString = connectionString ;
@@ -193,7 +184,7 @@ private void doInObservation(@Nullable RequestContext requestContext,
193184 }
194185
195186 Observation observation = requestContext .getOrDefault (ObservationThreadLocalAccessor .KEY , null );
196- if (observation == null || !(observation .getContext ()instanceof MongoHandlerContext context )) {
187+ if (observation == null || !(observation .getContext () instanceof MongoHandlerContext context )) {
197188 return ;
198189 }
199190
0 commit comments