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());
}
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);
}
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);
}
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());
}
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());
}
Aggregations