use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class LettuceTracingInterceptorTest method doTraceBefore.
@Test
public void doTraceBefore() {
LettuceTracingInterceptor lettuceTracingInterceptor = new LettuceTracingInterceptor();
Context context = EaseAgent.getContext();
MethodInfo methodInfo = MethodInfo.builder().invoker("tttt").args(new Object[] { "get" }).build();
lettuceTracingInterceptor.doTraceBefore(methodInfo, context);
Span span = context.remove(CommonRedisTracingInterceptorTest.SPAN_KEY);
span.finish();
ReportSpan mockSpan = Objects.requireNonNull(MockEaseAgent.getLastSpan());
assertNull(mockSpan.name());
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals("redis", mockSpan.remoteServiceName());
assertEquals(Type.REDIS.getRemoteType(), mockSpan.tag(MiddlewareConstants.TYPE_TAG_NAME));
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class RabbitMqConsumerTracingInterceptorTest method before.
@Test
public void before() {
RabbitMqConsumerTracingInterceptor interceptor = new RabbitMqConsumerTracingInterceptor();
Context context = EaseAgent.getContext();
String uri = "192.168.0.13:2222";
context.put(ContextCons.MQ_URI, uri);
String exchange = "testExchange";
String routingKey = "testRoutingKey";
Envelope envelope = new Envelope(0, false, exchange, routingKey);
AMQP.BasicProperties basicProperties = new AMQP.BasicProperties();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { null, envelope, basicProperties }).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
assertNotNull(reportSpan);
assertEquals(Span.Kind.CONSUMER.name(), reportSpan.kind());
assertEquals(exchange, reportSpan.tag("rabbit.exchange"));
assertEquals(routingKey, reportSpan.tag("rabbit.routing_key"));
assertEquals(routingKey, reportSpan.tag("rabbit.queue"));
assertEquals(uri, reportSpan.tag("rabbit.broker"));
assertEquals("rabbitmq", reportSpan.remoteServiceName());
assertEquals(Type.RABBITMQ.getRemoteType(), reportSpan.tag(MiddlewareConstants.TYPE_TAG_NAME));
assertNull(reportSpan.tag(MiddlewareConstants.REDIRECTED_LABEL_REMOTE_TAG_NAME));
assertFalse(reportSpan.hasError());
String errorInfo = "testError";
methodInfo = MethodInfo.builder().args(new Object[] { null, envelope, basicProperties }).throwable(new RuntimeException(errorInfo)).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
assertTrue(reportSpan.hasError());
assertEquals(errorInfo, reportSpan.errorInfo());
Span span = context.nextSpan();
span.cacheScope();
methodInfo = MethodInfo.builder().args(new Object[] { null, envelope, basicProperties }).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
assertEquals(span.traceIdString(), reportSpan.traceId());
assertEquals(span.spanIdString(), reportSpan.parentId());
span.finish();
TestUtils.setRedirect();
RedirectProcessor.redirected(Redirect.RABBITMQ, TestUtils.getRedirectUri());
methodInfo = MethodInfo.builder().args(new Object[] { null, envelope, basicProperties }).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
assertEquals(TestUtils.getRedirectUri(), reportSpan.tag(MiddlewareConstants.REDIRECTED_LABEL_REMOTE_TAG_NAME));
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class JdbcStmTracingInterceptorTest method doAfter.
@Test
public void doAfter() throws SQLException {
JdbcStmTracingInterceptor interceptor = new JdbcStmTracingInterceptor();
InterceptorTestUtils.init(interceptor, new JdbcTracingPlugin());
Context context = EaseAgent.getContext();
String method = "test_method";
MethodInfo methodInfo = MethodInfo.builder().method(method).build();
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.get(JdbcStmTracingInterceptor.SPAN_KEY);
assertNotNull(span);
interceptor.doAfter(methodInfo, context);
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, reportSpan);
assertFalse(reportSpan.hasError());
String error = "test error";
methodInfo = MethodInfo.builder().method(method).throwable(new RuntimeException(error)).build();
interceptor.doBefore(methodInfo, context);
span = context.get(JdbcStmTracingInterceptor.SPAN_KEY);
assertNotNull(span);
interceptor.doAfter(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, reportSpan);
assertTrue(reportSpan.hasError());
assertEquals(error, reportSpan.errorInfo());
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaConsumerTracingInterceptorTest method afterPoll.
@Test
public void afterPoll() {
KafkaConsumerTracingInterceptor interceptor = new KafkaConsumerTracingInterceptor();
MockKafkaConsumer kafkaConsumer = MockKafkaConsumer.buildOne();
String topic = "testTopic1";
String uri = (String) kafkaConsumer.getEaseAgent$$DynamicField$$Data();
ConsumerRecords<String, String> consumerRecords = new ConsumerRecords<>(Collections.singletonMap(new TopicPartition(topic, 1), Collections.singletonList(record(topic, 0))));
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
checkBaseInfo(Objects.requireNonNull(MockEaseAgent.getLastSpan()), topic, uri);
List<ReportSpan> mockSpans = new ArrayList<>();
MockEaseAgent.setMockSpanReport(mockSpans::add);
consumerRecords = new ConsumerRecords<>(Collections.singletonMap(new TopicPartition(topic, 1), tenRecords(topic)));
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(1, mockSpans.size());
checkBaseInfo(mockSpans.get(0), topic, uri);
mockSpans.clear();
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(10, mockSpans.size());
for (ReportSpan mockSpan : mockSpans) {
checkBaseInfo(mockSpan, topic, uri);
}
mockSpans.clear();
MockEaseAgent.setMockSpanReport(mockSpans::add);
consumerRecords = new ConsumerRecords<>(Collections.singletonMap(new TopicPartition(topic, 1), tenRecords(topic)));
interceptor.singleRootSpanOnReceiveBatch = false;
interceptor.afterPoll(EaseAgent.getContext(), consumerRecords, uri);
assertEquals(10, mockSpans.size());
for (ReportSpan mockSpan : mockSpans) {
checkBaseInfo(mockSpan, topic, uri);
}
mockSpans.clear();
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaConsumerTracingInterceptorTest method checkTowTopicMockSpans.
private void checkTowTopicMockSpans(List<ReportSpan> mockSpans, String uri) {
Set<String> topics = new HashSet<>();
for (ReportSpan mockSpan : mockSpans) {
topics.add(mockSpan.tag(KafkaTags.KAFKA_TOPIC_TAG));
}
assertTrue(topics.contains(topic1));
assertTrue(topics.contains(topic2));
for (ReportSpan mockSpan : mockSpans) {
String topic = mockSpan.tag(KafkaTags.KAFKA_TOPIC_TAG);
checkBaseInfo(mockSpan, topic, uri);
}
}
Aggregations