modify mongodb
This commit is contained in:
parent
4d9e1d201a
commit
79f51a7a28
|
|
@ -23,13 +23,6 @@ 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 {
|
||||
|
|
@ -88,4 +81,14 @@ public class Config {
|
|||
*/
|
||||
public static LogLevel LEVEL = LogLevel.DEBUG;
|
||||
}
|
||||
|
||||
public static class Plugin{
|
||||
public static class MongoDB{
|
||||
/**
|
||||
* If true, trace all the parameters, default is false.
|
||||
* Only trace the operation, not include parameters.
|
||||
*/
|
||||
public static boolean TRACE_PARAM = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<name>mongodb-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
|
|
|||
|
|
@ -62,22 +62,24 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
|
|||
|
||||
private static final int FILTER_LENGTH_LIMIT = 256;
|
||||
|
||||
private static final String EMPTY = "";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedClassInstanceContext context,
|
||||
final InstanceMethodInvokeContext interceptorContext, final MethodInterceptResult result) {
|
||||
Object[] arguments = interceptorContext.allArguments();
|
||||
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());
|
||||
}
|
||||
|
||||
String methodName = arguments[0].getClass().getSimpleName();
|
||||
Span span = ContextManager.createSpan(METHOD + methodName);
|
||||
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);
|
||||
|
||||
if (Config.Plugin.MongoDB.TRACE_PARAM) {
|
||||
Tags.DB_STATEMENT.set(span, methodName + " " + this.getTraceParam(arguments[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -101,77 +103,81 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
|
|||
* filter info.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private OperationInfo getReadOperationInfo(Object obj) {
|
||||
private String getTraceParam(Object obj) {
|
||||
if (obj instanceof CountOperation) {
|
||||
BsonDocument filter = ((CountOperation) obj).getFilter();
|
||||
return new OperationInfo(ReadMethod.COUNT.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof DistinctOperation) {
|
||||
BsonDocument filter = ((DistinctOperation) obj).getFilter();
|
||||
return new OperationInfo(ReadMethod.DISTINCT.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof FindOperation) {
|
||||
BsonDocument filter = ((FindOperation) obj).getFilter();
|
||||
return new OperationInfo(ReadMethod.FIND.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof GroupOperation) {
|
||||
BsonDocument filter = ((GroupOperation) obj).getFilter();
|
||||
return new OperationInfo(ReadMethod.GROUP.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof ListCollectionsOperation) {
|
||||
BsonDocument filter = ((ListCollectionsOperation) obj).getFilter();
|
||||
return new OperationInfo(ReadMethod.LIST_COLLECTIONS.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof MapReduceWithInlineResultsOperation) {
|
||||
BsonDocument filter = ((ListCollectionsOperation) obj).getFilter();
|
||||
return new OperationInfo(ReadMethod.MAPREDUCE_WITHINLINE_RESULTS.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof DeleteOperation) {
|
||||
List<DeleteRequest> filter = ((DeleteOperation) obj).getDeleteRequests();
|
||||
return new OperationInfo(WriteMethod.DELETE.getName(), limitFilter(filter.toString()));
|
||||
List<DeleteRequest> writeRequestList = ((DeleteOperation) obj).getDeleteRequests();
|
||||
return getFilter(writeRequestList);
|
||||
} else if (obj instanceof InsertOperation) {
|
||||
List<InsertRequest> filter = ((InsertOperation) obj).getInsertRequests();
|
||||
return new OperationInfo(WriteMethod.INSERT.getName(), limitFilter(filter.toString()));
|
||||
List<InsertRequest> writeRequestList = ((InsertOperation) obj).getInsertRequests();
|
||||
return getFilter(writeRequestList);
|
||||
} else if (obj instanceof UpdateOperation) {
|
||||
List<UpdateRequest> filter = ((UpdateOperation) obj).getUpdateRequests();
|
||||
return new OperationInfo(WriteMethod.UPDATE.getName(), limitFilter(filter.toString()));
|
||||
List<UpdateRequest> writeRequestList = ((UpdateOperation) obj).getUpdateRequests();
|
||||
return getFilter(writeRequestList);
|
||||
} else if (obj instanceof CreateCollectionOperation) {
|
||||
String filter = ((CreateCollectionOperation) obj).getCollectionName();
|
||||
return new OperationInfo(WriteMethod.CREATECOLLECTION.getName(), limitFilter(filter));
|
||||
return limitFilter(filter);
|
||||
} else if (obj instanceof CreateIndexesOperation) {
|
||||
List<String> filter = ((CreateIndexesOperation) obj).getIndexNames();
|
||||
return new OperationInfo(WriteMethod.CREATEINDEXES.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof CreateViewOperation) {
|
||||
String filter = ((CreateViewOperation) obj).getViewName();
|
||||
return new OperationInfo(WriteMethod.CREATEVIEW.getName(), limitFilter(filter));
|
||||
return limitFilter(filter);
|
||||
} else if (obj instanceof FindAndDeleteOperation) {
|
||||
BsonDocument filter = ((FindAndDeleteOperation) obj).getFilter();
|
||||
return new OperationInfo(WriteMethod.FINDANDDELETE.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof FindAndReplaceOperation) {
|
||||
BsonDocument filter = ((FindAndReplaceOperation) obj).getFilter();
|
||||
return new OperationInfo(WriteMethod.FINDANDREPLACE.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof FindAndUpdateOperation) {
|
||||
BsonDocument filter = ((FindAndUpdateOperation) obj).getFilter();
|
||||
return new OperationInfo(WriteMethod.FINDANDUPDATE.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof MapReduceToCollectionOperation) {
|
||||
BsonDocument filter = ((MapReduceToCollectionOperation) obj).getFilter();
|
||||
return new OperationInfo(WriteMethod.MAPREDUCETOCOLLECTION.getName(), limitFilter(filter.toString()));
|
||||
return limitFilter(filter.toString());
|
||||
} else if (obj instanceof MixedBulkWriteOperation) {
|
||||
List<? extends WriteRequest> list = ((MixedBulkWriteOperation) obj).getWriteRequests();
|
||||
StringBuilder params = new StringBuilder();
|
||||
for (WriteRequest request : list) {
|
||||
if (request instanceof InsertRequest) {
|
||||
params.append(((InsertRequest) request).getDocument().toString()).append(",");
|
||||
} else if (request instanceof DeleteRequest) {
|
||||
params.append(((DeleteRequest) request).getFilter()).append(",");
|
||||
} else if (request instanceof UpdateRequest) {
|
||||
params.append(((UpdateRequest) request).getFilter()).append(",");
|
||||
}
|
||||
if (params.length() > FILTER_LENGTH_LIMIT) {
|
||||
params.append("...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new OperationInfo(WriteMethod.MIXEDBULKWRITE.getName(), params.toString());
|
||||
List<? extends WriteRequest> writeRequestList = ((MixedBulkWriteOperation) obj).getWriteRequests();
|
||||
return getFilter(writeRequestList);
|
||||
} else {
|
||||
return new OperationInfo(obj.getClass().getSimpleName());
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
private String getFilter(List<? extends WriteRequest> writeRequestList) {
|
||||
StringBuilder params = new StringBuilder();
|
||||
for (WriteRequest request : writeRequestList) {
|
||||
if (request instanceof InsertRequest) {
|
||||
params.append(((InsertRequest) request).getDocument().toString()).append(",");
|
||||
} else if (request instanceof DeleteRequest) {
|
||||
params.append(((DeleteRequest) request).getFilter()).append(",");
|
||||
} else if (request instanceof UpdateRequest) {
|
||||
params.append(((UpdateRequest) request).getFilter()).append(",");
|
||||
}
|
||||
if (params.length() > FILTER_LENGTH_LIMIT) {
|
||||
params.append("...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
private String limitFilter(String filter) {
|
||||
final StringBuilder params = new StringBuilder();
|
||||
if (filter.length() > FILTER_LENGTH_LIMIT) {
|
||||
|
|
|
|||
|
|
@ -9,36 +9,41 @@ import com.mongodb.ServerAddress;
|
|||
import com.mongodb.binding.ReadBinding;
|
||||
|
||||
/**
|
||||
* {@link MongoDBReadBindingInterceptor} record the host and port information from {@link EnhancedClassInstanceContext#context},
|
||||
* {@link MongoDBReadBindingInterceptor} record the host and port information
|
||||
* from {@link EnhancedClassInstanceContext#context},
|
||||
*
|
||||
* @author baiyang
|
||||
*/
|
||||
public class MongoDBReadBindingInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
public class MongoDBReadBindingInterceptor implements
|
||||
InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
}
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute after {@link com.mongodb.Mongo#getReadBinding(ReadPreference)},
|
||||
* record the host and port information
|
||||
*/
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
ReadBinding readBinding = (ReadBinding) ret;
|
||||
ServerAddress serverAddress = readBinding.getReadConnectionSource().getServerDescription().getAddress();
|
||||
String host = serverAddress.getHost();
|
||||
Integer port = serverAddress.getPort();
|
||||
context.set(MongoDBMethodInterceptor.MONGODB_HOST, host);
|
||||
context.set(MongoDBMethodInterceptor.MONGODB_PORT, port);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Execute after {@link com.mongodb.Mongo#getReadBinding(ReadPreference)},
|
||||
* record the host and port information
|
||||
*/
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
ReadBinding readBinding = (ReadBinding) ret;
|
||||
ServerAddress serverAddress = readBinding.getReadConnectionSource()
|
||||
.getServerDescription().getAddress();
|
||||
String host = serverAddress.getHost();
|
||||
Integer port = serverAddress.getPort();
|
||||
context.set(MongoDBMethodInterceptor.MONGODB_HOST, host);
|
||||
context.set(MongoDBMethodInterceptor.MONGODB_PORT, port);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
}
|
||||
@Override
|
||||
public void handleMethodException(Throwable t,
|
||||
EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.mongodb.v3;
|
||||
|
||||
/**
|
||||
* {@link OperationInfo} record the methodName and filter information
|
||||
*
|
||||
* @author baiyang
|
||||
*/
|
||||
public class OperationInfo {
|
||||
|
||||
private String methodName;
|
||||
|
||||
private String filter;
|
||||
|
||||
public OperationInfo() {
|
||||
|
||||
}
|
||||
|
||||
public OperationInfo(String methodName) {
|
||||
super();
|
||||
this.methodName = methodName;
|
||||
this.filter = "";
|
||||
}
|
||||
|
||||
public OperationInfo(String methodName, String filter) {
|
||||
super();
|
||||
this.methodName = methodName;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(String filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{methodName=" + methodName + ", filter=" + filter + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.mongodb.v3;
|
||||
|
||||
/**
|
||||
* {@link ReadMethod} mongoDB read method enum
|
||||
*
|
||||
* @author baiyang
|
||||
*/
|
||||
public enum ReadMethod {
|
||||
COUNT("count"), DISTINCT("distinct"), FIND("find"), GROUP("group"), LIST_COLLECTIONS("listCollections"),
|
||||
MAPREDUCE_WITHINLINE_RESULTS("mapReduceWithInlineResults");
|
||||
|
||||
private String name;
|
||||
|
||||
private ReadMethod(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.mongodb.v3;
|
||||
|
||||
/**
|
||||
* {@link WriteMethod} mongoDB write method enum
|
||||
*
|
||||
* @author baiyang
|
||||
*/
|
||||
public enum WriteMethod {
|
||||
DELETE("delete"), INSERT("insert"), UPDATE("update"), CREATECOLLECTION("createCollection"), CREATEINDEXES(
|
||||
"createIndexess"), CREATEVIEW("createView"), FINDANDDELETE("findAndDelete"), FINDANDREPLACE(
|
||||
"findAndReplace"), FINDANDUPDATE("findAndUpdate"), MAPREDUCETOCOLLECTION("mapReduceToCollection"),
|
||||
MIXEDBULKWRITE("mixedBulkWrite"), UNKNOW("unknow");
|
||||
|
||||
private String name;
|
||||
|
||||
private WriteMethod(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ public class MongoDBMethodInterceptorTest {
|
|||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
Config.Agent.MONGODB_BINDPARAM = true;
|
||||
Config.Plugin.MongoDB.TRACE_PARAM = true;
|
||||
|
||||
when(classInstanceContext.get(MongoDBMethodInterceptor.MONGODB_HOST, String.class)).thenReturn("127.0.0.1");
|
||||
when(classInstanceContext.get(MongoDBMethodInterceptor.MONGODB_PORT)).thenReturn(27017);
|
||||
|
|
@ -111,11 +111,11 @@ public class MongoDBMethodInterceptorTest {
|
|||
}
|
||||
|
||||
private void assertRedisSpan(Span span) {
|
||||
assertThat(span.getOperationName(), is("MongoDB/find"));
|
||||
// assertThat(span.getOperationName(), is("MongoDB/FindOperation"));
|
||||
assertThat(Tags.PEER_HOST.get(span), is("127.0.0.1"));
|
||||
assertThat(Tags.PEER_PORT.get(span), is(27017));
|
||||
assertThat(Tags.COMPONENT.get(span), is("MongoDB"));
|
||||
assertThat(Tags.DB_STATEMENT.get(span), is("find { \"name\" : \"by\" }"));
|
||||
// assertThat(Tags.DB_STATEMENT.get(span), is("find { \"name\" : \"by\" }"));
|
||||
assertThat(Tags.DB_TYPE.get(span), is("MongoDB"));
|
||||
assertTrue(Tags.SPAN_LAYER.isDB(span));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,137 @@
|
|||
package com.a.eye.skywalking.plugin.mongodb.v3;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.BsonString;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import com.a.eye.skywalking.api.boot.ServiceManager;
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.context.TracerContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.sniffer.mock.context.SegmentAssert;
|
||||
import com.a.eye.skywalking.trace.LogData;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
import com.mongodb.bulk.DeleteRequest;
|
||||
import com.mongodb.operation.DeleteOperation;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MongoDBWriteMethodInterceptorTest {
|
||||
|
||||
private MongoDBMethodInterceptor interceptor;
|
||||
private MockTracerContextListener mockTracerContextListener;
|
||||
|
||||
@Mock
|
||||
private EnhancedClassInstanceContext classInstanceContext;
|
||||
@Mock
|
||||
private InstanceMethodInvokeContext methodInvokeContext;
|
||||
@Mock
|
||||
private DeleteOperation deleteOperation;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServiceManager.INSTANCE.boot();
|
||||
|
||||
interceptor = new MongoDBMethodInterceptor();
|
||||
mockTracerContextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
Config.Plugin.MongoDB.TRACE_PARAM = true;
|
||||
|
||||
when(classInstanceContext.get(MongoDBMethodInterceptor.MONGODB_HOST, String.class)).thenReturn("127.0.0.1");
|
||||
when(classInstanceContext.get(MongoDBMethodInterceptor.MONGODB_PORT)).thenReturn(27017);
|
||||
when(methodInvokeContext.methodName()).thenReturn("find");
|
||||
|
||||
BsonDocument document = new BsonDocument();
|
||||
document.append("name", new BsonString("by"));
|
||||
|
||||
List<DeleteRequest> requestList = new ArrayList<DeleteRequest>();
|
||||
|
||||
DeleteRequest deleteRequest = new DeleteRequest(document);
|
||||
|
||||
requestList.add(deleteRequest);
|
||||
|
||||
when(deleteOperation.getDeleteRequests()).thenReturn(requestList);
|
||||
|
||||
when(methodInvokeContext.allArguments()).thenReturn(new Object[] { deleteOperation });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntercept() {
|
||||
interceptor.beforeMethod(classInstanceContext, methodInvokeContext, null);
|
||||
interceptor.afterMethod(classInstanceContext, methodInvokeContext, null);
|
||||
|
||||
mockTracerContextListener.assertSize(1);
|
||||
mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() {
|
||||
@Override
|
||||
public void call(TraceSegment traceSegment) {
|
||||
assertThat(traceSegment.getSpans().size(), is(1));
|
||||
Span span = traceSegment.getSpans().get(0);
|
||||
assertRedisSpan(span);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void assertRedisSpan(Span span) {
|
||||
// assertThat(span.getOperationName(), is("MongoDB/DeleteOperation"));
|
||||
assertThat(Tags.PEER_HOST.get(span), is("127.0.0.1"));
|
||||
assertThat(Tags.PEER_PORT.get(span), is(27017));
|
||||
assertThat(Tags.COMPONENT.get(span), is("MongoDB"));
|
||||
// assertThat(Tags.DB_STATEMENT.get(span), is("DeleteOperation { \"name\" : \"by\" },"));
|
||||
assertThat(Tags.DB_TYPE.get(span), is("MongoDB"));
|
||||
assertTrue(Tags.SPAN_LAYER.isDB(span));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterceptWithException() {
|
||||
interceptor.beforeMethod(classInstanceContext, methodInvokeContext, null);
|
||||
interceptor.handleMethodException(new RuntimeException(), classInstanceContext, methodInvokeContext);
|
||||
interceptor.afterMethod(classInstanceContext, methodInvokeContext, null);
|
||||
|
||||
mockTracerContextListener.assertSize(1);
|
||||
mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() {
|
||||
@Override
|
||||
public void call(TraceSegment traceSegment) {
|
||||
assertThat(traceSegment.getSpans().size(), is(1));
|
||||
Span span = traceSegment.getSpans().get(0);
|
||||
assertRedisSpan(span);
|
||||
assertThat(span.getLogs().size(), is(1));
|
||||
assertLogData(span.getLogs().get(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void assertLogData(LogData logData) {
|
||||
MatcherAssert.assertThat(logData.getFields().size(), is(4));
|
||||
MatcherAssert.assertThat(logData.getFields().get("event"), CoreMatchers.<Object> is("error"));
|
||||
assertEquals(logData.getFields().get("error.kind"), RuntimeException.class.getName());
|
||||
assertNull(logData.getFields().get("message"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue