Search in sources :

Example 1 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class HystrixTestUtils method verifyTransactionTraceFailure.

public static void verifyTransactionTraceFailure(String command, CallType type, Failure output) {
    final String txName = InstrumentationTestRunner.getIntrospector().getTransactionNames().iterator().next();
    // transaction trace
    Collection<TransactionTrace> traces = InstrumentationTestRunner.getIntrospector().getTransactionTracesForTransaction(txName);
    Assert.assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    TraceSegment segment = trace.getInitialTraceSegment();
    Assert.assertEquals("Java/" + HystrixTestUtils.class.getName() + "/runCommand", segment.getName());
    Assert.assertEquals(1, segment.getCallCount());
    List<TraceSegment> children = segment.getChildren();
    if (type == CallType.TO_OBSERVABLE) {
        if (output == Failure.TIMEOUT) {
            Assert.assertEquals(3, children.size());
        } else {
            Assert.assertEquals(2, children.size());
        }
    } else {
        Assert.assertEquals(1, children.size());
    }
    segment = children.remove(0);
    switch(type) {
        case EXECUTE:
            Assert.assertEquals("Java/" + command + "/execute", segment.getName());
            Assert.assertEquals(1, segment.getCallCount());
            children = segment.getChildren();
            Assert.assertEquals(1, children.size());
            segment = children.get(0);
        // purposely fall through
        case QUEUE:
            Assert.assertEquals("Java/" + command + "/queue", segment.getName());
            Assert.assertEquals(1, segment.getCallCount());
            children = segment.getChildren();
            if (output == Failure.TIMEOUT) {
                Assert.assertEquals(3, children.size());
            } else {
                Assert.assertEquals(2, children.size());
            }
            segment = children.remove(0);
        // purposely fall through
        case TO_OBSERVABLE:
            Assert.assertEquals("Java/" + command + "/toObservable", segment.getName());
            Assert.assertEquals(1, segment.getCallCount());
            if (output == Failure.TIMEOUT) {
                Assert.assertEquals(2, children.size());
                for (TraceSegment seg : children) {
                    if (seg.getName().equals("Java/com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction/call")) {
                        Assert.assertEquals(1, seg.getCallCount());
                        children = seg.getChildren();
                        Assert.assertEquals(1, children.size());
                        seg = children.get(0);
                        Assert.assertEquals("Java/" + command + "/run", seg.getName());
                        Assert.assertEquals(1, seg.getCallCount());
                        children = seg.getChildren();
                        Assert.assertEquals(0, children.size());
                    } else {
                        Assert.assertEquals("Java/" + command + "/getFallback", seg.getName());
                        Assert.assertEquals(1, seg.getCallCount());
                        children = seg.getChildren();
                        Assert.assertEquals(0, children.size());
                    }
                }
            } else {
                Assert.assertEquals(1, children.size());
                segment = children.get(0);
                Assert.assertEquals("Java/com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction/call", segment.getName());
                Assert.assertEquals(1, segment.getCallCount());
                children = segment.getChildren();
                Assert.assertEquals(2, children.size());
                for (TraceSegment seg : children) {
                    if (seg.getName().equals("Java/" + command + "/run")) {
                        Assert.assertEquals(1, seg.getCallCount());
                        children = seg.getChildren();
                        Assert.assertEquals(0, children.size());
                    } else {
                        Assert.assertEquals("Java/" + command + "/getFallback", seg.getName());
                        Assert.assertEquals(1, seg.getCallCount());
                        children = seg.getChildren();
                        Assert.assertEquals(0, children.size());
                    }
                }
            }
    }
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Example 2 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class NingAsyncHttpClient10Tests method testSuccess.

@Test
public void testSuccess() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    String host = endpoint.getHost();
    String url = endpoint.toURL().toExternalForm();
    int status = makeAsyncRequest(url + "?no-transaction=true");
    assertEquals(200, status);
    // transaction
    assertEquals(1, introspector.getFinishedTransactionCount(TIMEOUT));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/AsyncHttpClient/onCompleted"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/AsyncHttpClient/onCompleted"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    // events
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txName);
    assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    assertEquals(1, transactionEvent.getExternalCallCount());
    assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    // traces
    Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(txName);
    assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    for (TraceSegment segment : trace.getInitialTraceSegment().getChildren()) {
        Map<String, Object> attributes = segment.getTracerAttributes();
        Object asyncContext = attributes.get("async_context");
        if (asyncContext != null && asyncContext.equals("External")) {
            assertEquals("", segment.getMethodName());
            assertEquals("External Request", segment.getClassName());
            assertEquals("External/" + host + "/AsyncHttpClient/onCompleted", segment.getName());
            assertEquals(url, segment.getUri());
            assertEquals(1, segment.getCallCount());
        }
    }
    // external request information
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txName);
    assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    assertEquals(1, externalRequest.getCount());
    assertEquals(host, externalRequest.getHostname());
    assertEquals("AsyncHttpClient", externalRequest.getLibrary());
    assertEquals("onCompleted", externalRequest.getOperation());
    assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    assertEquals("OK", externalRequest.getStatusText());
