Spring Data MongoDB currently has the most up-to-date code to support Observability in your MongoDB application. These changes, however, haven’t been picked up by Spring Boot (yet). Until those changes are applied, if you wish to use Spring Data MongoDB’s flavor of Observability, you must carry out the following steps.

  1. First of all, you must opt into Spring Data MongoDB’s configuration settings by customizing MongoClientSettings through either your @SpringBootApplication class or one of your configuration classes.

    Example 1. Registering MongoDB Micrometer customizer setup
    MongoClientSettingsBuilderCustomizer mongoMetricsSynchronousContextProvider(ObservationRegistry registry) {
        return (clientSettingsBuilder) -> {
                                 .addCommandListener(new MongoObservationCommandListener(registry));
  2. Your project must include Spring Boot Actuator.

  3. Disable Spring Boot’s autoconfigured MongoDB command listener and enable tracing manually by adding the following properties to your application.properties

    Example 2. Custom settings to apply
    # Disable Spring Boot's autoconfigured tracing
    # Enable it manually

    Be sure to add any other relevant settings needed to configure the tracer you are using based upon Micrometer’s reference documentation.

This should do it! You are now running with Spring Data MongoDB’s usage of Spring Observability’s Observation API. See also OpenTelemetry Semantic Conventions for further reference.