@@ -57,44 +57,35 @@ public class MongoObservationCommandListener implements CommandListener {
57
57
* @param observationRegistry must not be {@literal null}
58
58
*/
59
59
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 );
66
61
}
67
62
68
63
/**
69
64
* Create a new {@link MongoObservationCommandListener} to record {@link Observation}s. This constructor attaches the
70
65
* {@link ConnectionString} to every {@link Observation}.
71
66
*
72
67
* @param observationRegistry must not be {@literal null}
73
- * @param connectionString must not be {@literal null}
68
+ * @param connectionString can be {@literal null}
74
69
*/
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 ());
83
73
}
84
74
85
75
/**
86
76
* 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}.
88
78
*
89
79
* @param observationRegistry must not be {@literal null}
90
- * @param connectionString must not be {@literal null}
80
+ * @param connectionString can be {@literal null}
91
81
* @param observationConvention must not be {@literal null}
82
+ * @since 4.3
92
83
*/
93
- public MongoObservationCommandListener (ObservationRegistry observationRegistry , ConnectionString connectionString , MongoHandlerObservationConvention observationConvention ) {
84
+ public MongoObservationCommandListener (ObservationRegistry observationRegistry ,
85
+ @ Nullable ConnectionString connectionString , MongoHandlerObservationConvention observationConvention ) {
94
86
95
87
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" );
98
89
99
90
this .observationRegistry = observationRegistry ;
100
91
this .connectionString = connectionString ;
@@ -193,7 +184,7 @@ private void doInObservation(@Nullable RequestContext requestContext,
193
184
}
194
185
195
186
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 )) {
197
188
return ;
198
189
}
199
190
0 commit comments