From e42bf6e014597d9b43df0c3b7955aeedaac36e8c Mon Sep 17 00:00:00 2001 From: baiyang Date: Wed, 19 Apr 2017 20:22:32 +0800 Subject: [PATCH] Add a flag to determine whether to bind data --- .../java/com/a/eye/skywalking/api/conf/Config.java | 7 +++++++ .../plugin/mongodb/v3/MongoDBMethodInterceptor.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java index 96aaafa131..6bca636d90 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java @@ -23,6 +23,13 @@ public class Config { * Zero and negative number are illegal. */ public static int SAMPLING_CYCLE = 1; + + /** + * Set Mongodb plugin whether to bind params + * False=Not bound + * True=Binding + */ + public static boolean MONGODB_BINDPARAM = false; } public static class Collector { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptor.java index 9d7f8cdf34..21015772a3 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptor.java @@ -4,6 +4,7 @@ import java.util.List; import org.bson.BsonDocument; +import com.a.eye.skywalking.api.conf.Config; import com.a.eye.skywalking.api.context.ContextManager; import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; @@ -65,13 +66,18 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto public void beforeMethod(final EnhancedClassInstanceContext context, final InstanceMethodInvokeContext interceptorContext, final MethodInterceptResult result) { Object[] arguments = interceptorContext.allArguments(); - OperationInfo operationInfo = this.getReadOperationInfo(arguments[0]); - Span span = ContextManager.createSpan(METHOD + operationInfo.getMethodName()); + Span span = null; + if (Config.Agent.MONGODB_BINDPARAM) { + OperationInfo operationInfo = this.getReadOperationInfo(arguments[0]); + span = ContextManager.createSpan(METHOD + operationInfo.getMethodName()); + Tags.DB_STATEMENT.set(span, operationInfo.getMethodName() + " " + operationInfo.getFilter()); + } else { + span = ContextManager.createSpan(METHOD + arguments[0].getClass().getSimpleName()); + } Tags.COMPONENT.set(span, MONGODB_COMPONENT); Tags.DB_TYPE.set(span, MONGODB_COMPONENT); Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); Tags.SPAN_LAYER.asDB(span); - Tags.DB_STATEMENT.set(span, operationInfo.getMethodName() + " " + operationInfo.getFilter()); } @Override -- GitLab