You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "hxd123456 (via GitHub)" <gi...@apache.org> on 2023/08/23 09:43:06 UTC

[GitHub] [skywalking-java] hxd123456 opened a new pull request, #597: [#11252]add mongoDB plugin report db instance info

hxd123456 opened a new pull request, #597:
URL: https://github.com/apache/skywalking-java/pull/597

   <!--
       ⚠️ Please make sure to read this template first, pull requests that don't accord with this template
       maybe closed without notice.
       Texts surrounded by `<` and `>` are meant to be replaced by you, e.g. <framework name>, <issue number>.
       Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]`
   -->
   
   <!-- ==== 🐛 Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist 👇 ====
   ### Fix <bug description or the bug issue number or bug issue link>
   - [ ] Add a unit test to verify that the fix works.
   - [ ] Explain briefly why the bug exists and how to fix it.
        ==== 🐛 Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist 👆 ==== -->
   
   <!-- ==== 🔌 Remove this line WHEN AND ONLY WHEN you're adding a new plugin, follow the checklist 👇 ====
   ### Add an agent plugin to support <framework name>
   - [ ] Add a test case for the new plugin, refer to [the doc](https://github.com/apache/skywalking-java/blob/main/docs/en/setup/service-agent/java-agent/Plugin-test.md)
   - [ ] Add a component id in [the component-libraries.yml](https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml)
   - [ ] Add a logo in [the UI repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets)
        ==== 🔌 Remove this line WHEN AND ONLY WHEN you're adding a new plugin, follow the checklist 👆 ==== -->
   
   <!-- ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist 👇 ====
   ### Improve the performance of <class or module or ...>
   - [ ] Add a benchmark for the improvement, refer to [the existing ones](https://github.com/apache/skywalking-java/blob/main/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   - [ ] The benchmark result.
   ```text
   <Paste the benchmark results here>
   ```
   - [ ] Links/URLs to the theory proof or discussion articles/blogs. <links/URLs here>
        ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist 👆 ==== -->
   
   <!-- ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist 👇 ====
   ### <Feature description>
   - [ ] If this is non-trivial feature, paste the links/URLs to the design doc.
   - [ ] Update the documentation to include this new feature.
   - [ ] Tests(including UT, IT, E2E) are added to verify the new feature.
   - [ ] If it's UI related, attach the screenshots below.
        ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist 👆 ==== -->
   
   - [ ] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes #<issue number>.
   - [ ] Update the [`CHANGES` log](https://github.com/apache/skywalking-java/blob/main/CHANGES.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1696595908

   @hxd123456 Do you have an estimated time to finish this? I am planning the first agent v9 release. This is the only open issues/PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1696662002

   It is not hard required, I will postpone it to 9.1, take your time. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1694671618

   It is better if you could test it locally first. Because reviewers are watching the PR status, once you are updating, we assume you have fixed previous comments.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1302778041


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoInfoHelper.java:
##########
@@ -140,4 +146,65 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));

Review Comment:
   This will slow down the extra time of tracing from 10 nanoseconds to 100+ ns or more, determined by how many `instanceof`s you have to run before the reflection.
   
   As you are only trying to read DB instance info, can't you get that from the constructor of those `Operation`s?  You could instrument those and use dynamic field to carry all necessary information. 
   I believe from there, you don't need `instanceof` anymore.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1302774989


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoInfoHelper.java:
##########
@@ -40,21 +41,26 @@
 import com.mongodb.internal.operation.UpdateOperation;
 import org.bson.BsonDocument;
 
+import java.lang.reflect.Field;
 import java.util.List;
 
 @SuppressWarnings({
-    "deprecation",
-    "Duplicates"
+        "deprecation",
+        "Duplicates"

Review Comment:
   This will slow down the extra time of tracing from 10 nanoseconds to 100+ ns or more, determined by how many `instanceof`s you have to run before the reflection.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1713711209

   > Any update @hxd123456
   
   I still need some time to complete it, I need to check the differences between each version of Monggo


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1713045127

   Any update @hxd123456 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1308314044


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoSpanHelper.java:
##########
@@ -43,6 +44,13 @@ public static void createExitSpan(String executeMethod, String remotePeer, Objec
         Tags.DB_TYPE.set(span, MongoConstants.DB_TYPE);
         SpanLayer.asDB(span);
 
+        if (operation instanceof EnhancedInstance) {

Review Comment:
   Welcome to join the review, but you should use English. 
   We need to keep all ppl synced.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wuwen5 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wuwen5 (via GitHub)" <gi...@apache.org>.
wuwen5 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1311794909


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {

Review Comment:
   `DeleteOperation `、`InsertOperation `、`UpdateOperation `,It seems that it can be simplified to `BaseWriteOperation`



##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {

Review Comment:
   `DeleteOperation `、`InsertOperation `、`UpdateOperation `,It seems that it can be simplified to `BaseWriteOperation`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1311804956


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {

Review Comment:
   This is not the best method, I should not use reflection to obtain it. I am trying to use a new solution to obtain this property



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] zhaoyunxing92 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "zhaoyunxing92 (via GitHub)" <gi...@apache.org>.
zhaoyunxing92 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1308306271


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((DeleteOperation) obj).getNamespace());
+        } else if (obj instanceof InsertOperation) {
+            databaseName = getOrDefaultDatabaseName(((InsertOperation) obj).getNamespace());
+        } else if (obj instanceof UpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((UpdateOperation) obj).getNamespace());
+        } else if (obj instanceof CreateIndexesOperation) {
+            Field namespace = CreateIndexesOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof FindAndDeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndDeleteOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndReplaceOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndReplaceOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndUpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndUpdateOperation) obj).getNamespace());
+        } else if (obj instanceof MixedBulkWriteOperation) {
+            databaseName = getOrDefaultDatabaseName(((MixedBulkWriteOperation) obj).getNamespace());
+        } else if (obj instanceof FindOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindOperation) obj).getNamespace());
+        } else if (obj instanceof CreateViewOperation) {
+            databaseName = ((CreateViewOperation) obj).getDatabaseName();
+        } else if (obj instanceof ListCollectionsOperation) {
+            Field databaseNameObj = ListCollectionsOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            databaseNameObj.setAccessible(true);
+            databaseName = (String) databaseNameObj.get(obj);
+        } else if (obj instanceof CreateCollectionOperation) {
+            Field namespace = CreateCollectionOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = (String) namespace.get(obj);
+        } else if (obj instanceof MapReduceToCollectionOperation) {
+            databaseName = ((MapReduceToCollectionOperation) obj).getDatabaseName();
+        } else {
+            return MongoConstants.EMPTY;
+        }
+        return databaseName;
+    }
+
+    private static String getOrDefaultDatabaseName(MongoNamespace mongoNamespace){
+        return mongoNamespace == null ? MongoConstants.EMPTY : mongoNamespace.getDatabaseName();

Review Comment:
   我最近更好也在改这个,我感觉用 `com.mongodb.MongoNamespace#getFullName` 会好点



