Search in sources :

Example 1 with TransportType

use of com.newrelic.api.agent.TransportType in project newrelic-java-agent by newrelic.

the class InboundHeaderState method parseDistributedTraceHeaders.

private void parseDistributedTraceHeaders() {
    // Don't override TransportType if it has already been set
    if (TransportType.Unknown.equals(tx.getTransportType())) {
        TransportType transportType = inboundHeaders.getHeaderType() == HeaderType.MESSAGE ? TransportType.JMS : TransportType.HTTP;
        tx.setTransportType(transportType);
    }
    parseAndAcceptDistributedTraceHeaders(tx, inboundHeaders);
}
Also used : TransportType(com.newrelic.api.agent.TransportType)

Example 2 with TransportType

use of com.newrelic.api.agent.TransportType in project newrelic-java-agent by newrelic.

the class TransactionTest method testWithNullPriorityDoesNotResetPriority.

@Test
public void testWithNullPriorityDoesNotResetPriority() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    configMap.put(AgentConfigImpl.DISTRIBUTED_TRACING, ImmutableMap.of("enabled", Boolean.TRUE));
    createServiceManager(configMap);
    serviceManager.setDistributedTraceService(new DistributedTraceService() {

        @Override
        public boolean isEnabled() {
            return true;
        }

        @Override
        public int getMajorSupportedCatVersion() {
            return 1;
        }

        @Override
        public int getMinorSupportedCatVersion() {
            return 0;
        }

        @Override
        public String getAccountId() {
            return "9123";
        }

        @Override
        public String getApplicationId() {
            return "1234";
        }

        @Override
        public <T extends PriorityAware> float calculatePriority(Float priority, SamplingPriorityQueue<T> reservoir) {
            return 0.678f;
        }

        @Override
        public Map<String, Object> getIntrinsics(DistributedTracePayloadImpl inboundPayload, String guid, String traceId, TransportType transportType, long parentTransportDuration, long largestTransportDuration, String parentId, String parentSpanId, float priority) {
            return null;
        }

        @Override
        public String getTrustKey() {
            return "67890";
        }

        @Override
        public DistributedTracePayload createDistributedTracePayload(Tracer tracer) {
            return null;
        }
    });
    Transaction.clearTransaction();
    Tracer dispatcherTracer = createDispatcherTracer(true);
    Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
    transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
    String inboundPayload = "{" + "  \"v\": [0,2]," + "  \"d\": {" + "    \"ty\": \"Mobile\"," + "    \"ac\": \"9123\"," + "    \"tk\": \"67890\"," + "    \"ap\": \"51424\"" + "    \"id\": \"27856f70d3d314b7\"," + "    \"tr\": \"3221bf09aa0bcf0d\"," + "    \"pr\": null," + "    \"ti\": 1482959525577" + "  }" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    String spanId = "meatball101";
    DistributedTracePayloadImpl payload = transaction.createDistributedTracePayload(spanId);
    DistributedTracePayloadImpl secondPayload = transaction.createDistributedTracePayload(spanId);
    dispatcherTracer.finish(Opcodes.ARETURN, null);
    // Verify that when the inbound priority is null, that we retain our priority.
    assertEquals("Mobile", transaction.getSpanProxy().getInboundDistributedTracePayload().parentType);
    assertEquals(0.678f, payload.priority, 0.0f);
    // Verify that the payload that gets passed on will preserve the priority we created.
    assertEquals("App", secondPayload.parentType);
    assertEquals("3221bf09aa0bcf0d", secondPayload.traceId);
    assertEquals(spanId, secondPayload.guid);
    assertEquals(0.678f, secondPayload.priority, 0.0f);
}
Also used : DistributedTraceService(com.newrelic.agent.tracing.DistributedTraceService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) TransportType(com.newrelic.api.agent.TransportType) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Aggregations

TransportType (com.newrelic.api.agent.TransportType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 DistributedTraceService (com.newrelic.agent.tracing.DistributedTraceService)1 SegmentTest (com.newrelic.agent.transaction.SegmentTest)1 Test (org.junit.Test)1