Search in sources :

Example 6 with SpanEvent

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);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 7 with 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);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Test(org.junit.Test)

Example 8 with 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);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 9 with 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);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 10 with 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());
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Aggregations

SpanEvent (com.newrelic.agent.model.SpanEvent)81 Test (org.junit.Test)64 AttributeFilter (com.newrelic.agent.model.AttributeFilter)23 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)19 TransactionStats (com.newrelic.agent.stats.TransactionStats)14 TransactionData (com.newrelic.agent.TransactionData)12 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)12 Tracer (com.newrelic.agent.tracers.Tracer)9 HashMap (java.util.HashMap)8 Map (java.util.Map)5 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)4 TransactionDataList (com.newrelic.agent.TransactionDataList)3 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)3 Test (org.junit.jupiter.api.Test)3 SpanConverterTest.buildSpanEvent (com.newrelic.SpanConverterTest.buildSpanEvent)2 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 AttributesService (com.newrelic.agent.attributes.AttributesService)2 AgentConfig (com.newrelic.agent.config.AgentConfig)2 ReservoirManager (com.newrelic.agent.interfaces.ReservoirManager)2 Consumer (com.newrelic.agent.interfaces.backport.Consumer)2