use of com.newrelic.agent.tracing.W3CTraceState in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testWithTraceState.
@Test
public void testWithTraceState() {
// setup
String guid = "1234-abcd-dead-beef";
expectedIntrinsicAttributes.put("trustedParentId", guid);
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
W3CTraceState traceState = mock(W3CTraceState.class);
when(traceState.getGuid()).thenReturn(guid);
when(spanProxy.getInitiatingW3CTraceState()).thenReturn(traceState);
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);
}
use of com.newrelic.agent.tracing.W3CTraceState 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();
}
Aggregations