diff --git a/plugins-it/mongodb4-it/src/test/java/com/navercorp/pinpoint/plugin/mongodb4/ReactiveMongoDBITHelper.java b/plugins-it/mongodb4-it/src/test/java/com/navercorp/pinpoint/plugin/mongodb4/ReactiveMongoDBITHelper.java index 21a54d72d741..7f04588f2e48 100644 --- a/plugins-it/mongodb4-it/src/test/java/com/navercorp/pinpoint/plugin/mongodb4/ReactiveMongoDBITHelper.java +++ b/plugins-it/mongodb4-it/src/test/java/com/navercorp/pinpoint/plugin/mongodb4/ReactiveMongoDBITHelper.java @@ -75,6 +75,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; public class ReactiveMongoDBITHelper { + protected static final String MONGO_REACTIVE = "MONGO_REACTIVE"; protected static final String MONGO_EXECUTE_QUERY = "MONGO_EXECUTE_QUERY"; public void testConnection(String address, final MongoDatabase database, Class mongoDatabaseImplClass, String secondCollectionDefaultOption) throws Exception { @@ -162,6 +163,9 @@ public void insertComlexBsonValueData34(PluginTestVerifier verifier, String addr Method insertOneMethod = getMethod(mongoDatabaseImpl, "insertOne", Object.class); NormalizedBson parsedBson = parseBson(document); + // execute + verifier.verifyTrace(event(MONGO_REACTIVE)); + verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOneMethod, null, address, null , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo) , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption) @@ -181,6 +185,9 @@ public void insertData(PluginTestVerifier verifier, String address, MongoCollect Method insertOneMethod = getMethod(mongoDatabaseImpl, "insertOne", Object.class); NormalizedBson parsedBson = parseBson(doc); + // execute + verifier.verifyTrace(event(MONGO_REACTIVE)); + verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOneMethod, null, address, null , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo) , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption) @@ -201,6 +208,9 @@ public void updateData(PluginTestVerifier verifier, String address, MongoCollect Method updateOne = getMethod(mongoDatabaseImpl, "updateOne", Bson.class, Bson.class); NormalizedBson parsedBson = parseBson(doc, doc2); + // execute + verifier.verifyTrace(event(MONGO_REACTIVE)); + verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, updateOne, null, address, null , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers") , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY") @@ -243,6 +253,9 @@ public void deleteData(PluginTestVerifier verifier, String address, MongoCollect Method deleteMany = getMethod(mongoDatabaseImpl, "deleteMany", Bson.class); NormalizedBson parsedBson = parseBson(doc); + // execute + verifier.verifyTrace(event(MONGO_REACTIVE)); + verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, deleteMany, null, address, null , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers") , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY") @@ -263,6 +276,9 @@ public void filterData(PluginTestVerifier verifier, String address, MongoCollect } catch (Throwable throwable) { } + // execute + verifier.verifyTrace(event(MONGO_REACTIVE)); + verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, find, null, address, null , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers") , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred") @@ -283,6 +299,9 @@ public void filterData2(PluginTestVerifier verifier, String address, MongoCollec } catch (Throwable throwable) { } + // execute + verifier.verifyTrace(event(MONGO_REACTIVE)); + verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, find, null, address, null , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers") , new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred") @@ -316,7 +335,6 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { results.add(t); - System.out.println("## Subscriber.onNext=" + t); final int i = COUNT_UPDATER.incrementAndGet(this); if (i >= minimumNumberOfResults) { diff --git a/plugins/mongodb/src/main/java/com/navercorp/pinpoint/plugin/mongo/interceptor/MongoCollectionImplReadOperationInterceptor.java b/plugins/mongodb/src/main/java/com/navercorp/pinpoint/plugin/mongo/interceptor/MongoCollectionImplReadOperationInterceptor.java index 769232ffe493..2cb1aaaf236c 100644 --- a/plugins/mongodb/src/main/java/com/navercorp/pinpoint/plugin/mongo/interceptor/MongoCollectionImplReadOperationInterceptor.java +++ b/plugins/mongodb/src/main/java/com/navercorp/pinpoint/plugin/mongo/interceptor/MongoCollectionImplReadOperationInterceptor.java @@ -26,6 +26,8 @@ import com.navercorp.pinpoint.bootstrap.plugin.jdbc.MongoDatabaseInfo; import com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo; import com.navercorp.pinpoint.bootstrap.util.InterceptorUtils; +import com.navercorp.pinpoint.plugin.mongo.HostListAccessor; +import com.navercorp.pinpoint.plugin.mongo.MongoConstants; import com.navercorp.pinpoint.plugin.mongo.MongoUtil; import com.navercorp.pinpoint.plugin.mongo.NormalizedBson; @@ -46,13 +48,24 @@ public MongoCollectionImplReadOperationInterceptor(TraceContext traceContext, Me public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) { recorder.recordApi(methodDescriptor); - final DatabaseInfo databaseInfo = DatabaseInfoUtils.getDatabaseInfo(target, UnKnownDatabaseInfo.MONGO_INSTANCE); - recorder.recordServiceType(databaseInfo.getExecuteQueryType()); - recorder.recordEndPoint(databaseInfo.getMultipleHost()); - recorder.recordDestinationId(databaseInfo.getDatabaseId()); - if (databaseInfo instanceof MongoDatabaseInfo) { - MongoUtil.recordMongoCollection(recorder, ((MongoDatabaseInfo) databaseInfo).getCollectionName(), ((MongoDatabaseInfo) databaseInfo).getReadPreference()); + if (Boolean.FALSE == (target instanceof HostListAccessor)) { + return; + } + + final List hostList = ((HostListAccessor) target)._$PINPOINT$_getHostList(); + if (hostList == null) { + return; } + + final DatabaseInfo databaseInfo = DatabaseInfoUtils.getDatabaseInfo(target, UnKnownDatabaseInfo.MONGO_INSTANCE); + final MongoDatabaseInfo mongoDatabaseInfo = new MongoDatabaseInfo(MongoConstants.MONGODB, MongoConstants.MONGO_EXECUTE_QUERY, + null, null, hostList, databaseInfo.getDatabaseId(), ((MongoDatabaseInfo) databaseInfo).getCollectionName(), ((MongoDatabaseInfo) databaseInfo).getReadPreference(), ((MongoDatabaseInfo) databaseInfo).getWriteConcern()); + + recorder.recordServiceType(mongoDatabaseInfo.getExecuteQueryType()); + recorder.recordEndPoint(mongoDatabaseInfo.getMultipleHost()); + recorder.recordDestinationId(mongoDatabaseInfo.getDatabaseId()); + + MongoUtil.recordMongoCollection(recorder, mongoDatabaseInfo.getCollectionName(), mongoDatabaseInfo.getReadPreference()); } @Override