Search in sources :

Example 1 with OutboundHeaders

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());
}
Also used : HashMap(java.util.HashMap) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) HeaderType(com.newrelic.api.agent.HeaderType) SpanEvent(com.newrelic.agent.model.SpanEvent) OutboundHeaders(com.newrelic.api.agent.OutboundHeaders) Test(org.junit.Test)

Example 2 with OutboundHeaders

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());
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) InboundHeaders(com.newrelic.api.agent.InboundHeaders) CrossProcessConfig(com.newrelic.agent.config.CrossProcessConfig) OutboundHeaders(com.newrelic.api.agent.OutboundHeaders) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) Before(org.junit.Before)

Example 3 with OutboundHeaders

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.");
    }
}
Also used : OutboundHeaders(com.newrelic.api.agent.OutboundHeaders) DestinationType(com.newrelic.api.agent.DestinationType)

Aggregations

OutboundHeaders (com.newrelic.api.agent.OutboundHeaders)3 ExitTracer (com.newrelic.agent.bridge.ExitTracer)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 CrossProcessConfig (com.newrelic.agent.config.CrossProcessConfig)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 DestinationType (com.newrelic.api.agent.DestinationType)1 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)1 HeaderType (com.newrelic.api.agent.HeaderType)1 InboundHeaders (com.newrelic.api.agent.InboundHeaders)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1