use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaConsumerTracingInterceptorTest method afterPoll2.
@Test
public void afterPoll2() {
KafkaConsumerTracingInterceptor interceptor = new KafkaConsumerTracingInterceptor();
MockKafkaConsumer kafkaConsumer = MockKafkaConsumer.buildOne();
Map<TopicPartition, List<ConsumerRecord<String, String>>> records = new HashMap<>();
records.put(new TopicPartition(topic1, 1), Collections.singletonList(record(topic1, 0)));
records.put(new TopicPartition(topic2, 1), Collections.singletonList(record(topic2, 0)));
List<ReportSpan> mockSpans = new ArrayList<>();
MockEaseAgent.setMockSpanReport(mockSpans::add);
String uri = (String) kafkaConsumer.getEaseAgent$$DynamicField$$Data();
ConsumerRecords<String, String> consumerRecords = new ConsumerRecords<>(records);
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(2, mockSpans.size());
checkTowTopicMockSpans(mockSpans, uri);
mockSpans.clear();
consumerRecords = new ConsumerRecords<>(towTopicAndTenRecords());
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(2, mockSpans.size());
checkTowTopicMockSpans(mockSpans, uri);
mockSpans.clear();
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(10, mockSpans.size());
checkTowTopicMockSpans(mockSpans, uri);
mockSpans.clear();
MockEaseAgent.setMockSpanReport(mockSpans::add);
consumerRecords = new ConsumerRecords<>(towTopicAndTenRecords());
interceptor.singleRootSpanOnReceiveBatch = false;
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(10, mockSpans.size());
checkTowTopicMockSpans(mockSpans, uri);
mockSpans.clear();
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaConsumerTracingInterceptorTest method setConsumerSpan.
@Test
public void setConsumerSpan() {
KafkaConsumerTracingInterceptor interceptor = new KafkaConsumerTracingInterceptor();
Context context = EaseAgent.getContext();
Span span = context.nextSpan().start();
String topic = "testTopic";
String uri = "testUri";
interceptor.setConsumerSpan(topic, uri, span);
span.finish();
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
checkBaseInfo(mockSpan, topic, uri);
KafkaAbstractConfigConstructInterceptor kafkaAbstractConfigConstructInterceptor = new KafkaAbstractConfigConstructInterceptor();
KafkaTestUtils.mockRedirect(() -> {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { props }).build();
kafkaAbstractConfigConstructInterceptor.doBefore(methodInfo, EaseAgent.getContext());
MockKafkaConsumer kafkaConsumer = new MockKafkaConsumer(props);
kafkaConsumer.setEaseAgent$$DynamicField$$Data(props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
Span span1 = context.nextSpan().start();
interceptor.setConsumerSpan(topic, (String) kafkaConsumer.getEaseAgent$$DynamicField$$Data(), span1);
span1.finish();
ReportSpan mockSpan1 = MockEaseAgent.getLastSpan();
assertEquals(TestConst.REDIRECT_URIS, mockSpan1.tag("label.remote"));
});
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class JdbcStmTracingInterceptorTest method doBefore.
@Test
public void doBefore() throws SQLException {
JdbcStmTracingInterceptor interceptor = new JdbcStmTracingInterceptor();
Context context = EaseAgent.getContext();
InterceptorTestUtils.init(interceptor, new JdbcTracingPlugin());
String method = "test_method";
MethodInfo methodInfo = MethodInfo.builder().method(method).build();
interceptor.doBefore(methodInfo, context);
assertNull(context.get(JdbcStmTracingInterceptor.SPAN_KEY));
SqlInfo sqlInfo = new SqlInfo(TestUtils.mockConnection());
String sql = "select * from data";
sqlInfo.addSql(sql, false);
context.put(SqlInfo.class, sqlInfo);
interceptor.doBefore(methodInfo, context);
Span span = context.remove(JdbcStmTracingInterceptor.SPAN_KEY);
assertNotNull(span);
span.finish();
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, reportSpan);
assertEquals(method, reportSpan.name());
assertEquals(Span.Kind.CLIENT.name(), reportSpan.kind());
assertEquals(SQLCompressionFactory.getSqlCompression().compress(sql), reportSpan.tag(JdbcStmTracingInterceptor.SPAN_SQL_QUERY_TAG_NAME));
assertEquals("database", reportSpan.tag(JdbcStmTracingInterceptor.SPAN_LOCAL_COMPONENT_TAG_NAME));
assertEquals(TestUtils.URI, reportSpan.tag(JdbcStmTracingInterceptor.SPAN_URL));
assertEquals(Type.DATABASE.getRemoteType(), reportSpan.tag(MiddlewareConstants.TYPE_TAG_NAME));
assertEquals(TestUtils.DATABASE, reportSpan.remoteServiceName());
assertEquals(TestUtils.HOST, reportSpan.remoteEndpoint().ipv4());
assertEquals(TestUtils.PORT, reportSpan.remoteEndpoint().port());
TestUtils.setRedirect();
RedirectProcessor.redirected(Redirect.DATABASE, TestUtils.URI);
interceptor.doBefore(methodInfo, context);
span = context.remove(JdbcStmTracingInterceptor.SPAN_KEY);
assertNotNull(span);
span.finish();
reportSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, reportSpan);
assertEquals(TestUtils.URI, reportSpan.tag(MiddlewareConstants.REDIRECTED_LABEL_REMOTE_TAG_NAME));
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class AgentCoreSubscriberTest method onError.
@Test
public void onError() throws URISyntaxException {
MockCoreSubscriber mockCoreSubscriber = new MockCoreSubscriber();
String errorInfo = "test error";
WebClientFilterTracingInterceptor interceptor = new WebClientFilterTracingInterceptor();
Context context = EaseAgent.getContext();
URI uri = new URI(url);
ClientRequest clientRequest = MockClientRequest.build(uri);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).build();
interceptor.doBefore(methodInfo, context);
RequestContext requestContext = context.get(interceptor.getProgressKey());
AgentCoreSubscriber agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, methodInfo, requestContext);
agentCoreSubscriber.onError(new RuntimeException(errorInfo));
assertFalse(methodInfo.isSuccess());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertTrue(mockSpan.hasError());
assertEquals(errorInfo, mockSpan.errorInfo());
assertTrue(mockCoreSubscriber.onError.get());
MockEaseAgent.cleanLastSpan();
methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).build();
interceptor.doBefore(methodInfo, context);
requestContext = context.get(interceptor.getProgressKey());
agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, methodInfo, requestContext);
ClientResponse clientResponse = MockDefaultClientResponse.builder(500).build();
agentCoreSubscriber.onNext(clientResponse);
agentCoreSubscriber.onError(new RuntimeException(errorInfo));
assertFalse(methodInfo.isSuccess());
mockSpan = MockEaseAgent.getLastSpan();
assertTrue(mockSpan.hasError());
assertEquals(errorInfo, mockSpan.errorInfo());
assertEquals("500", mockSpan.tag("http.status_code"));
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class AgentCoreSubscriberTest method onComplete.
@Test
public void onComplete() throws URISyntaxException {
MockCoreSubscriber mockCoreSubscriber = new MockCoreSubscriber();
WebClientFilterTracingInterceptor interceptor = new WebClientFilterTracingInterceptor();
Context context = EaseAgent.getContext();
URI uri = new URI(url);
ClientRequest clientRequest = MockClientRequest.build(uri);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).build();
interceptor.doBefore(methodInfo, context);
RequestContext requestContext = context.get(interceptor.getProgressKey());
AgentCoreSubscriber agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, methodInfo, requestContext);
agentCoreSubscriber.onComplete();
assertTrue(mockCoreSubscriber.onComplete.get());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertFalse(mockSpan.hasError());
MockEaseAgent.cleanLastSpan();
methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).build();
interceptor.doBefore(methodInfo, context);
requestContext = context.get(interceptor.getProgressKey());
agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, methodInfo, requestContext);
ClientResponse clientResponse = MockDefaultClientResponse.builder(203).build();
agentCoreSubscriber.onNext(clientResponse);
agentCoreSubscriber.onComplete();
assertTrue(mockCoreSubscriber.onComplete.get());
mockSpan = MockEaseAgent.getLastSpan();
assertFalse(mockSpan.hasError());
}
Aggregations