Search in sources :

Example 36 with SpanEvent

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

the class SpanEventFactoryTest method shouldFilterAgentAttributes.

@Test
public void shouldFilterAgentAttributes() {
    SpanEventFactory target = new SpanEventFactory("blerb", new AttributeFilter.PassEverythingAttributeFilter() {

        @Override
        public Map<String, ?> filterAgentAttributes(String appName, Map<String, ?> agentAttributes) {
            return Collections.<String, Object>singletonMap("filtered", "yes");
        }
    }, DEFAULT_SYSTEM_TIMESTAMP_SUPPLIER);
    SpanEvent spanEvent = target.putAllAgentAttributes(Collections.<String, Object>singletonMap("original", "sad")).build();
    assertEquals("yes", spanEvent.getAgentAttributes().get("filtered"));
    assertNull(spanEvent.getAgentAttributes().get("original"));
}
Also used : AttributeFilter(com.newrelic.agent.model.AttributeFilter) SpanEvent(com.newrelic.agent.model.SpanEvent) Map(java.util.Map) Test(org.junit.Test)

Example 37 with SpanEvent

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

the class SpanEventsServiceTest method testMaxSamplesStored.

@Test
public void testMaxSamplesStored() {
    SpanEventsService spanEventsService = serviceManager.getSpanEventsService();
    spanEventsService.setMaxSamplesStored(0);
    final SpanEvent event = new SpanEventFactory(APP_NAME).setCategory(SpanCategory.generic).setDecider(true).setPriority(1.23f).setDurationInSeconds(1.3f).setHostName("yourHost").setTraceId("gnisnacirema").setGuid("globallyuniqueidentifier").setSampled(true).build();
    spanEventsService.storeEvent(event);
    SamplingPriorityQueue<SpanEvent> reservoir = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    assertEquals(0, reservoir.size());
    spanEventsService.setMaxSamplesStored(2);
    spanEventsService.storeEvent(event);
    spanEventsService.storeEvent(event);
    spanEventsService.storeEvent(event);
    spanEventsService.storeEvent(event);
    spanEventsService.storeEvent(event);
    reservoir = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    assertEquals(2, reservoir.size());
    spanEventsService.setMaxSamplesStored(13);
    for (int i = 0; i < 100; i++) {
        spanEventsService.storeEvent(event);
    }
    reservoir = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    assertEquals(13, reservoir.size());
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 38 with SpanEvent

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

the class TracerToSpanEventTest method testHappyPath.

@Test
public void testHappyPath() {
    // setup
    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 39 with SpanEvent

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

the class TracerToSpanEventTest method testDistributedTraceIntrinicsAreAdded.

@Test
public void testDistributedTraceIntrinicsAreAdded() {
    Map<String, Object> distributedTraceIntrinsics = Collections.singletonMap("dt-intrinsic", "yuppers");
    when(transactionDataToDistributedTraceIntrinsics.buildDistributedTracingIntrinsics(any(TransactionData.class), anyBoolean())).thenReturn(distributedTraceIntrinsics);
    expectedAgentAttributes.put("dt-intrinsic", "yuppers");
    SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
    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) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 40 with SpanEvent

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

the class DistributedTracingTest method testLateAcceptPayload.

@Test
public void testLateAcceptPayload() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
    try {
        String payload = getAndCreateDistributedTracePayload();
        deepTransaction(payload);
        SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
        String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
        SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(spanEventsPool);
        List<SpanEvent> spanEvents = spanEventsPool.asList();
        assertNotNull(spanEvents);
        assertEquals(6, spanEvents.size());
        spanEventsPool.clear();
        SpanEvent firstSpanEvent = Iterables.getFirst(spanEvents, null);
        assertNotNull(firstSpanEvent);
        String traceId = firstSpanEvent.getTraceId();
        for (SpanEvent event : spanEvents) {
            // Assert that all tracers have the same traceId
            assertEquals(traceId, event.getTraceId());
        }
    } finally {
        holder.close();
    }
}
Also used : SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) 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