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));
}
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);
}
}
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());
}
}
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);
}
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);
}
Aggregations