Skip to content

Commit

Permalink
Allow custom MongoHandlerObservationConvention
Browse files Browse the repository at this point in the history
  • Loading branch information
francoiskha committed Jan 10, 2024
1 parent 4877756 commit b874281
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MongoObservationCommandListener implements CommandListener {
private final ObservationRegistry observationRegistry;
private final @Nullable ConnectionString connectionString;

private final MongoHandlerObservationConvention observationConvention = new DefaultMongoHandlerObservationConvention();
private final MongoHandlerObservationConvention observationConvention;

/**
* Create a new {@link MongoObservationCommandListener} to record {@link Observation}s.
Expand All @@ -61,6 +61,7 @@ public MongoObservationCommandListener(ObservationRegistry observationRegistry)

this.observationRegistry = observationRegistry;
this.connectionString = null;
this.observationConvention = new DefaultMongoHandlerObservationConvention();
}

/**
Expand All @@ -77,6 +78,26 @@ public MongoObservationCommandListener(ObservationRegistry observationRegistry,

this.observationRegistry = observationRegistry;
this.connectionString = connectionString;
this.observationConvention = new DefaultMongoHandlerObservationConvention();
}

/**
* Create a new {@link MongoObservationCommandListener} to record {@link Observation}s. This constructor attaches the
* {@link ConnectionString} to every {@link Observation} and uses the given {@link MongoHandlerObservationConvention}
*
* @param observationRegistry must not be {@literal null}
* @param connectionString must not be {@literal null}
* @param observationConvention must not be {@literal null}
*/
public MongoObservationCommandListener(ObservationRegistry observationRegistry, ConnectionString connectionString,MongoHandlerObservationConvention observationConvention) {

Assert.notNull(observationRegistry, "ObservationRegistry must not be null");
Assert.notNull(connectionString, "ConnectionString must not be null");
Assert.notNull(observationConvention, "MongoHandlerObservationConvention must not be null");

this.observationRegistry = observationRegistry;
this.connectionString = connectionString;
this.observationConvention = observationConvention;
}

@Override
Expand Down

0 comments on commit b874281

Please sign in to comment.