use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class HttpClientDoExecuteInterceptorTest method before.
@Test
public void before() {
Context context = EaseAgent.getContext();
HttpGet httpGet = new HttpGet("http://127.0.0.1:8080");
ProtocolVersion protocolVersion = new ProtocolVersion("testProtocol", 10, 1);
BasicHttpResponse basicHttpResponse = new BasicHttpResponse(protocolVersion, 200, "");
basicHttpResponse.setHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
HttpClientDoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClientDoExecuteInterceptor();
MockEaseAgent.cleanLastSpan();
httpClientDoExecuteInterceptor.before(methodInfo, context);
httpClientDoExecuteInterceptor.after(methodInfo, context);
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
assertNull(mockSpan.parentId());
Span span = context.nextSpan();
try (Scope ignored = span.maybeScope()) {
httpClientDoExecuteInterceptor.doBefore(methodInfo, context);
httpClientDoExecuteInterceptor.doAfter(methodInfo, context);
mockSpan = MockEaseAgent.getLastSpan();
assertEquals(span.traceIdString(), mockSpan.traceId());
assertEquals(span.spanIdString(), mockSpan.parentId());
assertNotNull(mockSpan.id());
}
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class RunnableInterceptorTest method before.
@Test
public void before() throws InterruptedException {
Context context = EaseAgent.getContext();
final Span span = context.nextSpan();
span.start();
span.cacheScope();
RunnableInterceptor runnableInterceptor = new RunnableInterceptor();
AtomicInteger run = new AtomicInteger();
Runnable runnable = () -> {
Context runCont = EaseAgent.getContext();
assertTrue(runCont.currentTracing().hasCurrentSpan());
Span span1 = runCont.nextSpan();
assertEquals(span.traceId(), span1.traceId());
assertEquals(span.spanId(), span1.parentId());
assertNotEquals(span.spanId(), span1.spanId());
run.incrementAndGet();
};
MethodInfo methodInfo = MethodInfo.builder().invoker("").type("").method("").args(new Object[] { runnable }).build();
runnableInterceptor.before(methodInfo, context);
Thread thread = new Thread((Runnable) methodInfo.getArgs()[0]);
thread.start();
thread.join();
assertEquals(run.get(), 1);
span.finish();
ReportSpan span1 = MockEaseAgent.getLastSpan();
assertEquals(span.traceIdString(), span1.traceId());
assertEquals(span.parentIdString(), span1.parentId());
assertEquals(span.spanIdString(), span1.id());
System.out.println("run count: " + run.get());
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class ElasticsearchBaseTest method assertTrace.
protected void assertTrace(boolean success, String error) {
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals("index-1", mockSpan.tag("es.index"));
assertEquals("GET /index-1/_search", mockSpan.tag("es.operation"));
assertEquals(body, mockSpan.tag("es.body"));
if (success) {
assertNull(mockSpan.tag("error"));
}
if (!success) {
assertNotNull(mockSpan.tag("error"));
assertEquals(error, mockSpan.tag("error"));
}
assertNull(mockSpan.parentId());
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method doAfter.
@Test
public void doAfter() {
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
Context context = EaseAgent.getContext();
MockKafkaProducer kafkaProducer = MockKafkaProducer.buildOne();
interceptor.doAfter(null, context);
ProducerRecord record = new ProducerRecord<>(topic, key, value);
MethodInfo methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
interceptor.doAfter(methodInfo, context);
assertFalse(context.currentTracing().hasCurrentSpan());
Callback callback = (Callback) methodInfo.getArgs()[1];
callback.onCompletion(null, null);
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertFalse(mockSpan.tags().containsKey("error"));
record = new ProducerRecord<>(topic, key, value);
String errorInfo = "test error";
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).throwable(new RuntimeException(errorInfo)).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
interceptor.doAfter(methodInfo, context);
assertFalse(context.currentTracing().hasCurrentSpan());
callback = (Callback) methodInfo.getArgs()[1];
callback.onCompletion(null, null);
mockSpan = MockEaseAgent.getLastSpan();
assertTrue(mockSpan.tags().containsKey("error"));
assertEquals(errorInfo, mockSpan.tags().get("error"));
}
Aggregations