Search in sources :

Example 1 with MessageConsumeParameters

use of com.newrelic.api.agent.MessageConsumeParameters in project newrelic-java-agent by newrelic.

the class KafkaConsumer_Instrumentation method poll.

public ConsumerRecords<K, V> poll(Duration timeout) {
    final ConsumerRecords<K, V> records;
    try {
        records = Weaver.callOriginal();
    } catch (Exception e) {
        // Specifically ignore WakeupExceptions because they are common in non-error use cases
        if (!(e instanceof WakeupException)) {
            NewRelic.noticeError(e);
        }
        throw e;
    }
    for (ConsumerRecord record : records) {
        if (AgentBridge.getAgent().getTransaction(false) != null) {
            MessageConsumeParameters params = MessageConsumeParameters.library("Kafka").destinationType(DestinationType.NAMED_TOPIC).destinationName(record.topic()).inboundHeaders(null).build();
            NewRelic.getAgent().getTransaction().getTracedMethod().reportAsExternal(params);
        }
        break;
    }
    return records;
}
Also used : MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) WakeupException(org.apache.kafka.common.errors.WakeupException) WakeupException(org.apache.kafka.common.errors.WakeupException)

Example 2 with MessageConsumeParameters

use of com.newrelic.api.agent.MessageConsumeParameters in project newrelic-java-agent by newrelic.

the class KafkaConsumer_Instrumentation method poll.

public ConsumerRecords<K, V> poll(long timeout) {
    final ConsumerRecords<K, V> records;
    try {
        records = Weaver.callOriginal();
    } catch (Exception e) {
        // Specifically ignore WakeupExceptions because they are common in non-error use cases
        if (!(e instanceof WakeupException)) {
            NewRelic.noticeError(e);
        }
        throw e;
    }
    for (ConsumerRecord record : records) {
        if (AgentBridge.getAgent().getTransaction(false) != null) {
            MessageConsumeParameters params = MessageConsumeParameters.library("Kafka").destinationType(DestinationType.NAMED_TOPIC).destinationName(record.topic()).inboundHeaders(null).build();
            NewRelic.getAgent().getTransaction().getTracedMethod().reportAsExternal(params);
        }
        break;
    }
    return records;
}
Also used : MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) WakeupException(org.apache.kafka.common.errors.WakeupException) WakeupException(org.apache.kafka.common.errors.WakeupException)

Example 3 with MessageConsumeParameters

use of com.newrelic.api.agent.MessageConsumeParameters in project newrelic-java-agent by newrelic.

the class SqsClient_Instrumentation method receiveMessage.

@Trace
public ReceiveMessageResponse receiveMessage(ReceiveMessageRequest receiveMessageRequest) {
    MessageConsumeParameters messageConsumeParameters = Util.generateExternalConsumeMetrics(receiveMessageRequest.queueUrl());
    NewRelic.getAgent().getTracedMethod().reportAsExternal(messageConsumeParameters);
    return Weaver.callOriginal();
}
Also used : MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) Trace(com.newrelic.api.agent.Trace)

Example 4 with MessageConsumeParameters

use of com.newrelic.api.agent.MessageConsumeParameters in project newrelic-java-agent by newrelic.

the class UtilTest method testGenerateConsumeMetricsGoodQueueName.

@Test
public void testGenerateConsumeMetricsGoodQueueName() {
    MessageConsumeParameters messageConsumeParameters = Util.generateExternalConsumeMetrics("path/myQueue");
    Assert.assertEquals("SQS", messageConsumeParameters.getLibrary());
    Assert.assertEquals("myQueue", messageConsumeParameters.getDestinationName());
    Assert.assertEquals(DestinationType.NAMED_QUEUE, messageConsumeParameters.getDestinationType());
}
Also used : MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) Test(org.junit.Test)

Example 5 with MessageConsumeParameters

use of com.newrelic.api.agent.MessageConsumeParameters in project newrelic-java-agent by newrelic.

the class UtilTest method testGenerateConsumeMetricsBadQueueName.

@Test
public void testGenerateConsumeMetricsBadQueueName() {
    MessageConsumeParameters messageConsumeParameters = Util.generateExternalConsumeMetrics("path");
    Assert.assertEquals("SQS", messageConsumeParameters.getLibrary());
    Assert.assertEquals("unknown", messageConsumeParameters.getDestinationName());
    Assert.assertEquals(DestinationType.NAMED_QUEUE, messageConsumeParameters.getDestinationType());
}
Also used : MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) Test(org.junit.Test)

Aggregations

MessageConsumeParameters (com.newrelic.api.agent.MessageConsumeParameters)9 WakeupException (org.apache.kafka.common.errors.WakeupException)3 Trace (com.newrelic.api.agent.Trace)2 Test (org.junit.Test)2 HttpParameters (com.newrelic.api.agent.HttpParameters)1 InboundHeaders (com.newrelic.api.agent.InboundHeaders)1 MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)1 URI (java.net.URI)1