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);
}
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();
}
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());
}
Aggregations