Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f650d43
Add tracing support using Micrometer
nhachicha Apr 29, 2025
4a16c29
Simplifying bookkeeping logic for Span grouping
nhachicha Aug 3, 2025
33d46e8
Merging back missing changes after rebase
nhachicha Aug 4, 2025
86f1791
Fixing tests
nhachicha Aug 4, 2025
050fb60
Merge remote-tracking branch 'origin/main' into JAVA-5733
nhachicha Aug 5, 2025
da3ac32
Adding method to get namespace for Read and Write Operations
nhachicha Aug 10, 2025
1a75290
Refactoring operations and command spans
nhachicha Aug 10, 2025
26cc57a
Refactor the tracing implementation to use Observation instead of wor…
nhachicha Oct 2, 2025
45f3cb8
Added Prose Tests
nhachicha Oct 6, 2025
39483e4
Fixing test dependencies
nhachicha Oct 6, 2025
0ecfb19
Skipping non-compliant tests
nhachicha Oct 8, 2025
0523d41
Merge remote-tracking branch 'origin/main' into JAVA-5733
nhachicha Oct 8, 2025
fb1f1af
Fixing test deps for Scala
nhachicha Oct 8, 2025
0628386
Refactored some type visibility per PR feedback
nhachicha Oct 8, 2025
d3f2d62
Fixing javadoc & Scala test
nhachicha Oct 8, 2025
c490154
using JVM option behind a flag
nhachicha Oct 9, 2025
edb9c60
Refactoring logic around env variables.
nhachicha Oct 11, 2025
438f541
Merge remote-tracking branch 'origin/main' into JAVA-5733
nhachicha Oct 11, 2025
bf7b086
removed unused method
nhachicha Oct 13, 2025
360af35
update Java ticket reference
nhachicha Oct 13, 2025
471524b
Merge remote-tracking branch 'origin/main' into JAVA-5733
nhachicha Oct 13, 2025
427554b
switching to new spec branch for testing
nhachicha Oct 13, 2025
d4df11b
PR feedback refactoring:
nhachicha Oct 14, 2025
9a3696e
Extracting logic from InternalStreamConnection
nhachicha Oct 14, 2025
9a4889c
update submodule
nhachicha Oct 14, 2025
1f202bb
Update driver-core/src/main/com/mongodb/internal/tracing/MicrometerTr…
nhachicha Oct 15, 2025
7e5f1f0
Update driver-sync/src/test/functional/com/mongodb/client/tracing/Mic…
nhachicha Oct 15, 2025
da6bff1
Update driver-sync/src/test/functional/com/mongodb/client/tracing/Mic…
nhachicha Oct 15, 2025
46e2932
Update driver-core/src/main/com/mongodb/internal/tracing/TracingManag…
nhachicha Oct 15, 2025
d71c5c4
Update driver-core/src/main/com/mongodb/internal/tracing/TracingManag…
nhachicha Oct 15, 2025
e3b1c93
PR feedback
nhachicha Oct 15, 2025
c5a429e
Fixing tests
nhachicha Oct 15, 2025
d7b4449
Update driver-core/src/main/com/mongodb/MongoNamespace.java
nhachicha Oct 15, 2025
9f611b1
Update driver-core/src/main/com/mongodb/internal/tracing/TracingManag…
nhachicha Oct 16, 2025
a1ad428
Update driver-core/src/main/com/mongodb/observability/ObservabilitySe…
nhachicha Oct 16, 2025
1a8c59e
switching to main submodule commit; updating skipped tests; adding mi…
nhachicha Oct 16, 2025
b3e85fd
adding skip tests
nhachicha Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/project/Companion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ import org.gradle.kotlin.dsl.getByType
internal val Project.libs: LibrariesForLibs
get() = extensions.getByType()

internal const val DEFAULT_JAVA_VERSION = 17
const val DEFAULT_JAVA_VERSION = 17
1 change: 1 addition & 0 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

<!-- Allow printStackTrace in this file -->
<suppress checks="Regexp" files="CallbackResultHolder"/>
<suppress checks="Regexp" files="MicrometerTracer"/>

