39
39
* @author OpenZipkin Brave Authors
40
40
* @author Marcin Grzejszczak
41
41
* @author Greg Turnquist
42
+ * @author François Kha
42
43
* @since 4.0
43
44
*/
44
45
public class MongoObservationCommandListener implements CommandListener {
@@ -48,7 +49,7 @@ public class MongoObservationCommandListener implements CommandListener {
48
49
private final ObservationRegistry observationRegistry ;
49
50
private final @ Nullable ConnectionString connectionString ;
50
51
51
- private final MongoHandlerObservationConvention observationConvention = new DefaultMongoHandlerObservationConvention () ;
52
+ private final MongoHandlerObservationConvention observationConvention ;
52
53
53
54
/**
54
55
* Create a new {@link MongoObservationCommandListener} to record {@link Observation}s.
@@ -61,6 +62,7 @@ public MongoObservationCommandListener(ObservationRegistry observationRegistry)
61
62
62
63
this .observationRegistry = observationRegistry ;
63
64
this .connectionString = null ;
65
+ this .observationConvention = new DefaultMongoHandlerObservationConvention ();
64
66
}
65
67
66
68
/**
@@ -77,6 +79,26 @@ public MongoObservationCommandListener(ObservationRegistry observationRegistry,
77
79
78
80
this .observationRegistry = observationRegistry ;
79
81
this .connectionString = connectionString ;
82
+ this .observationConvention = new DefaultMongoHandlerObservationConvention ();
83
+ }
84
+
85
+ /**
86
+ * 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}
88
+ *
89
+ * @param observationRegistry must not be {@literal null}
90
+ * @param connectionString must not be {@literal null}
91
+ * @param observationConvention must not be {@literal null}
92
+ */
93
+ public MongoObservationCommandListener (ObservationRegistry observationRegistry , ConnectionString connectionString ,MongoHandlerObservationConvention observationConvention ) {
94
+
95
+ 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" );
98
+
99
+ this .observationRegistry = observationRegistry ;
100
+ this .connectionString = connectionString ;
101
+ this .observationConvention = observationConvention ;
80
102
}
81
103
82
104
@ Override
0 commit comments