use of com.newrelic.agent.introspec.TraceSegment 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());
}
}
}
}
}
use of com.newrelic.agent.introspec.TraceSegment 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?
}
use of com.newrelic.agent.introspec.TraceSegment 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());
}
use of com.newrelic.agent.introspec.TraceSegment in project newrelic-java-agent by newrelic.
the class RabbitMQTest_Integration method getAttribute.
private String getAttribute(TransactionTrace senderTT, String attributeName) {
Queue<TraceSegment> queue = new LinkedList<TraceSegment>();
queue.offer(senderTT.getInitialTraceSegment());
while (!queue.isEmpty()) {
TraceSegment segment = queue.poll();
if (segment.getTracerAttributes().containsKey(attributeName)) {
return (String) segment.getTracerAttributes().get(attributeName);
}
for (TraceSegment childSegment : segment.getChildren()) {
queue.offer(childSegment);
}
}
return null;
}
use of com.newrelic.agent.introspec.TraceSegment in project newrelic-java-agent by newrelic.
the class RabbitMQTest method assertProduceConsumeTraceAttrs.
private void assertProduceConsumeTraceAttrs(TransactionTrace trace, String exchangeName, String replyTo, String correlationId, Map<String, Object> headers) {
// Collect all segments
Map<String, TraceSegment> segments = new HashMap<>();
Queue<TraceSegment> queue = new LinkedList<>();
queue.offer(trace.getInitialTraceSegment());
while (!queue.isEmpty()) {
TraceSegment segment = queue.poll();
segments.put(segment.getName(), segment);
queue.addAll(segment.getChildren());
}
TraceSegment produceSegment = segments.get("MessageBroker/RabbitMQ/Exchange/Consume/Named/" + exchangeName);
assertTrue(produceSegment.getTracerAttributes().containsKey("message.routingKey"));
assertEquals(replyTo, produceSegment.getTracerAttributes().get("message.replyTo"));
assertEquals(correlationId, produceSegment.getTracerAttributes().get("message.correlationId"));
for (String key : headers.keySet()) {
assertNotNull(produceSegment.getTracerAttributes().get("message." + key));
}
TraceSegment consumeSegment = segments.get("MessageBroker/RabbitMQ/Exchange/Consume/Named/" + exchangeName);
assertTrue(consumeSegment.getTracerAttributes().containsKey("message.routingKey"));
assertTrue(consumeSegment.getTracerAttributes().containsKey("message.queueName"));
assertEquals(replyTo, consumeSegment.getTracerAttributes().get("message.replyTo"));
for (String key : headers.keySet()) {
assertNotNull(consumeSegment.getTracerAttributes().get("message." + key));
}
}
Aggregations