Search in sources :

Example 6 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class TraceCallbackTest method onCompletion.

@Test
public void onCompletion() throws InterruptedException {
    Context context = EaseAgent.getContext();
    Span span = context.nextSpan().start();
    TraceCallback traceCallback = new TraceCallback(span, null);
    traceCallback.onCompletion(null, null);
    ReportSpan mockSpan = MockEaseAgent.getLastSpan();
    SpanTestUtils.sameId(span, mockSpan);
    assertFalse(mockSpan.hasError());
    span = context.nextSpan().start();
    String errorInfo = "test error";
    traceCallback = new TraceCallback(span, null);
    traceCallback.onCompletion(null, new RuntimeException(errorInfo));
    mockSpan = MockEaseAgent.getLastSpan();
    SpanTestUtils.sameId(span, mockSpan);
    assertTrue(mockSpan.hasError());
    assertEquals(errorInfo, mockSpan.errorInfo());
    AtomicBoolean ran = new AtomicBoolean(false);
    span = context.nextSpan().start();
    final TraceCallback traceCallbackAsync = new TraceCallback(span, (metadata, exception) -> {
        assertTrue(EaseAgent.getContext().currentTracing().hasCurrentSpan());
        ran.set(true);
    });
    Thread thread = new Thread(() -> traceCallbackAsync.onCompletion(null, null));
    thread.start();
    thread.join();
    mockSpan = MockEaseAgent.getLastSpan();
    SpanTestUtils.sameId(span, mockSpan);
    assertFalse(mockSpan.hasError());
    assertTrue(ran.get());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 7 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class HttpClient5AsyncTracingInterceptorTest method doBefore.

@Test
public void doBefore() throws InterruptedException {
    BasicHttpResponse basicHttpResponse = new BasicHttpResponse(200);
    basicHttpResponse.setHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE);
    ReportSpan mockSpan = runOne(httpResponseFutureCallback -> {
        httpResponseFutureCallback.completed(basicHttpResponse);
    });
    assertNotNull(mockSpan);
    assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
    assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
    assertNull(mockSpan.parentId());
    Context context = EaseAgent.getContext();
    Span span = context.nextSpan();
    try (Scope scope = span.maybeScope()) {
        mockSpan = runOne(httpResponseFutureCallback -> {
            httpResponseFutureCallback.completed(basicHttpResponse);
        });
        assertNotNull(mockSpan);
        assertEquals(span.traceIdString(), mockSpan.traceId());
        assertEquals(span.spanIdString(), mockSpan.parentId());
        assertNotNull(mockSpan.id());
    }
    mockSpan = runOne(httpResponseFutureCallback -> {
        httpResponseFutureCallback.failed(new RuntimeException("test error"));
    });
    assertNull(mockSpan);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Context(com.megaease.easeagent.plugin.api.Context) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Span(com.megaease.easeagent.plugin.api.trace.Span) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) AtomicReference(java.util.concurrent.atomic.AtomicReference) MockEaseAgent(com.megaease.easeagent.mock.plugin.api.MockEaseAgent) Scope(com.megaease.easeagent.plugin.api.trace.Scope) EaseAgent(com.megaease.easeagent.plugin.bridge.EaseAgent) Consumer(java.util.function.Consumer) SimpleRequestProducer(org.apache.hc.client5.http.async.methods.SimpleRequestProducer) FutureCallback(org.apache.hc.core5.concurrent.FutureCallback) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) SimpleHttpRequest(org.apache.hc.client5.http.async.methods.SimpleHttpRequest) HttpResponse(org.apache.hc.core5.http.HttpResponse) EaseAgentJunit4ClassRunner(com.megaease.easeagent.mock.plugin.api.junit.EaseAgentJunit4ClassRunner) Assert(org.junit.Assert) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) Scope(com.megaease.easeagent.plugin.api.trace.Scope) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 8 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class RabbitMqOnMessageTracingInterceptorTest method after4Single.

@Test
public void after4Single() {
    RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
    Context context = EaseAgent.getContext();
    Message message = buildMessage(context);
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { message }).build();
    interceptor.before4Single(methodInfo, context);
    interceptor.after4Single(methodInfo, context);
    ReportSpan reportSpan = MockEaseAgent.getLastSpan();
    assertNotNull(reportSpan);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Message(org.springframework.amqp.core.Message) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 9 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class RabbitMqOnMessageTracingInterceptorTest method processMessageAfter.

@Test
public void processMessageAfter() {
    RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
    Context context = EaseAgent.getContext();
    Message message = buildMessage(context);
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { message }).build();
    interceptor.before4Single(methodInfo, context);
    Span span = context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0);
    interceptor.processMessageAfter(methodInfo, context, 0);
    ReportSpan reportSpan = MockEaseAgent.getLastSpan();
    assertNotNull(reportSpan);
    SpanTestUtils.sameId(span, reportSpan);
    String errorInfo = "test error";
    methodInfo = MethodInfo.builder().args(new Object[] { message }).throwable(new RuntimeException(errorInfo)).build();
    interceptor.before4Single(methodInfo, context);
    span = context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0);
    interceptor.processMessageAfter(methodInfo, context, 0);
    reportSpan = MockEaseAgent.getLastSpan();
    assertNotNull(reportSpan);
    SpanTestUtils.sameId(span, reportSpan);
    assertTrue(reportSpan.hasError());
    assertEquals(errorInfo, reportSpan.errorInfo());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Message(org.springframework.amqp.core.Message) 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 10 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class CommonRedisTracingInterceptorTest method startTracing.

@Test
public void startTracing() {
    CommonRedisTracingInterceptor commonRedisTracingInterceptor = new MockCommonRedisTracingInterceptor();
    Context context = EaseAgent.getContext();
    commonRedisTracingInterceptor.startTracing(context, name, null, null);
    Span span = context.get(SPAN_KEY);
    span.finish();
    checkMockSpanInfo(Objects.requireNonNull(MockEaseAgent.getLastSpan()));
    String cmd = "testCmd";
    commonRedisTracingInterceptor.startTracing(context, name, null, cmd);
    span = context.get(SPAN_KEY);
    span.finish();
    ReportSpan mockSpan = Objects.requireNonNull(MockEaseAgent.getLastSpan());
    checkMockSpanInfo(mockSpan);
    assertEquals(cmd, mockSpan.tag("redis.method"));
    Span pSpan = context.nextSpan().start();
    ReportSpan child;
    try (Scope ignored = pSpan.maybeScope()) {
        commonRedisTracingInterceptor.startTracing(context, name, null, null);
        span = context.get(SPAN_KEY);
        span.finish();
        child = Objects.requireNonNull(MockEaseAgent.getLastSpan());
    } finally {
        pSpan.finish();
    }
    ReportSpan parent = Objects.requireNonNull(MockEaseAgent.getLastSpan());
    assertEquals(parent.traceId(), child.traceId());
    assertEquals(parent.id(), child.parentId());
    assertNull(parent.parentId());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Scope(com.megaease.easeagent.plugin.api.trace.Scope) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

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