##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoSpanHelper.java:
##########
@@ -43,6 +44,13 @@ public static void createExitSpan(String executeMethod, String remotePeer, Objec
         Tags.DB_TYPE.set(span, MongoConstants.DB_TYPE);
         SpanLayer.asDB(span);
 
+        if (operation instanceof EnhancedInstance) {

Review Comment:
   这个代码感觉放到下面会合理点,开启参数上报才上传这些



##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((DeleteOperation) obj).getNamespace());
+        } else if (obj instanceof InsertOperation) {
+            databaseName = getOrDefaultDatabaseName(((InsertOperation) obj).getNamespace());
+        } else if (obj instanceof UpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((UpdateOperation) obj).getNamespace());
+        } else if (obj instanceof CreateIndexesOperation) {
+            Field namespace = CreateIndexesOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof FindAndDeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndDeleteOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndReplaceOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndReplaceOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndUpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndUpdateOperation) obj).getNamespace());
+        } else if (obj instanceof MixedBulkWriteOperation) {
+            databaseName = getOrDefaultDatabaseName(((MixedBulkWriteOperation) obj).getNamespace());
+        } else if (obj instanceof FindOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindOperation) obj).getNamespace());
+        } else if (obj instanceof CreateViewOperation) {
+            databaseName = ((CreateViewOperation) obj).getDatabaseName();
+        } else if (obj instanceof ListCollectionsOperation) {
+            Field databaseNameObj = ListCollectionsOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            databaseNameObj.setAccessible(true);
+            databaseName = (String) databaseNameObj.get(obj);
+        } else if (obj instanceof CreateCollectionOperation) {
+            Field namespace = CreateCollectionOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = (String) namespace.get(obj);
+        } else if (obj instanceof MapReduceToCollectionOperation) {
+            databaseName = ((MapReduceToCollectionOperation) obj).getDatabaseName();
+        } else {
+            return MongoConstants.EMPTY;
+        }
+        return databaseName;
+    }
+
+    private static String getOrDefaultDatabaseName(MongoNamespace mongoNamespace){
+        return mongoNamespace == null ? MongoConstants.EMPTY : mongoNamespace.getDatabaseName();

Review Comment:
   我最近更好也在改这个,我感觉用 `com.mongodb.MongoNamespace#getFullName` 会好点



##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoSpanHelper.java:
##########
@@ -43,6 +44,13 @@ public static void createExitSpan(String executeMethod, String remotePeer, Objec
         Tags.DB_TYPE.set(span, MongoConstants.DB_TYPE);
         SpanLayer.asDB(span);
 
+        if (operation instanceof EnhancedInstance) {

Review Comment:
   这个代码感觉放到下面会合理点,开启参数上报才上传这些



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1689664897

   Meanwhile, as you are adding new tags for the MongoDB spans. The test scenarios of MongoDB should be updated accordingly.
   
   - https://github.com/apache/skywalking-java/tree/main/test/plugin/scenarios/mongodb-3.x-scenario
   - https://github.com/apache/skywalking-java/tree/main/test/plugin/scenarios/mongodb-4.x-scenario


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1302774989


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoInfoHelper.java:
##########
@@ -40,21 +41,26 @@
 import com.mongodb.internal.operation.UpdateOperation;
 import org.bson.BsonDocument;
 
+import java.lang.reflect.Field;
 import java.util.List;
 
 @SuppressWarnings({
-    "deprecation",
-    "Duplicates"
+        "deprecation",
+        "Duplicates"

Review Comment:
   This will slow down the extra time of tracing from 10 nanoseconds to 100+ ns or more, determined by how many `instanceof`s you have to run before the reflection.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wuwen5 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wuwen5 (via GitHub)" <gi...@apache.org>.
wuwen5 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1311794909


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {

Review Comment:
   `DeleteOperation `、`InsertOperation `、`UpdateOperation `,It seems that it can be simplified to use the `BaseWriteOperation`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] zhaoyunxing92 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "zhaoyunxing92 (via GitHub)" <gi...@apache.org>.
zhaoyunxing92 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1308363204


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((DeleteOperation) obj).getNamespace());
+        } else if (obj instanceof InsertOperation) {
+            databaseName = getOrDefaultDatabaseName(((InsertOperation) obj).getNamespace());
+        } else if (obj instanceof UpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((UpdateOperation) obj).getNamespace());
+        } else if (obj instanceof CreateIndexesOperation) {
+            Field namespace = CreateIndexesOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof FindAndDeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndDeleteOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndReplaceOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndReplaceOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndUpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndUpdateOperation) obj).getNamespace());
+        } else if (obj instanceof MixedBulkWriteOperation) {
+            databaseName = getOrDefaultDatabaseName(((MixedBulkWriteOperation) obj).getNamespace());
+        } else if (obj instanceof FindOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindOperation) obj).getNamespace());
+        } else if (obj instanceof CreateViewOperation) {
+            databaseName = ((CreateViewOperation) obj).getDatabaseName();
+        } else if (obj instanceof ListCollectionsOperation) {
+            Field databaseNameObj = ListCollectionsOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            databaseNameObj.setAccessible(true);
+            databaseName = (String) databaseNameObj.get(obj);
+        } else if (obj instanceof CreateCollectionOperation) {
+            Field namespace = CreateCollectionOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = (String) namespace.get(obj);
+        } else if (obj instanceof MapReduceToCollectionOperation) {
+            databaseName = ((MapReduceToCollectionOperation) obj).getDatabaseName();
+        } else {
+            return MongoConstants.EMPTY;
+        }
+        return databaseName;
+    }
+
+    private static String getOrDefaultDatabaseName(MongoNamespace mongoNamespace){
+        return mongoNamespace == null ? MongoConstants.EMPTY : mongoNamespace.getDatabaseName();

Review Comment:
   fullname=database + collection [fullName](https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/MongoNamespace.java#L115)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1694670588

   1. CI should be fixed.
   2. 3.x plugin is still using the old way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1737057036

   No update for weeks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng closed pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng closed pull request #597: Add mongoDB plugin report db instance info
URL: https://github.com/apache/skywalking-java/pull/597


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: [#11252]add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1302771948


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoInfoHelper.java:
##########
@@ -140,4 +146,65 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));

Review Comment:
   You are doing `instance of` and reflection for every request multiple times, usually this would cost significant resources of CPU and cause extra latency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: [#11252]add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1302769623


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoInfoHelper.java:
##########
@@ -40,21 +41,26 @@
 import com.mongodb.internal.operation.UpdateOperation;
 import org.bson.BsonDocument;
 
+import java.lang.reflect.Field;
 import java.util.List;
 
 @SuppressWarnings({
-    "deprecation",
-    "Duplicates"
+        "deprecation",
+        "Duplicates"

Review Comment:
   Have you done a local style check? You are changing the original source code format.
   Wrong code styles would cause all CIs failing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1302781791


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoInfoHelper.java:
##########
@@ -140,4 +146,65 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));

Review Comment:
   > This will slow down the extra time of tracing from 10 nanoseconds to 100+ ns or more, determined by how many `instanceof`s you have to run before the reflection.
   > 
   > As you are only trying to read DB instance info, can't you get that from the constructor of those `Operation`s? You could instrument those and use dynamic field to carry all necessary information. I believe from there, you don't need `instanceof` anymore.
   
   Okay, thank you for your prompt. I will modify this part of the code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1311828739


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {

Review Comment:
   `reflection` is also slow from a performance perspective. You could run a benchmark to see the result.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 closed pull request #597: [#11252]add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 closed pull request #597: [#11252]add mongoDB plugin report db instance info
URL: https://github.com/apache/skywalking-java/pull/597


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] zhaoyunxing92 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "zhaoyunxing92 (via GitHub)" <gi...@apache.org>.
zhaoyunxing92 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1308339061


##########
apm-sniffer/apm-sdk-plugin/mongodb-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v4/support/MongoSpanHelper.java:
##########
@@ -43,6 +44,13 @@ public static void createExitSpan(String executeMethod, String remotePeer, Objec
         Tags.DB_TYPE.set(span, MongoConstants.DB_TYPE);
         SpanLayer.asDB(span);
 
+        if (operation instanceof EnhancedInstance) {

Review Comment:
   I am also working on this recently and have implemented it, I can share my implementation ideas if needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 commented on a diff in pull request #597: Add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 commented on code in PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#discussion_r1308353219


##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((DeleteOperation) obj).getNamespace());
+        } else if (obj instanceof InsertOperation) {
+            databaseName = getOrDefaultDatabaseName(((InsertOperation) obj).getNamespace());
+        } else if (obj instanceof UpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((UpdateOperation) obj).getNamespace());
+        } else if (obj instanceof CreateIndexesOperation) {
+            Field namespace = CreateIndexesOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof FindAndDeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndDeleteOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndReplaceOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndReplaceOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndUpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndUpdateOperation) obj).getNamespace());
+        } else if (obj instanceof MixedBulkWriteOperation) {
+            databaseName = getOrDefaultDatabaseName(((MixedBulkWriteOperation) obj).getNamespace());
+        } else if (obj instanceof FindOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindOperation) obj).getNamespace());
+        } else if (obj instanceof CreateViewOperation) {
+            databaseName = ((CreateViewOperation) obj).getDatabaseName();
+        } else if (obj instanceof ListCollectionsOperation) {
+            Field databaseNameObj = ListCollectionsOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            databaseNameObj.setAccessible(true);
+            databaseName = (String) databaseNameObj.get(obj);
+        } else if (obj instanceof CreateCollectionOperation) {
+            Field namespace = CreateCollectionOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = (String) namespace.get(obj);
+        } else if (obj instanceof MapReduceToCollectionOperation) {
+            databaseName = ((MapReduceToCollectionOperation) obj).getDatabaseName();
+        } else {
+            return MongoConstants.EMPTY;
+        }
+        return databaseName;
+    }
+
+    private static String getOrDefaultDatabaseName(MongoNamespace mongoNamespace){
+        return mongoNamespace == null ? MongoConstants.EMPTY : mongoNamespace.getDatabaseName();

Review Comment:
   > 我最近更好也在改这个,我感觉用 `com.mongodb.MongoNamespace#getFullName` 会好点
   
   I don't understand what the information obtained through this method , I want to obtain the database name



##########
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoInfoHelper.java:
##########
@@ -143,4 +150,66 @@ private static String limitFilter(String filter) {
         }
     }
 
