Search in sources :

Example 16 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class SpanParentTest method executeCrossProcessOnlyTest.

@Trace(dispatcher = true)
private void executeCrossProcessOnlyTest() throws IOException, URISyntaxException {
    Transaction txn = ServiceFactory.getServiceManager().getTransactionService().getTransaction(false);
    DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload(null, txn.getGuid(), txn.getGuid(), 1.0f);
    txn.acceptDistributedTracePayload(payload.httpSafe());
    try (HttpTestServer server = HttpServerLocator.createAndStart()) {
        nonExternalOrDatastore();
        executeHttpRequest(false, server.getEndPoint().getPort());
        executeFakeDatastoreRequest();
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) HttpTestServer(com.newrelic.agent.introspec.HttpTestServer) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl)

Example 17 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TraceAccessorApiTest method testAcceptPayloadGetSpanId.

@Test
public void testAcceptPayloadGetSpanId() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
    try {
        DistributedTracePayloadImpl distributedTracePayload = getDistributedTracePayload();
        // We don't care about the DT payload transaction, so we will harvest and clear the tx list before continuing
        harvestAndCheckTxn(holder);
        TransactionDataList transactionList = holder.getTransactionList();
        transactionList.clear();
        String spanId = startTxAcceptPayloadAndReturnSpanId(distributedTracePayload);
        harvestAndCheckTxn(holder);
        Tracer rootTracer = transactionList.get(0).getRootTracer();
        String expectedGuid = rootTracer.getGuid();
        assertEquals(expectedGuid, spanId);
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) Tracer(com.newrelic.agent.tracers.Tracer) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Test(org.junit.Test)

Example 18 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TracerToSpanEventTest method testParentIdFromDTPayload.

@Test
public void testParentIdFromDTPayload() {
    // setup
    String parentGuid = "98765";
    expectedIntrinsicAttributes.put("parentId", parentGuid);
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    DistributedTracePayloadImpl dtPayload = mock(DistributedTracePayloadImpl.class);
    when(dtPayload.getGuid()).thenReturn(parentGuid);
    when(txnData.getInboundDistributedTracePayload()).thenReturn(dtPayload);
    TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
    // execution
    SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, isRoot, false);
    // assertions
    assertEquals(expectedSpanEvent, spanEvent);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Test(org.junit.Test)

Example 19 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TracerToSpanEvent method createSpanEvent.

public SpanEvent createSpanEvent(Tracer tracer, TransactionData transactionData, TransactionStats transactionStats, boolean isRoot, boolean crossProcessOnly) {
    SpanProxy spanProxy = transactionData.getSpanProxy();
    DistributedTracePayloadImpl inboundPayload = spanProxy.getInboundDistributedTracePayload();
    SpanEventFactory builder = new SpanEventFactory(transactionData.getApplicationName(), filter, timestampSupplier).setGuid(tracer.getGuid()).setTraceId(spanProxy.getOrCreateTraceId()).setSampled(transactionData.sampled()).setParentId(getParentId(tracer, transactionData, crossProcessOnly)).setTransactionId(transactionData.getGuid()).setDurationInSeconds((float) tracer.getDuration() / TimeConversion.NANOSECONDS_PER_SECOND).setName(tracer.getTransactionSegmentName()).setTimestamp(tracer.getStartTimeInMillis()).setPriority(transactionData.getPriority()).setExternalParameterAttributes(tracer.getExternalParameters()).setIsRootSpanEvent(isRoot).setDecider(inboundPayload == null || inboundPayload.priority == null);
    builder = maybeSetError(tracer, transactionData, isRoot, builder);
    builder = maybeSetGraphQLAttributes(tracer, builder);
    W3CTraceState traceState = spanProxy.getInitiatingW3CTraceState();
    if (traceState != null) {
        if (isRoot && traceState.getGuid() != null) {
            builder.setTrustedParent(traceState.getGuid());
        }
        Set<String> vendorKeys = W3CTraceStateSupport.buildVendorKeys(traceState);
        builder.setTracingVendors(vendorKeys);
    }
    LimitedSizeHashMap<String, Object> spanUserAttributes = new LimitedSizeHashMap<>(MAX_USER_ATTRIBUTES);
    // order matters here because we don't want transaction attributes to overwrite tracer attributes. This would be the case if there were 64
    // transaction attributes and they got added first to the span attributes map. Then none of the tracer attributes would make it in due
    // to the limit of 64 attributes.
    spanUserAttributes.putAll(tracer.getCustomAttributes());
    if (isRoot) {
        copyTransactionAttributesToRootSpanBuilder(builder, transactionData, spanUserAttributes, transactionStats);
    }
    builder.putAllUserAttributes(spanUserAttributes);
    return builder.build();
}
Also used : SpanProxy(com.newrelic.agent.tracing.SpanProxy) W3CTraceState(com.newrelic.agent.tracing.W3CTraceState) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl)

