Search in sources :

Example 6 with MessageConsumeParameters

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

the class Util method generateExternalConsumeMetrics.

public static MessageConsumeParameters generateExternalConsumeMetrics(String queueUrl) {
    String queueName = UNKOWN;
    int index = queueUrl.lastIndexOf('/');
    if (index > 0) {
        queueName = queueUrl.substring(index + 1);
    }
    MessageConsumeParameters params = MessageConsumeParameters.library(LIBRARY).destinationType(DestinationType.NAMED_QUEUE).destinationName(queueName).inboundHeaders(null).build();
    return params;
}
Also used : MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters)

Example 7 with MessageConsumeParameters

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

the class AmazonSQS_Instrumentation method receiveMessage.

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

Example 8 with MessageConsumeParameters

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

the class KafkaConsumer_Instrumentation method poll.

private ConsumerRecords<K, V> poll(final Timer timer, final boolean includeMetadataInTimeout) {
    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 9 with MessageConsumeParameters

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

the class DefaultTracer method reportAsExternal.

@Override
public void reportAsExternal(ExternalParameters externalParameters) {
    if (Agent.LOG.isFineEnabled()) {
        Agent.LOG.log(Level.FINE, "Setting externalParameters to: " + externalParameters);
    }
    MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_REPORT_AS_EXTERNAL);
    this.externalParameters = externalParameters;
    if (this.externalParameters instanceof HttpParameters) {
        // URI validity check and logging
        HttpParameters httpParameters = (HttpParameters) this.externalParameters;
        URI uri = httpParameters.getUri();
        if (uri == null || uri.getScheme() == null || uri.getHost() == null || uri.getPort() == -1) {
            Agent.LOG.log(Level.FINE, "URI parameter passed to HttpParameters should include a valid scheme, host, and port.");
        }
        InboundHeaders headers = httpParameters.getInboundResponseHeaders();
        if (null != headers) {
            readInboundResponseHeaders(headers);
        }
    } else if (this.externalParameters instanceof MessageProduceParameters) {
        catForMessaging(((MessageProduceParameters) this.externalParameters));
    } else if (this.externalParameters instanceof MessageConsumeParameters) {
        catForMessaging(((MessageConsumeParameters) this.externalParameters));
    }
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) InboundHeaders(com.newrelic.api.agent.InboundHeaders) MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) URI(java.net.URI)

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