use of com.newrelic.api.agent.HeaderType in project newrelic-java-agent by newrelic.
the class SegmentTest method testSpanParenting.
@Test
public void testSpanParenting() {
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
Transaction.clearTransaction();
Tracer rootTracer = makeTransaction();
rootTracer.getTransactionActivity().getTransaction().setPriorityIfNotNull(1.0f);
rootTracer.setMetricName("RootTracer");
Transaction tx = rootTracer.getTransactionActivity().getTransaction();
Segment segment = tx.startSegment("custom", "segment");
final HashMap<String, String> headers = new HashMap<>();
segment.addOutboundRequestHeaders(new OutboundHeaders() {
@Override
public HeaderType getHeaderType() {
return HeaderType.HTTP;
}
@Override
public void setHeader(String name, String value) {
headers.put(name, value);
}
});
String payload = headers.get("newrelic");
segment.end();
rootTracer.finish(Opcodes.ARETURN, null);
Transaction.clearTransaction();
Tracer secondRootTracer = makeTransaction();
secondRootTracer.setMetricName("SecondRootTracer");
Transaction secondTxn = secondRootTracer.getTransactionActivity().getTransaction();
secondTxn.acceptDistributedTracePayload(payload);
secondRootTracer.finish(Opcodes.ARETURN, null);
List<SpanEvent> spanEvents = eventPool.asList();
Assert.assertNotNull(spanEvents);
assertEquals(3, spanEvents.size());
SpanEvent rootTracerSpanEvent = findSpanByName(spanEvents, "RootTracer");
SpanEvent segmentSpanEvent = findSpanByName(spanEvents, "custom/segment");
SpanEvent secondRootTracerSpanEvent = findSpanByName(spanEvents, "SecondRootTracer");
assertEquals(rootTracerSpanEvent.getTraceId(), segmentSpanEvent.getTraceId());
assertEquals(segmentSpanEvent.getTraceId(), secondRootTracerSpanEvent.getTraceId());
assertEquals(rootTracerSpanEvent.getGuid(), segmentSpanEvent.getParentId());
assertEquals(segmentSpanEvent.getGuid(), secondRootTracerSpanEvent.getParentId());
}
use of com.newrelic.api.agent.HeaderType in project newrelic-java-agent by newrelic.
the class OtherTransactionErrorsTest method testException.
@Test
public void testException() throws Exception {
MockHttpRequest mockHttpRequest = new MockHttpRequest();
mockHttpRequest.setMethod("GET");
mockHttpRequest.setRequestURI("requesturi");
mockHttpRequest.setHeader(AttributeNames.REQUEST_ACCEPT_PARAMETER_NAME, "accept");
mockHttpRequest.setHeader(AttributeNames.REQUEST_HOST_PARAMETER_NAME, "host");
mockHttpRequest.setHeader(AttributeNames.REQUEST_USER_AGENT_PARAMETER_NAME, "useragent");
mockHttpRequest.setHeader(AttributeNames.REQUEST_CONTENT_LENGTH_PARAMETER_NAME, "content-length");
NewRelic.setRequestAndResponse(mockHttpRequest, new Response() {
@Override
public int getStatus() throws Exception {
return 200;
}
@Override
public String getStatusMessage() throws Exception {
return "Status Message";
}
@Override
public String getContentType() {
return "text/content-type";
}
@Override
public HeaderType getHeaderType() {
return HeaderType.HTTP;
}
@Override
public void setHeader(String name, String value) {
//
}
});
try {
new Runnable() {
@Trace(dispatcher = true)
@Override
public void run() {
throw new RuntimeException();
}
}.run();
} catch (RuntimeException ex) {
}
Assert.assertEquals(1, transactions.size());
Assert.assertNotNull(transactions.get(0).getThrowable());
}
Aggregations