Search in sources :

Example 1 with MessageProduceParameters

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

the class KafkaProducer_Instrumentation method doSend.

@Trace
private Future<RecordMetadata> doSend(ProducerRecord record, Callback callback) {
    if (callback != null) {
        // Wrap the callback so we can capture metrics about messages being produced
        callback = new CallbackWrapper(callback, record.topic());
    }
    if (AgentBridge.getAgent().getTransaction(false) != null) {
        // use null for headers so we don't try to do CAT
        MessageProduceParameters params = MessageProduceParameters.library("Kafka").destinationType(DestinationType.NAMED_TOPIC).destinationName(record.topic()).outboundHeaders(null).build();
        NewRelic.getAgent().getTransaction().getTracedMethod().reportAsExternal(params);
    }
    try {
        return Weaver.callOriginal();
    } catch (Exception e) {
        Map<String, Object> atts = new HashMap<>();
        atts.put("topic_name", record.topic());
        NewRelic.noticeError(e, atts);
        throw e;
    }
}
Also used : MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) CallbackWrapper(com.nr.instrumentation.kafka.CallbackWrapper) HashMap(java.util.HashMap) Map(java.util.Map) Trace(com.newrelic.api.agent.Trace)

Example 2 with MessageProduceParameters

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

the class AmazonSNSAsync_Instrumentation method startSegment.

private Segment startSegment(PublishRequest publishRequest, Transaction transaction) {
    final Segment segment = transaction.startSegment("SNS");
    MessageProduceParameters params = SNSInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    segment.reportAsExternal(params);
    return segment;
}
Also used : MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) Segment(com.newrelic.api.agent.Segment)

Example 3 with MessageProduceParameters

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

the class SNSInstrumentationHelperTest method testPhoneNumberBasedMessage.

@Test
public void testPhoneNumberBasedMessage() throws Exception {
    PublishRequest publishRequest = new PublishRequest(null, "message", "VERY IMPORTANT");
    publishRequest.setPhoneNumber("8675309er");
    MessageProduceParameters result = SNSInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    assertEquals("SNS", result.getLibrary());
    assertEquals("PhoneNumber", result.getDestinationName());
    assertEquals(DestinationType.NAMED_TOPIC, result.getDestinationType());
}
Also used : MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) PublishRequest(com.amazonaws.services.sns.model.PublishRequest) Test(org.junit.Test)

Example 4 with MessageProduceParameters

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

the class SNSInstrumentationHelperTest method testTopicArnBasedMessage.

@Test
public void testTopicArnBasedMessage() throws Exception {
    PublishRequest publishRequest = new PublishRequest("userSpecifiedTopicArn", "message", "VERY IMPORTANT");
    MessageProduceParameters result = SNSInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    assertEquals("SNS", result.getLibrary());
    assertEquals("userSpecifiedTopicArn", result.getDestinationName());
    assertEquals(DestinationType.NAMED_TOPIC, result.getDestinationType());
}
Also used : MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) PublishRequest(com.amazonaws.services.sns.model.PublishRequest) Test(org.junit.Test)

Example 5 with MessageProduceParameters

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

the class SnsClientInstrumentationHelperTest method testPhoneNumberBasedMessage.

@Test
public void testPhoneNumberBasedMessage() throws Exception {
    PublishRequest publishRequest = PublishRequest.builder().message("message").phoneNumber("8675309er").subject("VERY IMPORTANT").build();
    MessageProduceParameters result = SnsClientInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    assertEquals("SNS", result.getLibrary());
    assertEquals("PhoneNumber", result.getDestinationName());
    assertEquals(DestinationType.NAMED_TOPIC, result.getDestinationType());
}
Also used : MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest) Test(org.junit.Test)

Aggregations

MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)17 Test (org.junit.Test)8 Trace (com.newrelic.api.agent.Trace)5 PublishRequest (com.amazonaws.services.sns.model.PublishRequest)3 PublishRequest (software.amazon.awssdk.services.sns.model.PublishRequest)3 Segment (com.newrelic.api.agent.Segment)2 HttpParameters (com.newrelic.api.agent.HttpParameters)1 InboundHeaders (com.newrelic.api.agent.InboundHeaders)1 MessageConsumeParameters (com.newrelic.api.agent.MessageConsumeParameters)1 Transaction (com.newrelic.api.agent.Transaction)1 CallbackWrapper (com.nr.instrumentation.kafka.CallbackWrapper)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1