Example 20 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class SlowQueryInfo method createParameters.

@SuppressWarnings("unchecked")
private Map<String, Object> createParameters(Tracer tracer) {
    Map<String, Object> parameters = new HashMap<>();
    // Check for an explain plan (right now this only potentially exists for a SqlTracer)
    Object explainPlan = tracer.getAgentAttribute(SqlTracer.EXPLAIN_PLAN_PARAMETER_NAME);
    if (explainPlan != null) {
        parameters.put(SlowQueryAggregatorImpl.EXPLAIN_PLAN_KEY, explainPlan);
    }
    // A backtrace could exist for any type of tracer
    List<StackTraceElement> backtrace = (List<StackTraceElement>) tracer.getAgentAttribute(DefaultTracer.BACKTRACE_PARAMETER_NAME);
    if (backtrace != null) {
        backtrace = StackTraces.scrubAndTruncate(backtrace);
        List<String> backtraceStrings = StackTraces.toStringList(backtrace);
        parameters.put(SlowQueryAggregatorImpl.BACKTRACE_KEY, backtraceStrings);
    }
    DatastoreConfig datastoreConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDatastoreConfig();
    String host = (String) tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_HOST);
    String port_path_or_id = (String) tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID);
    boolean allUnknown = host == null && port_path_or_id == null;
    if (datastoreConfig.isInstanceReportingEnabled() && !allUnknown) {
        parameters.put(DatastoreMetrics.DATASTORE_HOST, host);
        parameters.put(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID, port_path_or_id);
    }
    String databaseName = (String) tracer.getAgentAttribute(DatastoreMetrics.DB_INSTANCE);
    if (datastoreConfig.isDatabaseNameReportingEnabled() && databaseName != null) {
        parameters.put(DatastoreMetrics.DB_INSTANCE, databaseName);
    }
    // An input query could exist for any type of tracer and records ORM-like query strings
    Map<String, String> inputQuery = (Map<String, String>) tracer.getAgentAttribute(DatastoreMetrics.INPUT_QUERY_ATTRIBUTE);
    if (inputQuery != null) {
        parameters.put(DatastoreMetrics.INPUT_QUERY_ATTRIBUTE, inputQuery);
    }
    Transaction txn = tracer.getTransactionActivity().getTransaction();
    DistributedTracePayloadImpl inboundPayload = txn.getSpanProxy().getInboundDistributedTracePayload();
    DistributedTraceService distributedTraceService = ServiceFactory.getDistributedTraceService();
    DistributedTracingConfig distributedTracingConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDistributedTracingConfig();
    if (distributedTracingConfig.isEnabled()) {
        String traceId = txn.getOrCreateTraceId();
        String parentId = inboundPayload == null ? null : inboundPayload.txnId;
        String parentSpanId = inboundPayload == null ? null : inboundPayload.guid;
        Map<String, Object> intrinsics = distributedTraceService.getIntrinsics(inboundPayload, txn.getGuid(), traceId, txn.getTransportType(), txn.getTransportDurationInMillis(), txn.getLargestTransportDurationInMillis(), parentId, parentSpanId, txn.getPriority());
        parameters.putAll(intrinsics);
    }
    parameters.put("priority", txn.getPriority());
    return parameters;
}
Also used : DistributedTraceService(com.newrelic.agent.tracing.DistributedTraceService) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) HashMap(java.util.HashMap) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Transaction(com.newrelic.agent.Transaction) DatastoreConfig(com.newrelic.agent.config.DatastoreConfig) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)22 Test (org.junit.Test)8 Tracer (com.newrelic.agent.tracers.Tracer)6 SpanProxy (com.newrelic.agent.tracing.SpanProxy)5 Transaction (com.newrelic.agent.Transaction)4 SpanEvent (com.newrelic.agent.model.SpanEvent)3 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)3 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)3 DistributedTraceService (com.newrelic.agent.tracing.DistributedTraceService)3 SegmentTest (com.newrelic.agent.transaction.SegmentTest)3 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 TransactionData (com.newrelic.agent.TransactionData)2 TransactionDataList (com.newrelic.agent.TransactionDataList)2 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)2 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)2 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)2 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)2 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)2