Search in sources :

Example 56 with SpanEvent

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

Example 57 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class TracerToSpanEventTest method testParentIdFromDTPayload.

@Test
public void testParentIdFromDTPayload() {
    // setup
    String parentGuid = "98765";
    expectedIntrinsicAttributes.put("parentId", parentGuid);
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    DistributedTracePayloadImpl dtPayload = mock(DistributedTracePayloadImpl.class);
    when(dtPayload.getGuid()).thenReturn(parentGuid);
    when(txnData.getInboundDistributedTracePayload()).thenReturn(dtPayload);
    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) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Test(org.junit.Test)

Example 58 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class TracerToSpanEventTest method testPrefixedAttributesAddedToRoot.

@Test
public void testPrefixedAttributesAddedToRoot() {
    Map<String, Map<String, String>> prefixedAttributes = new HashMap<>();
    Map<String, String> requestAttributes = new HashMap<>();
    Map<String, String> messagingAttributes = new HashMap<>();
    prefixedAttributes.put(HTTP_REQUEST_PREFIX, requestAttributes);
    prefixedAttributes.put(MESSAGE_REQUEST_PREFIX, messagingAttributes);
    requestAttributes.put("count", "7");
    messagingAttributes.put("messagingService", "fakebook");
    // setup
    expectedAgentAttributes.put(HTTP_REQUEST_PREFIX + "count", "7");
    expectedAgentAttributes.put(MESSAGE_REQUEST_PREFIX + "messagingService", "fakebook");
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    when(txnData.getPrefixedAttributes()).thenReturn(prefixedAttributes);
    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 : HashMap(java.util.HashMap) SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 59 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanEventFactoryTest method categoryShouldBeSet.

@Test
public void categoryShouldBeSet() {
    SpanEvent target = spanEventFactory.setCategory(SpanCategory.http).build();
    assertEquals(SpanCategory.http, target.getCategory());
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 60 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanEventFactoryTest method shouldNotSetStatusCodeWhenFiltering.

@Test
public void shouldNotSetStatusCodeWhenFiltering() {
    SpanEventFactory factory = new SpanEventFactory("blerb", new PassNothingAttributeFilter(), DEFAULT_SYSTEM_TIMESTAMP_SUPPLIER);
    SpanEvent spanEvent = factory.setHttpStatusCode(418).build();
    assertNull(spanEvent.getAgentAttributes().get("http.statusCode"));
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) 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