Search in sources :

Example 1 with CallbackWrapper

use of com.nr.instrumentation.kafka.CallbackWrapper 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)

Aggregations

MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)1 Trace (com.newrelic.api.agent.Trace)1 CallbackWrapper (com.nr.instrumentation.kafka.CallbackWrapper)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1