Search in sources :

Example 6 with Context

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

the class RabbitMqChannelConsumerDeliveryInterceptorTest method before.

@Test
public void before() {
    RabbitMqChannelConsumerDeliveryInterceptor interceptor = new RabbitMqChannelConsumerDeliveryInterceptor();
    AMQP.BasicProperties properties = new AMQP.BasicProperties();
    MockConsumer mockConsumer = new MockConsumer(null);
    String data = "192.168.0.13:2222";
    mockConsumer.setEaseAgent$$DynamicField$$Data(data);
    MethodInfo methodInfo = MethodInfo.builder().invoker(mockConsumer).args(new Object[] { null, null, properties }).build();
    Context context = EaseAgent.getContext();
    interceptor.before(methodInfo, context);
    assertEquals(data, context.get(ContextCons.MQ_URI));
    assertEquals(data, properties.getHeaders().get(ContextCons.MQ_URI));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) AMQP(com.rabbitmq.client.AMQP) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 7 with Context

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

the class OkHttpForwardedInterceptorTest method before.

@Test
public void before() {
    OkHttpForwardedInterceptor okHttpForwardedInterceptor = new OkHttpForwardedInterceptor();
    Request request = new Request.Builder().url("http://127.0.0.1:8080/test").build();
    OkHttpClient client = new OkHttpClient();
    Call call = client.newCall(request);
    MethodInfo methodInfo = MethodInfo.builder().invoker(call).build();
    Context context = EaseAgent.getContext();
    okHttpForwardedInterceptor.before(methodInfo, context);
    assertNull(call.request().header(TestConst.FORWARDED_NAME));
    context.put(TestConst.FORWARDED_NAME, TestConst.FORWARDED_VALUE);
    try {
        okHttpForwardedInterceptor.before(methodInfo, context);
        assertNotNull(call.request().header(TestConst.FORWARDED_NAME));
        assertEquals(TestConst.FORWARDED_VALUE, call.request().header(TestConst.FORWARDED_NAME));
    } finally {
        context.remove(TestConst.FORWARDED_NAME);
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 8 with Context

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

the class OkHttpTracingInterceptorTest method doBefore.

@Test
public void doBefore() {
    Call call = OkHttpTestUtils.buildCall();
    MethodInfo.MethodInfoBuilder methodInfoBuilder = MethodInfo.builder().invoker(call);
    MethodInfo methodInfo = methodInfoBuilder.build();
    Context context = EaseAgent.getContext();
    OkHttpTracingInterceptor okHttpTracingInterceptor = new OkHttpTracingInterceptor();
    MockEaseAgent.cleanLastSpan();
    okHttpTracingInterceptor.before(methodInfo, context);
    methodInfo = methodInfoBuilder.retValue(OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build()).build();
    okHttpTracingInterceptor.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());
    call = OkHttpTestUtils.buildCall();
    methodInfo = methodInfoBuilder.invoker(call).retValue(null).build();
    okHttpTracingInterceptor.before(methodInfo, context);
    methodInfo.retValue(OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build());
    RuntimeException runtimeException = new RuntimeException("test error");
    methodInfo.throwable(runtimeException);
    okHttpTracingInterceptor.after(methodInfo, context);
    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());
    call = OkHttpTestUtils.buildCall();
    methodInfo = methodInfoBuilder.invoker(call).retValue(null).build();
    Span span = context.nextSpan();
    try (Scope ignored = span.maybeScope()) {
        okHttpTracingInterceptor.before(methodInfo, context);
        methodInfo.retValue(OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build());
        okHttpTracingInterceptor.after(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) Call(okhttp3.Call) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Scope(com.megaease.easeagent.plugin.api.trace.Scope) 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 9 with Context

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

the class MongoReactiveTraceCommandListener method commandSucceeded.

@Override
public void commandSucceeded(CommandSucceededEvent event) {
    // LOGGER.warn("reactive commandSucceeded trace");
    Context context = EaseAgent.getContext();
    context.put(MongoUtils.EVENT_KEY, event);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context)

Example 10 with Context

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

the class MongoTraceCommandListener method commandFailed.

@Override
public void commandFailed(CommandFailedEvent event) {
    // LOGGER.warn("commandFailed trace");
    Context context = EaseAgent.getContext();
    TraceHelper.commandFailed(context, event);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context)

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