Search in sources :

Example 11 with ReportSpan

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));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 12 with ReportSpan

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));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) AMQP(com.rabbitmq.client.AMQP) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Envelope(com.rabbitmq.client.Envelope) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 13 with ReportSpan

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());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) SqlInfo(com.megaease.easeagent.plugin.jdbc.common.SqlInfo) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) JdbcTracingPlugin(com.megaease.easeagent.plugin.jdbc.JdbcTracingPlugin) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 14 with ReportSpan

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();
}
Also used : ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) TopicPartition(org.apache.kafka.common.TopicPartition) MockKafkaConsumer(com.megaease.easeagent.plugin.kafka.interceptor.MockKafkaConsumer) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) Test(org.junit.Test)

Example 15 with ReportSpan

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);
    }
}
Also used : ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan)

Aggregations

ReportSpan (com.megaease.easeagent.plugin.report.tracing.ReportSpan)54 Test (org.junit.Test)46 Context (com.megaease.easeagent.plugin.api.Context)38 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)36 Span (com.megaease.easeagent.plugin.api.trace.Span)28 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)10 Scope (com.megaease.easeagent.plugin.api.trace.Scope)9 Message (org.springframework.amqp.core.Message)6 URI (java.net.URI)5 MockEaseAgent (com.megaease.easeagent.mock.plugin.api.MockEaseAgent)4 EaseAgentJunit4ClassRunner (com.megaease.easeagent.mock.plugin.api.junit.EaseAgentJunit4ClassRunner)4 EaseAgent (com.megaease.easeagent.plugin.bridge.EaseAgent)4 MockKafkaConsumer (com.megaease.easeagent.plugin.kafka.interceptor.MockKafkaConsumer)4 ArrayList (java.util.ArrayList)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Assert (org.junit.Assert)4 RunWith (org.junit.runner.RunWith)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)3