Observability
-
启用 Spring Data MongoDB 的配置设置。
-
注册 MongoDB Micrometer 自定义程序设置。
-
包含 Spring Boot Actuator。
-
禁用 Spring Boot 的自动配置 MongoDB 命令监听器并手动启用跟踪。
Spring Data MongoDB 目前拥有最最新的代码,可在您的 MongoDB 应用程序中支持可观察性。但是,Spring Boot(尚未)采用这些更改。在应用这些更改之前,如果您希望使用 Spring Data MongoDB 风格的可观察性,则必须执行以下步骤。
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.
-
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..Registering MongoDB Micrometer customizer setup
@Bean
MongoClientSettingsBuilderCustomizer mongoMetricsSynchronousContextProvider(ObservationRegistry registry) {
return (clientSettingsBuilder) -> {
clientSettingsBuilder.contextProvider(ContextProviderFactory.create(registry))
.addCommandListener(new MongoObservationCommandListener(registry));
};
}
-
Your project must include Spring Boot Actuator.
-
Disable Spring Boot’s autoconfigured MongoDB command listener and enable tracing manually by adding the following properties to your
application.properties
.Custom settings to apply
# Disable Spring Boot's autoconfigured tracing
management.metrics.mongo.command.enabled=false
# Enable it manually
management.tracing.enabled=true
确保添加了配置您正在使用的跟踪器的任何其他相关设置,这些设置基于 Micrometer 参考文档。
Be sure to add any other relevant settings needed to configure the tracer you are using based upon Micrometer’s reference documentation.
现在应该可以了!你正在运行带有 Spring Data MongoDB 使用场景的 Spring Observability’s Observation
API。有关更多参考,另请参阅 OpenTelemetry Semantic Conventions。
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.