use of com.megaease.easeagent.plugin.interceptor.MethodInfo in project easeagent by megaease.
the class CommonInlineAdvice method enter.
@Advice.OnMethodEnter(suppress = NoExceptionHandler.class)
public static MethodInfo enter(@Index int index, @Advice.This(optional = true) Object invoker, @Advice.Origin("#t") String type, @Advice.Origin("#m") String method, @Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] args, @Advice.Local(CONTEXT) InitializeContext context) {
context = EaseAgent.initializeContextSupplier.get();
if (context.isNoop()) {
return null;
}
MethodInfo methodInfo = MethodInfo.builder().invoker(invoker).type(type).method(method).args(args).build();
Dispatcher.enter(index, methodInfo, context);
if (methodInfo.isChanged()) {
args = methodInfo.getArgs();
}
return methodInfo;
}
use of com.megaease.easeagent.plugin.interceptor.MethodInfo in project easeagent by megaease.
the class MongoReactiveMetricTest method performSuccess.
@Test
public void performSuccess() {
Context context = EaseAgent.getContext();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { null, null, null, mock(SingleResultCallback.class) }).build();
interceptor.before(methodInfo, context);
BsonDocument bsonDocument = new BsonDocument();
bsonDocument.put("collection", new BsonString(collection));
CommandSucceededEvent succeededEvent = new CommandSucceededEvent(this.requestId, this.connectionDescription, this.cmdName, bsonDocument, 10);
this.listener.commandStarted(startedEvent);
this.listener.commandSucceeded(succeededEvent);
MongoInternalConnectionSendAndReceiveAsync4MetricInterceptor.SingleResultCallbackProxy<?> proxy = (MongoInternalConnectionSendAndReceiveAsync4MetricInterceptor.SingleResultCallbackProxy<?>) methodInfo.getArgs()[3];
proxy.onResult(null, null);
this.assertMetric(initMetricInterceptor.getMongoMetric().getNameFactory(), initMetricInterceptor.getMongoMetric().getMetricRegistry(), true);
context.exit(interceptor.getEnterKey(methodInfo, context));
}
use of com.megaease.easeagent.plugin.interceptor.MethodInfo in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method testRedirectedTag.
@Test
public void testRedirectedTag() {
KafkaAbstractConfigConstructInterceptor kafkaAbstractConfigConstructInterceptor = new KafkaAbstractConfigConstructInterceptor();
KafkaTestUtils.mockRedirect(() -> {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { props }).build();
kafkaAbstractConfigConstructInterceptor.doBefore(methodInfo, EaseAgent.getContext());
MockKafkaProducer kafkaProducer = new MockKafkaProducer(props);
kafkaProducer.setEaseAgent$$DynamicField$$Data(props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
Context context = EaseAgent.getContext();
ProducerRecord record = new ProducerRecord<>(topic, key, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertEquals(TestConst.REDIRECT_URIS, mockSpan.tag("label.remote"));
});
}
use of com.megaease.easeagent.plugin.interceptor.MethodInfo in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method doBefore.
@Test
public void doBefore() {
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
MockKafkaProducer kafkaProducer = MockKafkaProducer.buildOne();
Context context = EaseAgent.getContext();
ProducerRecord record = new ProducerRecord<>(topic, key, value);
MethodInfo methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
Span span = finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
checkBaseInfo(mockSpan);
assertEquals(key, mockSpan.tag(KafkaTags.KAFKA_KEY_TAG));
record = new ProducerRecord<>(topic, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
context = EaseAgent.getContext();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
span = finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
checkBaseInfo(mockSpan);
assertNull(mockSpan.tag(KafkaTags.KAFKA_KEY_TAG));
record = new ProducerRecord<>(topic, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
context = EaseAgent.getContext();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
assertNotNull(methodInfo.getArgs()[1]);
assertTrue(methodInfo.getArgs()[1] instanceof TraceCallback);
}
use of com.megaease.easeagent.plugin.interceptor.MethodInfo 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));
}
Aggregations