// netty?
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Test(org.junit.Test)

Example 3 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class PlayAsyncHttpClientTests method testSuccess.

@Test
public void testSuccess() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    String host = endpoint.getHost();
    String url = endpoint.toURL().toExternalForm();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger result = new AtomicInteger();
    makeAsyncRequest(url + "?no-transaction=true", standaloneWSResponse -> {
        result.set(standaloneWSResponse.status());
        latch.countDown();
    });
    latch.await(30, TimeUnit.SECONDS);
    assertEquals(200, result.get());
    // transaction
    assertEquals(1, introspector.getFinishedTransactionCount(TimeUnit.SECONDS.toMillis(30)));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/PlayWS/get"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/PlayWS/get"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    // events
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txName);
    assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    assertEquals(1, transactionEvent.getExternalCallCount());
    assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    // traces
    Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(txName);
    assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    for (TraceSegment segment : trace.getInitialTraceSegment().getChildren()) {
        Map<String, Object> attributes = segment.getTracerAttributes();
        if (attributes.get("async_context").equals("segment-api")) {
            assertEquals("", segment.getMethodName());
            assertEquals("PlayWS", segment.getClassName());
            assertEquals("External/" + host + "/PlayWS/get", segment.getName());
            assertEquals(url, segment.getUri());
            assertEquals(1, segment.getCallCount());
        }
    }
    // external request information
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txName);
    assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    assertEquals(1, externalRequest.getCount());
    assertEquals(host, externalRequest.getHostname());
    assertEquals("PlayWS", externalRequest.getLibrary());
    assertEquals("get", externalRequest.getOperation());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Java10IncompatibleTest(com.newrelic.test.marker.Java10IncompatibleTest) Java13IncompatibleTest(com.newrelic.test.marker.Java13IncompatibleTest) Java16IncompatibleTest(com.newrelic.test.marker.Java16IncompatibleTest) Java9IncompatibleTest(com.newrelic.test.marker.Java9IncompatibleTest) Java17IncompatibleTest(com.newrelic.test.marker.Java17IncompatibleTest) Java14IncompatibleTest(com.newrelic.test.marker.Java14IncompatibleTest) Test(org.junit.Test) Java11IncompatibleTest(com.newrelic.test.marker.Java11IncompatibleTest) Java15IncompatibleTest(com.newrelic.test.marker.Java15IncompatibleTest) Java12IncompatibleTest(com.newrelic.test.marker.Java12IncompatibleTest)

Example 4 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class RabbitMQTest_Integration method testCat.

