Skip to content

Commit db5387c

Browse files
committed
Fixing tests
1 parent cf4660c commit db5387c

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

driver-core/src/main/com/mongodb/internal/observability/micrometer/TransactionSpan.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class TransactionSpan {
3131

3232
public TransactionSpan(final TracingManager tracingManager) {
3333
this.span = tracingManager.addTransactionSpan();
34-
this.span.openScope();
3534
}
3635

3736
/**
@@ -113,4 +112,12 @@ public void setIsConvenientTransaction() {
113112
public TraceContext getContext() {
114113
return span.context();
115114
}
115+
116+
/**
117+
* Opens a scope for the transaction span, making it the current observation on the thread.
118+
* Must only be called from the sync driver where open and close happen on the same thread.
119+
*/
120+
public void openScope() {
121+
span.openScope();
122+
}
116123
}

driver-sync/src/main/com/mongodb/client/internal/ClientSessionImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private void startTransaction(final TransactionOptions transactionOptions, final
178178

179179
if (tracingManager.isEnabled()) {
180180
transactionSpan = new TransactionSpan(tracingManager);
181+
transactionSpan.openScope();
181182
}
182183
clearTransactionContext();
183184
setTimeoutContext(timeoutContext);

driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.mongodb.lang.Nullable;
5050
import com.mongodb.logging.TestLoggingInterceptor;
5151
import com.mongodb.observability.ObservabilitySettings;
52-
import io.micrometer.observation.Observation;
5352
import io.micrometer.observation.ObservationRegistry;
5453
import io.micrometer.tracing.test.reporter.inmemory.InMemoryOtelSetup;
5554
import org.bson.BsonArray;
@@ -114,7 +113,6 @@ public final class Entities {
114113
private final Map<String, TestLoggingInterceptor> clientLoggingInterceptors = new HashMap<>();
115114
private final Map<String, InMemoryOtelSetup.Builder.OtelBuildingBlocks> clientTracing = new HashMap<>();
116115
private final Set<InMemoryOtelSetup> inMemoryOTelInstances = new HashSet<>();
117-
private final Set<Observation.Scope> observationScopes = new HashSet<>();
118116
private final Map<String, TestConnectionPoolListener> clientConnectionPoolListeners = new HashMap<>();
119117
private final Map<String, TestServerListener> clientServerListeners = new HashMap<>();
120118
private final Map<String, TestClusterListener> clientClusterListeners = new HashMap<>();
@@ -596,11 +594,6 @@ private void initClient(final BsonDocument entity, final String id,
596594
.observationRegistry(observationRegistry)
597595
.enableCommandPayloadTracing(enableCommandPayload).build());
598596

599-
// Simulate what Spring Boot's observation does
600-
// open a parent observation's scope before running the MongoDB operation
601-
Observation parentObservation = Observation.createNotStarted("http.request", observationRegistry)
602-
.start();
603-
observationScopes.add(parentObservation.openScope());
604597
}
605598

606599
MongoClientSettings clientSettings = clientSettingsBuilder.build();
@@ -824,6 +817,5 @@ public void close() {
824817
clientLoggingInterceptors.values().forEach(TestLoggingInterceptor::close);
825818
threads.values().forEach(ExecutorService::shutdownNow);
826819
inMemoryOTelInstances.forEach(InMemoryOtelSetup::close);
827-
observationScopes.forEach(Observation.Scope::close);
828820
}
829821
}

driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ public static void applyCustomizations(final TestDef def) {
197197
.test("client-side-operations-timeout", "timeoutMS can be configured on a MongoClient",
198198
"timeoutMS can be set to 0 on a MongoClient - dropIndexes on collection");
199199

200+
// OpenTelemetry
201+
def.skipNoncompliantReactive("withTransaction is not supported in the reactive driver unified test runner")
202+
.file("open-telemetry/tests", "convenient transactions");
203+
200204
// TODO-JAVA-5712
201205

202206
// collection-management

0 commit comments

Comments
 (0)