Search in sources :

Example 6 with SpanProxy

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

the class CrossProcessTransactionStateImplTest method mockBasicTransactionMethods.

private void mockBasicTransactionMethods() {
    when(tx.getLock()).thenReturn(new Object());
    when(tx.getSpanProxy()).thenReturn(new SpanProxy());
    when(tx.isIgnore()).thenReturn(false);
}
Also used : SpanProxy(com.newrelic.agent.tracing.SpanProxy)

Example 7 with SpanProxy

use of com.newrelic.agent.tracing.SpanProxy 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 8 with SpanProxy

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

the class DefaultTracerTest method testSpanParentingEvent.

@Test
public void testSpanParentingEvent() {
    DefaultTracer tracer = prepareTracer();
    tracer.finish(0, null);
    SpanProxy spanProxy = tracer.getTransaction().getSpanProxy();
    W3CTraceParentHeader.create(spanProxy, "12341234123412341234123412341234", "0101010101010101", false);
    SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
    ((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
    SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    List<SpanEvent> spanEvents = eventPool.asList();
    assertNotNull(spanEvents);
    assertEquals(1, spanEvents.size());
    SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
    assertNotNull(spanEvent);
    Assert.assertNotEquals("0101010101010101", spanEvent.getParentId());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanProxy(com.newrelic.agent.tracing.SpanProxy) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Aggregations

SpanProxy (com.newrelic.agent.tracing.SpanProxy)8 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)5 TransactionData (com.newrelic.agent.TransactionData)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 Tracer (com.newrelic.agent.tracers.Tracer)2 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)2 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1 AgentIdentity (com.newrelic.agent.environment.AgentIdentity)1 Environment (com.newrelic.agent.environment.Environment)1 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 SpanError (com.newrelic.agent.model.SpanError)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)1 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)1 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)1 W3CTraceParent (com.newrelic.agent.tracing.W3CTraceParent)1 W3CTraceState (com.newrelic.agent.tracing.W3CTraceState)1 W3CTraceStateHeader (com.newrelic.agent.tracing.W3CTraceStateHeader)1