<!--Do not check documentation tests classes -->
<suppress checks="Javadoc*" files=".*documentation.*"/>
Expand Down
1 change: 1 addition & 0 deletions driver-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {

optionalImplementation(libs.snappy.java)
optionalImplementation(libs.zstd.jni)
optionalImplementation(libs.micrometer.observation)

testImplementation(project(path = ":bson", configuration = "testArtifacts"))
testImplementation(libs.reflections)
Expand Down
43 changes: 43 additions & 0 deletions driver-core/src/main/com/mongodb/MongoClientSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import com.mongodb.connection.SslSettings;
import com.mongodb.connection.TransportSettings;
import com.mongodb.event.CommandListener;
import com.mongodb.internal.VisibleForTesting;
import com.mongodb.lang.Nullable;
import com.mongodb.spi.dns.DnsClient;
import com.mongodb.spi.dns.InetAddressResolver;
import com.mongodb.tracing.Tracer;
import org.bson.UuidRepresentation;
import org.bson.codecs.BsonCodecProvider;
import org.bson.codecs.BsonValueCodecProvider;
Expand All @@ -57,6 +59,8 @@
import static com.mongodb.assertions.Assertions.isTrueArgument;
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.internal.TimeoutSettings.convertAndValidateTimeout;
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
import static java.lang.System.getenv;
import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
Expand Down Expand Up @@ -119,6 +123,10 @@ public final class MongoClientSettings {
@Nullable
private final Long timeoutMS;

@VisibleForTesting(otherwise = PRIVATE)
public static final String ENV_OTEL_ENABLED = "OTEL_JAVA_INSTRUMENTATION_MONGODB_ENABLED";
private final Tracer tracer;

/**
* Gets the default codec registry. It includes the following providers:
*
Expand Down Expand Up @@ -238,6 +246,7 @@ public static final class Builder {
private ContextProvider contextProvider;
private DnsClient dnsClient;
private InetAddressResolver inetAddressResolver;
private Tracer tracer;

private Builder() {
}
Expand Down Expand Up @@ -275,6 +284,7 @@ private Builder(final MongoClientSettings settings) {
if (settings.heartbeatSocketTimeoutSetExplicitly) {
heartbeatSocketTimeoutMS = settings.heartbeatSocketSettings.getReadTimeout(MILLISECONDS);
}
tracer = settings.tracer;
}

/**
Expand Down Expand Up @@ -723,6 +733,20 @@ Builder heartbeatSocketTimeoutMS(final int heartbeatSocketTimeoutMS) {
return this;
}

/**
* Sets the tracer to use for creating Spans for operations, commands and transactions.
*
* @param tracer the tracer
* @see com.mongodb.tracing.MicrometerTracer
* @return this
* @since 5.7
*/
@Alpha(Reason.CLIENT)
public Builder tracer(final Tracer tracer) {
this.tracer = tracer;
return this;
}

/**
* Build an instance of {@code MongoClientSettings}.
*
Expand Down Expand Up @@ -1040,6 +1064,16 @@ public ContextProvider getContextProvider() {
return contextProvider;
}

/**
* Get the tracer to create Spans for operations, commands and transactions.
*
* @return the configured Tracer
* @since 5.7
*/
public Tracer getTracer() {
return tracer;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down Expand Up @@ -1156,5 +1190,14 @@ private MongoClientSettings(final Builder builder) {
heartbeatConnectTimeoutSetExplicitly = builder.heartbeatConnectTimeoutMS != 0;
contextProvider = builder.contextProvider;
timeoutMS = builder.timeoutMS;

String envOtelInstrumentationEnabled = getenv(ENV_OTEL_ENABLED);
boolean enableTracing = true;
if (envOtelInstrumentationEnabled != null) {
enableTracing = Boolean.parseBoolean(envOtelInstrumentationEnabled);
}
tracer = (builder.tracer == null) ? Tracer.NO_OP
: (enableTracing) ? builder.tracer
: Tracer.NO_OP;
}
}
Loading