Search in sources :

Example 11 with SpanEvent

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

the class TracerToSpanEventTest method testTracerAttributes.

@Test
public void testTracerAttributes() {
    // setup
    tracerUserAttributes.put("user", "attribute");
    expectedUserAttributes.put("user", "attribute");
    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(expectedSpanEvent, spanEvent);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 12 with SpanEvent

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

the class TracerToSpanEventTest method testParentIdFromW3CPayload.

@Test
public void testParentIdFromW3CPayload() {
    // setup
    String parentGuid = "98765";
    expectedIntrinsicAttributes.put("parentId", parentGuid);
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    W3CTraceParent w3cPayload = mock(W3CTraceParent.class);
    when(txnData.getW3CTraceParent()).thenReturn(w3cPayload);
    when(w3cPayload.getParentId()).thenReturn(parentGuid);
    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 : W3CTraceParent(com.newrelic.agent.tracing.W3CTraceParent) SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 13 with SpanEvent

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

the class TracerToSpanEventTest method testGraphQLAttribute.

@Test
public void testGraphQLAttribute() {
    // setup
    expectedAgentAttributes.put("graphql.operation.type", "Query");
    expectedAgentAttributes.put("graphql.field.name", "book");
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    tracerAgentAttributes.put("graphql.operation.type", "Query");
    tracerAgentAttributes.put("graphql.field.name", "book");
    TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
    // execution
    SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, true, false);
    when(txnData.getAgentAttributes()).thenReturn(transactionAgentAttributes);
    // assertions
    assertEquals(expectedSpanEvent, spanEvent);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 14 with SpanEvent

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

the class TracerToSpanEventTest method testUndesiredAttributesFiltered.

@Test
public void testUndesiredAttributesFiltered() {
    // setup
    Map<String, Object> intrinsicAttributes = new HashMap<>();
    intrinsicAttributes.put("foo", "bar");
    intrinsicAttributes.put("externalCallCount", 13);
    Map<String, Object> userAttributes = new HashMap<>();
    userAttributes.put("ok", "okey");
    userAttributes.put("host.displayName", "myrad.server");
    userAttributes.put("parentSpanId", "1234-abcd");
    transactionAgentAttributes.put("a", "b");
    transactionAgentAttributes.put("nr.guid", "I sure hope I don't make it to the output");
    expectedAgentAttributes.put("a", "b");
    expectedAgentAttributes.put("foo", "bar");
    expectedUserAttributes = new HashMap<>();
    expectedUserAttributes.put("ok", "okey");
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    when(txnData.getIntrinsicAttributes()).thenReturn(intrinsicAttributes);
    when(txnData.getUserAttributes()).thenReturn(userAttributes);
    when(txnData.getAgentAttributes()).thenReturn(transactionAgentAttributes);
    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 : HashMap(java.util.HashMap) SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) Test(org.junit.Test)

Example 15 with SpanEvent

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

the class TracerToSpanEventTest method testAutoAppNaming.

@Test
public void testAutoAppNaming() {
    // setup
    String newAppName = "new app name";
    when(txnData.getApplicationName()).thenReturn(newAppName);
    SpanEvent expectedSpanEvent = SpanEvent.builder().appName(newAppName).priority(priority).putAllAgentAttributes(expectedAgentAttributes).putAllIntrinsics(expectedIntrinsicAttributes).putAllUserAttributes(expectedUserAttributes).decider(true).timestamp(timestamp).build();
    when(spanErrorBuilder.areErrorsEnabled()).thenReturn(true);
    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)

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