+    /**
+     * Get the databaseName
+     *
+     * @param obj operation
+     * @return databaseName
+     */
+    @SuppressWarnings("rawtypes")
+    public static String getMongoDatabaseName(Object obj) throws NoSuchFieldException, IllegalAccessException {
+        String databaseName = "";
+        if (obj instanceof CountOperation) {
+            Field namespace = CountOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof DistinctOperation) {
+            Field namespace = DistinctOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof MapReduceWithInlineResultsOperation) {
+            databaseName = getOrDefaultDatabaseName(((MapReduceWithInlineResultsOperation) obj).getNamespace());
+        } else if (obj instanceof DeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((DeleteOperation) obj).getNamespace());
+        } else if (obj instanceof InsertOperation) {
+            databaseName = getOrDefaultDatabaseName(((InsertOperation) obj).getNamespace());
+        } else if (obj instanceof UpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((UpdateOperation) obj).getNamespace());
+        } else if (obj instanceof CreateIndexesOperation) {
+            Field namespace = CreateIndexesOperation.class.getDeclaredField(NAMESPACE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = getOrDefaultDatabaseName((MongoNamespace) namespace.get(obj));
+        } else if (obj instanceof FindAndDeleteOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndDeleteOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndReplaceOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndReplaceOperation) obj).getNamespace());
+        } else if (obj instanceof FindAndUpdateOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindAndUpdateOperation) obj).getNamespace());
+        } else if (obj instanceof MixedBulkWriteOperation) {
+            databaseName = getOrDefaultDatabaseName(((MixedBulkWriteOperation) obj).getNamespace());
+        } else if (obj instanceof FindOperation) {
+            databaseName = getOrDefaultDatabaseName(((FindOperation) obj).getNamespace());
+        } else if (obj instanceof CreateViewOperation) {
+            databaseName = ((CreateViewOperation) obj).getDatabaseName();
+        } else if (obj instanceof ListCollectionsOperation) {
+            Field databaseNameObj = ListCollectionsOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            databaseNameObj.setAccessible(true);
+            databaseName = (String) databaseNameObj.get(obj);
+        } else if (obj instanceof CreateCollectionOperation) {
+            Field namespace = CreateCollectionOperation.class.getDeclaredField(DATABASE_FIELD_NAME);
+            namespace.setAccessible(true);
+            databaseName = (String) namespace.get(obj);
+        } else if (obj instanceof MapReduceToCollectionOperation) {
+            databaseName = ((MapReduceToCollectionOperation) obj).getDatabaseName();
+        } else {
+            return MongoConstants.EMPTY;
+        }
+        return databaseName;
+    }
+
+    private static String getOrDefaultDatabaseName(MongoNamespace mongoNamespace){
+        return mongoNamespace == null ? MongoConstants.EMPTY : mongoNamespace.getDatabaseName();

Review Comment:
   > 我最近更好也在改这个,我感觉用 `com.mongodb.MongoNamespace#getFullName` 会好点
   
   I don't understand what the information obtained through this method , I want to obtain the database name



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1696654273

   > @hxd123456 Do you have an estimated time to finish this? I am planning the first agent v9 release. This is the only open issues/PR.
   
   If it needs to be released in v9 version, it should be too late. I need some time to understand the relevant knowledge of mongodb v3


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [skywalking-java] hxd123456 commented on pull request #597: Add mongoDB plugin report db instance info

Posted by "hxd123456 (via GitHub)" <gi...@apache.org>.
hxd123456 commented on PR #597:
URL: https://github.com/apache/skywalking-java/pull/597#issuecomment-1694670990

   > 1. CI should be fixed.
   > 2. 3.x plugin is still using the old way.
   
   I am currently fixing the issue with the v3 version, but I apologize that it will not be completed until next week


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org