Better witness class for mongo3.8.x (#5524)

* modify witness class

* modify witness class & add test case

* replace DB_STATEMENT to DB_BIND_VARIABLES & remove executeMethod prefix

* fix ci

Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
harvies 2020-09-22 09:50:44 +08:00 committed by GitHub
parent 075cb981a9
commit c3edd3dad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 5 deletions

View File

@ -35,7 +35,7 @@ import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
*/
public class MongoDBOperationExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String WITNESS_CLASS = "com.mongodb.client.ClientSession";
private static final String WITNESS_CLASS = "com.mongodb.operation.AggregateOperationImpl";
private static final String ENHANCE_CLASS = "com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor";

View File

@ -39,7 +39,7 @@ public class MongoSpanHelper {
SpanLayer.asDB(span);
if (MongoPluginConfig.Plugin.MongoDB.TRACE_PARAM) {
Tags.DB_STATEMENT.set(span, executeMethod + " " + MongoOperationHelper.getTraceParam(operation));
Tags.DB_BIND_VARIABLES.set(span, MongoOperationHelper.getTraceParam(operation));
}
}
}

View File

@ -128,7 +128,7 @@ public class MongoDBInterceptorTest {
assertThat(span.getOperationName(), is("MongoDB/FindOperation"));
assertThat(SpanHelper.getComponentId(span), is(42));
List<TagValuePair> tags = SpanHelper.getTags(span);
assertThat(tags.get(1).getValue(), is("FindOperation {\"name\": \"by\"}"));
assertThat(tags.get(1).getValue(), is("{\"name\": \"by\"}"));
assertThat(tags.get(0).getValue(), is("MongoDB"));
assertThat(span.isExit(), is(true));
assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB));

View File

@ -127,7 +127,7 @@ public class MongoDBOperationExecutorInterceptorTest {
assertThat(span.getOperationName(), is("MongoDB/FindOperation"));
assertThat(SpanHelper.getComponentId(span), is(42));
List<TagValuePair> tags = SpanHelper.getTags(span);
assertThat(tags.get(1).getValue(), is("FindOperation {\"name\": \"by\"}"));
assertThat(tags.get(1).getValue(), is("{\"name\": \"by\"}"));
assertThat(tags.get(0).getValue(), is("MongoDB"));
assertThat(span.isExit(), is(true));
assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB));

View File

@ -18,4 +18,4 @@
home="$(cd "$(dirname $0)"; pwd)"
java -jar ${agent_opts} ${home}/../libs/mongodb-3.x-scenario.jar &
java -jar -Dskywalking.plugin.mongodb.trace_param=true ${agent_opts} ${home}/../libs/mongodb-3.x-scenario.jar &

View File

@ -32,6 +32,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: MongoDB/MixedBulkWriteOperation
operationId: 0
@ -46,6 +47,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: MongoDB/FindOperation
operationId: 0
@ -60,6 +62,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: MongoDB/MixedBulkWriteOperation
operationId: 0
@ -74,6 +77,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: MongoDB/FindOperation
operationId: 0
@ -88,6 +92,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: MongoDB/MixedBulkWriteOperation
operationId: 0
@ -102,6 +107,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: MongoDB/DropDatabaseOperation
operationId: 0
@ -116,6 +122,7 @@ segmentItems:
peer: mongodb-server:27017
tags:
- {key: db.type, value: MongoDB}
- {key: db.bind_vars, value: not null}
skipAnalysis: 'false'
- operationName: /mongodb-case/case/mongodb
operationId: 0