Mongodb: avoid duplicate tracing
MODIFY
instrumentation/mongo/mongo-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_1/MongoClientInstrumentationModule.java
instrumentation/mongo/mongo-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_1/MongoClientInstrumentationModule.java
@@ -66,7 +66,7 @@ public class MongoClientInstrumentationModule extends InstrumentationModule {
@Advice.This MongoClientOptions.Builder builder,
@Advice.FieldValue("commandListeners") List<CommandListener> commandListeners) {
for (CommandListener commandListener : commandListeners) {
- if (commandListener == MongoInstrumentationSingletons.LISTENER) {
+ if (MongoInstrumentationSingletons.isTracingListener(commandListener)) {
return;
}
}

MODIFY
instrumentation/mongo/mongo-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_1/MongoInstrumentationSingletons.java
instrumentation/mongo/mongo-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_1/MongoInstrumentationSingletons.java
@@ -14,5 +14,9 @@ public final class MongoInstrumentationSingletons {
public static final CommandListener LISTENER =
MongoTelemetry.create(GlobalOpenTelemetry.get()).newCommandListener();
+ public static boolean isTracingListener(CommandListener listener) {
+ return listener.getClass().getName().equals(LISTENER.getClass().getName());
+ }
+
private MongoInstrumentationSingletons() {}
}

MODIFY
instrumentation/mongo/mongo-3.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_7/MongoClientSettingsBuilderInstrumentation.java
instrumentation/mongo/mongo-3.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_7/MongoClientSettingsBuilderInstrumentation.java
@@ -49,7 +49,7 @@ final class MongoClientSettingsBuilderInstrumentation implements TypeInstrumenta
@Advice.This MongoClientSettings.Builder builder,
@Advice.FieldValue("commandListeners") List<CommandListener> commandListeners) {
for (CommandListener commandListener : commandListeners) {
- if (commandListener == MongoInstrumentationSingletons.LISTENER) {
+ if (MongoInstrumentationSingletons.isTracingListener(commandListener)) {
return;
}
}

MODIFY
instrumentation/mongo/mongo-3.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_7/MongoInstrumentationSingletons.java
instrumentation/mongo/mongo-3.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_7/MongoInstrumentationSingletons.java
@@ -14,5 +14,9 @@ public final class MongoInstrumentationSingletons {
public static final CommandListener LISTENER =
MongoTelemetry.create(GlobalOpenTelemetry.get()).newCommandListener();
+ public static boolean isTracingListener(CommandListener listener) {
+ return listener.getClass().getName().equals(LISTENER.getClass().getName());
+ }
+
private MongoInstrumentationSingletons() {}
}

MODIFY
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/MongoClientSettingsBuilderInstrumentation.java
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/MongoClientSettingsBuilderInstrumentation.java
@@ -49,7 +49,7 @@ final class MongoClientSettingsBuilderInstrumentation implements TypeInstrumenta
@Advice.This MongoClientSettings.Builder builder,
@Advice.FieldValue("commandListeners") List<CommandListener> commandListeners) {
for (CommandListener commandListener : commandListeners) {
- if (commandListener == MongoInstrumentationSingletons.LISTENER) {
+ if (MongoInstrumentationSingletons.isTracingListener(commandListener)) {
return;
}
}

MODIFY
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/MongoInstrumentationSingletons.java
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/MongoInstrumentationSingletons.java
@@ -14,5 +14,9 @@ public final class MongoInstrumentationSingletons {
public static final CommandListener LISTENER =
MongoTelemetry.create(GlobalOpenTelemetry.get()).newCommandListener();
+ public static boolean isTracingListener(CommandListener listener) {
+ return listener.getClass().getName().equals(LISTENER.getClass().getName());
+ }
+
private MongoInstrumentationSingletons() {}
}

MODIFY
instrumentation/mongo/mongo-async-3.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongoasync/v3_3/MongoClientSettingsBuildersInstrumentation.java
instrumentation/mongo/mongo-async-3.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongoasync/v3_3/MongoClientSettingsBuildersInstrumentation.java
@@ -51,7 +51,7 @@ final class MongoClientSettingsBuildersInstrumentation implements TypeInstrument
@Advice.This MongoClientSettings.Builder builder,
@Advice.FieldValue("commandListeners") List<CommandListener> commandListeners) {
for (CommandListener commandListener : commandListeners) {
- if (commandListener == MongoInstrumentationSingletons.LISTENER) {
+ if (MongoInstrumentationSingletons.isTracingListener(commandListener)) {
return;
}
}

MODIFY
instrumentation/mongo/mongo-async-3.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongoasync/v3_3/MongoInstrumentationSingletons.java
instrumentation/mongo/mongo-async-3.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongoasync/v3_3/MongoInstrumentationSingletons.java
@@ -14,5 +14,9 @@ public final class MongoInstrumentationSingletons {
public static final CommandListener LISTENER =
MongoTelemetry.create(GlobalOpenTelemetry.get()).newCommandListener();
+ public static boolean isTracingListener(CommandListener listener) {
+ return listener.getClass().getName().equals(LISTENER.getClass().getName());
+ }
+
private MongoInstrumentationSingletons() {}
}

Mongodb: avoid duplicate tracing (#6465)