use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class HttpClient5DoExecuteInterceptorTest method before.
@Test
public void before() {
Context context = EaseAgent.getContext();
HttpGet httpGet = new HttpGet("http://127.0.0.1:8080");
BasicHttpResponse basicHttpResponse = new BasicHttpResponse(200);
basicHttpResponse.setHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
HttpClient5DoExecuteInterceptor httpClient5DoExecuteInterceptor = new HttpClient5DoExecuteInterceptor();
MockEaseAgent.cleanLastSpan();
httpClient5DoExecuteInterceptor.before(methodInfo, context);
httpClient5DoExecuteInterceptor.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()) {
httpClient5DoExecuteInterceptor.doBefore(methodInfo, context);
httpClient5DoExecuteInterceptor.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.api.Context in project easeagent by megaease.
the class HttpClient5DoExecuteInterceptorTest method getRequest.
@Test
public void getRequest() {
Context context = EaseAgent.getContext();
HttpGet httpGet = new HttpGet("http://127.0.0.1:8080");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).build();
HttpClient5DoExecuteInterceptor httpClient5DoExecuteInterceptor = new HttpClient5DoExecuteInterceptor();
HttpRequest request = httpClient5DoExecuteInterceptor.getRequest(methodInfo, context);
assertEquals(Span.Kind.CLIENT, request.kind());
assertEquals("GET", request.method());
}
use of com.megaease.easeagent.plugin.api.Context 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.api.Context 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.api.Context in project easeagent by megaease.
the class AsyncResponse4TraceListener method process.
private void process(Response response, Exception exception) {
try (Cleaner ignored = asyncContext.importToCurrent()) {
Context context = EaseAgent.getContext();
ElasticsearchCtxUtils.finishSpan(response, exception, context);
}
}
Aggregations