Search in sources :

Example 6 with TransactionSegment

use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.

the class AsyncTest method verifyTransactionSegmentNodesWithExecContext.

public void verifyTransactionSegmentNodesWithExecContext(Map<String, String> metricToContext) {
    Assert.assertNotNull(data);
    TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
    TransactionSegment root = trace.getRootSegment();
    Queue<TransactionSegment> segments = new LinkedList<>(root.getChildren());
    int index = 0;
    while (!segments.isEmpty()) {
        TransactionSegment seg = segments.poll();
        String context = metricToContext.get(seg.getMetricName());
        if (context != null) {
            Assert.assertNotNull(seg.getTraceParameters().get("async_context"));
            Assert.assertEquals(context, seg.getTraceParameters().get("async_context"));
            index++;
        } else {
            Assert.assertNull(seg.getTraceParameters().get("async_context"));
        }
        segments.addAll(seg.getChildren());
    }
    Assert.assertEquals(index, metricToContext.size());
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionTrace(com.newrelic.agent.trace.TransactionTrace) LinkedList(java.util.LinkedList)

Example 7 with TransactionSegment

use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.

the class AsyncTest method verifyTransactionSegmentsChildren.

public void verifyTransactionSegmentsChildren(String parent, String... children) {
    Assert.assertNotNull(data);
    TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
    TransactionSegment root = trace.getRootSegment();
    Queue<TransactionSegment> segments = new LinkedList<>(root.getChildren());
    int index = 0;
    while (!segments.isEmpty()) {
        TransactionSegment seg = segments.poll();
        if (parent.equals(seg.getMetricName())) {
            Collection<TransactionSegment> actualChildren = seg.getChildren();
            List<String> expectedChildren = Arrays.asList(children);
            for (TransactionSegment current : actualChildren) {
                Assert.assertTrue(expectedChildren.contains(current.getMetricName()));
                index++;
            }
        } else {
            segments.addAll(seg.getChildren());
        }
    }
    Assert.assertEquals(index, children.length);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionTrace(com.newrelic.agent.trace.TransactionTrace) LinkedList(java.util.LinkedList)

Example 8 with TransactionSegment

use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.

the class TraceSegmentImpl method createTraceSegment.

static TraceSegmentImpl createTraceSegment(TransactionTrace trace, TransactionSegment tracer) {
    TraceSegmentImpl output = new TraceSegmentImpl();
    output.name = tracer.getMetricName();
    output.startMs = tracer.getStartTime();
    output.endMs = tracer.getEndTime();
    output.className = tracer.getClassName();
    output.methodName = tracer.getMethodName();
    output.atts = Maps.newHashMap(tracer.getTraceParameters());
    output.atts.putAll(trace.getUserAttributes());
    Collection<TransactionSegment> originalChildren = tracer.getChildren();
    output.children = new ArrayList<>(originalChildren.size());
    for (TransactionSegment current : originalChildren) {
        TraceSegmentImpl impl = createTraceSegment(trace, current);
        output.children.add(impl);
    }
    output.uri = tracer.getUri();
    output.callCount = tracer.getCallCount();
    return output;
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment)

Example 9 with TransactionSegment

use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.

the class AsyncTest method verifyGivenTransactionSegmentBreadthFirst.

private void verifyGivenTransactionSegmentBreadthFirst(TransactionSegment segment, String... metricNamesAndThreads) {
    Assert.assertEquals("ROOT", segment.getMetricName());
    Assert.assertNotNull(segment.getTraceParameters().get("async_context"));
    Queue<TransactionSegment> segments = new LinkedList<>(segment.getChildren());
    int index = 0;
    while (!segments.isEmpty()) {
        TransactionSegment seg = segments.poll();
        Assert.assertEquals(metricNamesAndThreads[index], seg.getMetricName());
        index++;
        String next = metricNamesAndThreads[index];
        if (next.equals(NO_ASYNC_CONTEXT)) {
            Assert.assertNull(seg.getTraceParameters().get("async_context"));
        } else {
            Assert.assertNotNull(seg.getTraceParameters().get("async_context"));
            Assert.assertEquals(metricNamesAndThreads[index], seg.getTraceParameters().get("async_context"));
        }
        index++;
        segments.addAll(seg.getChildren());
    }
    Assert.assertEquals(index, metricNamesAndThreads.length);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) LinkedList(java.util.LinkedList)

Example 10 with TransactionSegment

use of com.newrelic.agent.trace.TransactionSegment in project newrelic-java-agent by newrelic.

the class AsyncTest method verifyTransactionSegmentsBreadthFirst.

public void verifyTransactionSegmentsBreadthFirst(String scope, String... metricNamesAndThreads) {
    Assert.assertNotNull(data);
    TransactionTrace trace = TransactionTrace.getTransactionTrace(data);
    Assert.assertEquals(scope, trace.getRootMetricName());
    TransactionSegment root = trace.getRootSegment();
    verifyGivenTransactionSegmentBreadthFirst(root, metricNamesAndThreads);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionTrace(com.newrelic.agent.trace.TransactionTrace)

Aggregations

TransactionSegment (com.newrelic.agent.trace.TransactionSegment)16 TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)8 SqlObfuscator (com.newrelic.agent.database.SqlObfuscator)8 Test (org.junit.Test)8 JSONArray (org.json.simple.JSONArray)6 JSONObject (org.json.simple.JSONObject)5 TransactionTrace (com.newrelic.agent.trace.TransactionTrace)3 LinkedList (java.util.LinkedList)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Transaction (com.newrelic.agent.Transaction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1