Search in sources :

Example 1 with MethodInfo

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;
}
Also used : MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo)

Example 2 with 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));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) CommandSucceededEvent(com.mongodb.event.CommandSucceededEvent) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) MongoInternalConnectionSendAndReceiveAsync4MetricInterceptor(com.megaease.easeagent.plugin.mongodb.interceptor.MongoInternalConnectionSendAndReceiveAsync4MetricInterceptor) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 3 with MethodInfo

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"));
    });
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) MockKafkaProducer(com.megaease.easeagent.plugin.kafka.interceptor.MockKafkaProducer) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Properties(java.util.Properties) KafkaAbstractConfigConstructInterceptor(com.megaease.easeagent.plugin.kafka.interceptor.redirect.KafkaAbstractConfigConstructInterceptor) Test(org.junit.Test)

Example 4 with MethodInfo

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);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) MockKafkaProducer(com.megaease.easeagent.plugin.kafka.interceptor.MockKafkaProducer) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) 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 5 with MethodInfo

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

Aggregations

MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)138 Test (org.junit.Test)126 Context (com.megaease.easeagent.plugin.api.Context)85 ReportSpan (com.megaease.easeagent.plugin.report.tracing.ReportSpan)33 Span (com.megaease.easeagent.plugin.api.trace.Span)21 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)16 URI (java.net.URI)14 LastJsonReporter (com.megaease.easeagent.mock.report.impl.LastJsonReporter)10 Scope (com.megaease.easeagent.plugin.api.trace.Scope)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 Message (org.springframework.amqp.core.Message)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)9 HttpRequest (com.megaease.easeagent.plugin.tools.trace.HttpRequest)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 TagVerifier (com.megaease.easeagent.mock.plugin.api.utils.TagVerifier)6 HttpResponse (com.megaease.easeagent.plugin.tools.trace.HttpResponse)6 Request (feign.Request)6 SqlInfo (com.megaease.easeagent.plugin.jdbc.common.SqlInfo)5