use of com.newrelic.api.agent.OutboundHeaders 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.OutboundHeaders in project newrelic-java-agent by newrelic.
the class InboundHeaderStateTest method setup.
@Before
public void setup() {
serviceManager.setConfigService(new MockConfigService(AgentConfigFactory.createAgentConfig(Collections.emptyMap(), Collections.emptyMap(), null)));
ServiceFactory.setServiceManager(serviceManager);
OutboundHeaders outboundHeaders = mock(OutboundHeaders.class);
InboundHeaders inboundHeaders = mock(InboundHeaders.class);
request = mock(ExtendedRequest.class);
agentConfig = mock(AgentConfig.class);
crossProcessConfig = mock(CrossProcessConfig.class);
distributedTracingConfig = mock(DistributedTracingConfig.class);
tx = mock(Transaction.class);
when(inboundHeaders.getHeaderType()).thenReturn(HeaderType.HTTP);
when(outboundHeaders.getHeaderType()).thenReturn(HeaderType.HTTP);
when(crossProcessConfig.getEncodingKey()).thenReturn(encodingKey);
when(crossProcessConfig.isCrossApplicationTracing()).thenReturn(true);
when(distributedTracingConfig.isEnabled()).thenReturn(false);
when(agentConfig.getDistributedTracingConfig()).thenReturn(distributedTracingConfig);
when(tx.isIgnore()).thenReturn(false);
when(tx.getDispatcher()).thenReturn(mock(Dispatcher.class));
when(tx.getDispatcher().getRequest()).thenReturn(request);
when(tx.getDispatcher().getRequest().getHeaderType()).thenReturn(HeaderType.HTTP);
when(tx.getCrossProcessConfig()).thenReturn(crossProcessConfig);
when(tx.getAgentConfig()).thenReturn(agentConfig);
when(tx.getPriorityTransactionName()).thenReturn(PriorityTransactionName.create("Test", "TEST", TransactionNamePriority.NONE));
when(tx.getApplicationName()).thenReturn("TestApp");
when(tx.getLock()).thenReturn(new Object());
}
use of com.newrelic.api.agent.OutboundHeaders in project newrelic-java-agent by newrelic.
the class DefaultTracer method catForMessaging.
private void catForMessaging(MessageProduceParameters produceParameters) {
OutboundHeaders outboundHeaders = produceParameters.getOutboundHeaders();
if (outboundHeaders == null) {
return;
}
// In amqp we don't know if we're sending a request or a response.
DestinationType destinationType = produceParameters.getDestinationType();
if (destinationType == DestinationType.EXCHANGE) {
addOutboundRequestHeaders(outboundHeaders);
} else // 2. Producing a message to a temporary queue, it is writing a response (outbound response).
if (destinationType == DestinationType.NAMED_QUEUE || destinationType == DestinationType.NAMED_TOPIC) {
addOutboundRequestHeaders(outboundHeaders);
} else if (destinationType == DestinationType.TEMP_QUEUE || destinationType == DestinationType.TEMP_TOPIC) {
getTransaction().getCrossProcessState().processOutboundResponseHeaders(outboundHeaders, -1);
} else {
Agent.LOG.log(Level.FINE, "Unexpected destination type when recording CAT metrics for message produce.");
}
}
Aggregations