Search in sources :

Example 26 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class ElasticsearchPerformRequestTraceInterceptorTest method performFail.

@Test
public void performFail() {
    MethodInfo methodInfo = MethodInfo.builder().invoker(this).method("perform").args(new Object[] { request }).retValue(this.failResponse).build();
    Context context = EaseAgent.getContext();
    interceptor.before(methodInfo, context);
    interceptor.after(methodInfo, context);
    this.assertTrace(false, "500");
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 27 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class ElasticsearchPerformRequestTraceInterceptorTest method performSuccess.

@Test
public void performSuccess() {
    MethodInfo methodInfo = MethodInfo.builder().invoker(this).method("perform").args(new Object[] { request }).retValue(this.successResponse).build();
    Context context = EaseAgent.getContext();
    interceptor.before(methodInfo, context);
    interceptor.after(methodInfo, context);
    this.assertTrace(true, null);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 28 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class AsyncResponse4MetricsListener method process.

private void process(Response response, Exception exception) {
    try (Cleaner ignored = asyncContext.importToCurrent()) {
        Context context = EaseAgent.getContext();
        Request request = context.get(REQUEST);
        long duration = ContextUtils.getDuration(context);
        boolean success = ElasticsearchCtxUtils.checkSuccess(response, exception);
        this.elasticsearchMetric.collectMetric(ElasticsearchCtxUtils.getIndex(request.getEndpoint()), duration, success);
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) AsyncContext(com.megaease.easeagent.plugin.api.context.AsyncContext) Request(org.elasticsearch.client.Request) Cleaner(com.megaease.easeagent.plugin.api.Cleaner)

Example 29 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class HttpClient5DoExecuteInterceptorTest method getResponse.

@Test
public void getResponse() {
    Context context = EaseAgent.getContext();
    HttpGet httpGet = new HttpGet("http://127.0.0.1:8080");
    BasicHttpResponse basicHttpResponse = new BasicHttpResponse(200);
    basicHttpResponse.setHeader("aa", "bb");
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
    HttpClient5DoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClient5DoExecuteInterceptor();
    HttpResponse httpResponse = httpClientDoExecuteInterceptor.getResponse(methodInfo, context);
    assertEquals(200, httpResponse.statusCode());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 30 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class HttpClientDoExecuteInterceptorTest method getRequest.

@Test
public void getRequest() {
    Context context = EaseAgent.getContext();
    HttpGet httpGet = new HttpGet();
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).build();
    HttpClientDoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClientDoExecuteInterceptor();
    HttpRequest request = httpClientDoExecuteInterceptor.getRequest(methodInfo, context);
    assertEquals(com.megaease.easeagent.plugin.api.trace.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.http.client.methods.HttpGet) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

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