Search in sources :

Example 96 with Context

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());
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) Scope(com.megaease.easeagent.plugin.api.trace.Scope) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) 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 97 with Context

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());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 98 with Context

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());
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) Scope(com.megaease.easeagent.plugin.api.trace.Scope) HttpGet(org.apache.http.client.methods.HttpGet) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) ProtocolVersion(org.apache.http.ProtocolVersion) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 99 with Context

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

Example 100 with Context

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);
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) AsyncContext(com.megaease.easeagent.plugin.api.context.AsyncContext) Cleaner(com.megaease.easeagent.plugin.api.Cleaner)

Aggregations

Context (com.megaease.easeagent.plugin.api.Context)122 Test (org.junit.Test)101 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)87 ReportSpan (com.megaease.easeagent.plugin.report.tracing.ReportSpan)39 Span (com.megaease.easeagent.plugin.api.trace.Span)32 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)13 Scope (com.megaease.easeagent.plugin.api.trace.Scope)13 Message (org.springframework.amqp.core.Message)10 URI (java.net.URI)9 LastJsonReporter (com.megaease.easeagent.mock.report.impl.LastJsonReporter)8 TagVerifier (com.megaease.easeagent.mock.plugin.api.utils.TagVerifier)7 BsonDocument (org.bson.BsonDocument)7 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)7 HttpRequest (com.megaease.easeagent.plugin.tools.trace.HttpRequest)6 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)6 ArrayList (java.util.ArrayList)6 BsonString (org.bson.BsonString)6 Call (okhttp3.Call)5 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)4 MockClientRequest (org.springframework.web.reactive.function.client.MockClientRequest)4