use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testParentIdFromParentSpan.
@Test
public void testParentIdFromParentSpan() {
// setup
String parentGuid = "98765";
expectedIntrinsicAttributes.put("parentId", parentGuid);
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
Tracer parentTracer = mock(Tracer.class);
when(parentTracer.getGuid()).thenReturn(parentGuid);
when(parentTracer.isTransactionSegment()).thenReturn(true);
when(spanErrorBuilder.buildSpanError(tracer, false, responseStatus, statusMessage, throwable)).thenReturn(spanError);
when(tracer.getParentTracer()).thenReturn(parentTracer);
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.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testRequestAttributesAddedToRoot.
@Test
public void testRequestAttributesAddedToRoot() {
// setup
String requestUri = "httpss://404.com";
String requestMethod = "SUPERGET";
String requestHeadersRefer = "referee";
String requestHeadersAccept = "college";
String requestHeadersContentLength = "very long";
String requestHeadersHost = "Drew Carey";
String requestHeadersUserAgent = "007";
float queueDuration = 123456789F;
expectedAgentAttributes.put(REQUEST_REFERER_PARAMETER_NAME, requestHeadersRefer);
expectedAgentAttributes.put(REQUEST_ACCEPT_PARAMETER_NAME, requestHeadersAccept);
expectedAgentAttributes.put(REQUEST_CONTENT_LENGTH_PARAMETER_NAME, requestHeadersContentLength);
expectedAgentAttributes.put(REQUEST_HOST_PARAMETER_NAME, requestHeadersHost);
expectedAgentAttributes.put(REQUEST_USER_AGENT_PARAMETER_NAME, requestHeadersUserAgent);
expectedAgentAttributes.put(REQUEST_METHOD_PARAMETER_NAME, requestMethod);
expectedAgentAttributes.put(REQUEST_URI, requestUri);
expectedAgentAttributes.put(PORT, port);
expectedAgentAttributes.put(QUEUE_DURATION, queueDuration);
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
transactionAgentAttributes.put(REQUEST_REFERER_PARAMETER_NAME, requestHeadersRefer);
transactionAgentAttributes.put(REQUEST_ACCEPT_PARAMETER_NAME, requestHeadersAccept);
transactionAgentAttributes.put(REQUEST_CONTENT_LENGTH_PARAMETER_NAME, requestHeadersContentLength);
transactionAgentAttributes.put(REQUEST_HOST_PARAMETER_NAME, requestHeadersHost);
transactionAgentAttributes.put(REQUEST_USER_AGENT_PARAMETER_NAME, requestHeadersUserAgent);
transactionAgentAttributes.put(REQUEST_METHOD_PARAMETER_NAME, requestMethod);
transactionAgentAttributes.put(REQUEST_URI, requestUri);
transactionAgentAttributes.put(PORT, port);
when(txnData.getAgentAttributes()).thenReturn(transactionAgentAttributes);
when(environment.getAgentIdentity()).thenReturn(new AgentIdentity("dispatcher", "1.2.3", port, "myInstance"));
when(txnStats.getUnscopedStats().getStatsMap().containsKey(QUEUE_TIME)).thenReturn(true);
when(txnStats.getUnscopedStats().getOrCreateResponseTimeStats(QUEUE_TIME).getTotal()).thenReturn(queueDuration);
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.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testCrossProcessOnly.
@Test
public void testCrossProcessOnly() {
// setup
String parentGuid = "98765";
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
Tracer parentTracer = mock(Tracer.class);
// the parent tracer and guid are used to make sure the test fails if crossProcessOnly isn't set
when(parentTracer.getGuid()).thenReturn(parentGuid);
when(parentTracer.isTransactionSegment()).thenReturn(true);
when(spanErrorBuilder.buildSpanError(tracer, false, responseStatus, statusMessage, throwable)).thenReturn(spanError);
when(tracer.getParentTracer()).thenReturn(parentTracer);
TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
// execution
SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, isRoot, true);
// assertions
assertEquals(expectedSpanEvent, spanEvent);
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testErrorCollectorDisabled.
@Test
public void testErrorCollectorDisabled() {
// setup
expectedAgentAttributes.remove("error.class");
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
when(spanErrorBuilder.areErrorsEnabled()).thenReturn(false);
TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
// execution
SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, true, false);
// assertions
assertEquals(expectedSpanEvent, spanEvent);
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testSpanAttributeLimits.
@Test
public void testSpanAttributeLimits() {
// setup
for (int i = 1; i <= 100; i++) {
tracerUserAttributes.put("SpanAttrib" + i, "SpanValue" + i);
}
for (int i = 1; i <= 64; i++) {
expectedUserAttributes.put("SpanAttrib" + i, "SpanValue" + i);
}
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
// execution
SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, true, false);
// assertions
assertEquals("size was actually " + spanEvent.getUserAttributesCopy().size(), 64, spanEvent.getUserAttributesCopy().size());
}
Aggregations