@Test
public void testCat() throws IOException, InterruptedException {
    final String queueName = UUID.randomUUID().toString();
    channel.queueDeclare(queueName, false, false, true, true, Collections.<String, Object>emptyMap());
    final String replyMessage = "reply";
    channel.basicConsume(queueName, new DefaultConsumer(channel) {

        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            channel.basicPublish(DEFAULT_EXCHANGE, properties.getReplyTo(), new AMQP.BasicProperties(), replyMessage.getBytes());
        }
    });
    Thread thread = new Thread(new Runnable() {

        @Override
        @Trace(dispatcher = true)
        public void run() {
            NewRelic.setTransactionName("Category", "Sender");
            try {
                String tempQueue = channel.queueDeclare().getQueue();
                AMQP.BasicProperties properties = new AMQP.BasicProperties();
                properties.setReplyTo(tempQueue);
                channel.basicPublish(DEFAULT_EXCHANGE, queueName, properties, "message".getBytes());
                QueueingConsumer queueingConsumer = new QueueingConsumer(channel);
                channel.basicConsume(tempQueue, true, queueingConsumer);
                // block
                QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery();
                assertEquals(replyMessage, new String(delivery.getBody()));
            } catch (IOException e) {
            } catch (InterruptedException e) {
            }
        }
    });
    thread.start();
    thread.join(2000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String senderTransactioName = "OtherTransaction/Category/Sender";
    String messageListenerTransactionName = String.format("OtherTransaction/Message/RabbitMQ/Queue/Named/%s", queueName);
    final Collection<String> transactionNames = introspector.getTransactionNames();
    assertTrue(transactionNames.contains(senderTransactioName));
    assertTrue(transactionNames.contains(messageListenerTransactionName));
    Map<String, TracedMetricData> senderMetrics = introspector.getMetricsForTransaction(senderTransactioName);
    Map<String, TracedMetricData> messageListenerMetrics = introspector.getMetricsForTransaction(messageListenerTransactionName);
    assertTrue(senderMetrics.containsKey(String.format("MessageBroker/RabbitMQ/Queue/Produce/Named/%s", queueName)));
    assertTrue(senderMetrics.containsKey("MessageBroker/RabbitMQ/Queue/Consume/Temp"));
    assertTrue(messageListenerMetrics.containsKey(String.format("MessageBroker/RabbitMQ/Queue/Consume/Named/%s", queueName)));
    assertTrue(messageListenerMetrics.containsKey("MessageBroker/RabbitMQ/Queue/Produce/Temp"));
    // Ideally, the block below could be replaced with the following line:
    // CatHelper.verifyOneSuccessfulCat(introspector, senderTransactioName, messageListenerTransactionName);
    {
        TransactionTrace senderTT = introspector.getTransactionTracesForTransaction(senderTransactioName).iterator().next();
        TransactionTrace messageListenerTT = introspector.getTransactionTracesForTransaction(messageListenerTransactionName).iterator().next();
        Map<String, Object> senderTTIntrinsics = senderTT.getIntrinsicAttributes();
        Map<String, Object> messageListenerTTIntrinsics = messageListenerTT.getIntrinsicAttributes();
        assertNotNull(senderTTIntrinsics.get("trip_id"));
        assertNotNull(senderTTIntrinsics.get("path_hash"));
        assertNotNull(getAttribute(senderTT, "transaction_guid"));
        assertNotNull(messageListenerTTIntrinsics.get("referring_transaction_guid"));
        assertNotNull(messageListenerTTIntrinsics.get("client_cross_process_id"));
        TransactionEvent senderEvent = introspector.getTransactionEvents(senderTransactioName).iterator().next();
        TransactionEvent messageListenerEvent = introspector.getTransactionEvents(messageListenerTransactionName).iterator().next();
        assertEquals(senderEvent.getMyGuid(), messageListenerEvent.getReferrerGuid());
    }
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Introspector(com.newrelic.agent.introspec.Introspector) IOException(java.io.IOException) Envelope(com.rabbitmq.client.Envelope) Trace(com.newrelic.api.agent.Trace) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) AMQP(com.rabbitmq.client.AMQP) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Map(java.util.Map) Test(org.junit.Test)

