Skip to content

Commit 0285515

Browse files
Update observability configuration section.
Recommend using driver native API for observability. See: #5009
1 parent 6297482 commit 0285515

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/ContextProviderFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
/**
3838
* Factory to create a {@link ContextProvider} to propagate the request context across tasks. Requires either
3939
* {@link SynchronousContextProvider} or {@link ReactiveContextProvider} to be present.
40+
* <p>
41+
* <strong>NOTE:</strong> MongoDB Java Driver 5.7+ comes with observability directly built in which can be configured
42+
* via {@code MongoClientSettings.Builder#observabilitySettings(ObservabilitySettings)}.
4043
*
4144
* @author Mark Paluch
4245
* @since 3.0

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MongoHandlerContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
/**
3737
* A {@link Observation.Context} that contains MongoDB events.
38+
* <p>
39+
* <strong>NOTE:</strong> MongoDB Java Driver 5.7+ comes with observability directly built in which can be configured
40+
* via {@code MongoClientSettings.Builder#observabilitySettings(ObservabilitySettings)}.
3841
*
3942
* @author Marcin Grzejszczak
4043
* @author Greg Turnquist

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MongoHandlerObservationConvention.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
/**
2222
* {@link ObservationConvention} for {@link MongoHandlerContext}.
23-
*
23+
* <p>
24+
* <strong>NOTE:</strong> MongoDB Java Driver 5.7+ comes with observability directly built in which can be configured
25+
* via {@code MongoClientSettings.Builder#observabilitySettings(ObservabilitySettings)}.
26+
*
2427
* @author Greg Turnquist
2528
* @since 4
2629
*/

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MongoObservationCommandListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
/**
3737
* Implement MongoDB's {@link CommandListener} using Micrometer's {@link Observation} API.
38+
* <p>
39+
* <strong>NOTE:</strong> MongoDB Java Driver 5.7+ comes with observability directly built in which can be configured
40+
* via {@code MongoClientSettings.Builder#observabilitySettings(ObservabilitySettings)}.
3841
*
3942
* @author OpenZipkin Brave Authors
4043
* @author Marcin Grzejszczak
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/**
22
* Infrastructure to provide driver observability using Micrometer.
3+
* <p>
4+
* <strong>NOTE:</strong> MongoDB Java Driver 5.7+ comes with observability directly built in which can be configured
5+
* via {@code MongoClientSettings.Builder#observabilitySettings(ObservabilitySettings)}.
36
*/
47
@org.jspecify.annotations.NullMarked
58
package org.springframework.data.mongodb.observability;

src/main/antora/modules/ROOT/pages/observability/observability.adoc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@
33
[[mongodb.observability]]
44
= Observability
55

6-
Spring Data MongoDB currently has the most up-to-date code to support Observability in your MongoDB application.
7-
These changes, however, haven't been picked up by Spring Boot (yet).
8-
Until those changes are applied, if you wish to use Spring Data MongoDB's flavor of Observability, you must carry out the following steps.
6+
[NOTE]
7+
====
8+
MongoDB Java Driver 5.7+ comes with observability directly built in.
9+
We recommend switching to the driver native `ObservabilitySettings`, which can be configured as outlined below:
10+
[source,java]
11+
----
12+
@Bean
13+
MongoClientSettingsBuilderCustomizer mongoDbObservabilitySettings(ObservationRegistry registry) {
14+
return (clientSettingsBuilder) -> {
15+
clientSettingsBuilder.observabilitySettings(ObservabilitySettings.micrometerBuilder()
16+
.observationRegistry(observationRegistry)
17+
.build());
18+
};
19+
}
20+
----
21+
In the light of driver native observability support, the types within the Spring Data provided _org.springframework.data.mongodb.observability_ package will not see further development and are subject to deprecation/removal in subsequent releases.
22+
====
23+
24+
To use Spring Data MongoDB's flavor of Observability you must:
925

10-
. 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.
26+
. opt into Spring Data MongoDB's configuration settings by customizing `MongoClientSettings` through either your `@SpringBootApplication` class or one of your configuration classes.
1127
+
1228
.Registering MongoDB Micrometer customizer setup
1329
====

0 commit comments

Comments
 (0)