Example 5 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class TransactionTraceTest method testOneTracerInTransactionWithDepthChildren.

@Test
public void testOneTracerInTransactionWithDepthChildren() {
    // transaction
    long start = System.currentTimeMillis();
    Transaction.getTransaction();
    Tracer rootTracer = IntrospectorImplTest.createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Tracer child1 = IntrospectorImplTest.createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    Tracer child2 = IntrospectorImplTest.createDefaultTracer("default2");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
    Tracer child3 = IntrospectorImplTest.createDefaultTracer("default3");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child3);
    child3.setAgentAttribute("myatt", "hello");
    child3.setAgentAttribute("myNumber", 99);
    child3.finish(Opcodes.RETURN, 0);
    child2.finish(Opcodes.RETURN, 0);
    child1.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    long end = System.currentTimeMillis();
    // data check
    Assert.assertEquals(1, impl.getFinishedTransactionCount());
    Map<String, TracedMetricData> metrics = impl.getUnscopedMetrics();
    TracedMetricData txMetric = metrics.get("OtherTransaction/rootOnly");
    Collection<TransactionTrace> traces = impl.getTransactionTracesForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    Assert.assertEquals(txMetric.getTotalTimeInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertEquals(trace.getWallClockDurationInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertTrue(trace.getStartTime() >= start);
    Assert.assertTrue(trace.getStartTime() <= end);
    TraceSegment segment = trace.getInitialTraceSegment();
    Assert.assertEquals(1, segment.getChildren().size());
    TraceSegment seg = segment.getChildren().get(0);
    long relativeStart = segment.getRelativeStartTime();
    long relativeEnd = segment.getRelativeEndTime();
    int count = 0;
    while (seg != null) {
        count++;
        Assert.assertTrue(seg.getRelativeStartTime() >= relativeStart);
        Assert.assertTrue(seg.getRelativeEndTime() <= relativeEnd);
        Assert.assertTrue(seg.getRelativeStartTime() <= seg.getRelativeEndTime());
        relativeStart = seg.getRelativeStartTime();
        relativeEnd = seg.getRelativeEndTime();
        Map<String, Object> info = seg.getTracerAttributes();
        Assert.assertNull(info.get("async_context"));
        Assert.assertNotNull(info.get("exclusive_duration_millis"));
        Assert.assertTrue(seg.getMethodName().startsWith("default"));
        Assert.assertTrue(seg.getName().startsWith("Custom/default"));
        Assert.assertEquals("MyClass", seg.getClassName());
        if (seg.getName().equals("Custom/default3")) {
            Assert.assertEquals("hello", info.get("myatt"));
            Assert.assertEquals(99, info.get("myNumber"));
            Assert.assertEquals(0, seg.getChildren().size());
            seg = null;
        } else {
            Assert.assertEquals(1, seg.getChildren().size());
            seg = seg.getChildren().get(0);
        }
    }
    Assert.assertEquals(3, count);
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment) Test(org.junit.Test)

Aggregations

TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)33 Test (org.junit.Test)27 TraceSegment (com.newrelic.agent.introspec.TraceSegment)24 Introspector (com.newrelic.agent.introspec.Introspector)23 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)15 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)12 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)12 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)10 DatastoreHelper (com.newrelic.agent.introspec.DatastoreHelper)7 URI (java.net.URI)7 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)6 Java11IncompatibleTest (com.newrelic.test.marker.Java11IncompatibleTest)6 Java12IncompatibleTest (com.newrelic.test.marker.Java12IncompatibleTest)6 Java13IncompatibleTest (com.newrelic.test.marker.Java13IncompatibleTest)6 Java14IncompatibleTest (com.newrelic.test.marker.Java14IncompatibleTest)6 Java15IncompatibleTest (com.newrelic.test.marker.Java15IncompatibleTest)6 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)6 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)6 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)4 CountDownLatch (java.util.concurrent.CountDownLatch)4