Search in sources :

Example 66 with SpanEvent

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

the class SpanEventFactoryTest method shouldSetDataStoreParameters.

@Test
public void shouldSetDataStoreParameters() {
    DatastoreParameters mockParameters = mock(DatastoreParameters.class);
    when(mockParameters.getDatabaseName()).thenReturn("database name");
    SpanEvent target = spanEventFactory.setExternalParameterAttributes(mockParameters).build();
    assertEquals("database name", target.getIntrinsics().get("db.instance"));
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 67 with SpanEvent

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

the class SpanEventsServiceTest method testSpanEvent.

@Test
public void testSpanEvent() {
    TransactionData transactionData = new TransactionDataTestBuilder(APP_NAME, ServiceFactory.getConfigService().getDefaultAgentConfig(), new MockDispatcherTracer()).setTracers(Collections.<Tracer>emptyList()).build();
    Transaction mockTransaction = transactionData.getTransaction();
    when(mockTransaction.sampled()).thenReturn(true);
    when(mockTransaction.getPriority()).thenReturn(1.5f);
    SpanEventsServiceImpl spanEventsService = (SpanEventsServiceImpl) ServiceFactory.getSpanEventService();
    spanEventsService.dispatcherTransactionFinished(transactionData, new TransactionStats());
    SamplingPriorityQueue<SpanEvent> reservoir = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    assertEquals(1, reservoir.getSampled());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 68 with SpanEvent

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

the class SpanEventsServiceTest method before.

@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    serviceManager = new MockServiceManager();
    Map<String, Object> localSettings = new HashMap<>();
    localSettings.put(AgentConfigImpl.APP_NAME, APP_NAME);
    localSettings.put("distributed_tracing", Collections.singletonMap("enabled", true));
    localSettings.put("span_events", Collections.singletonMap("collect_span_events", true));
    when(spanEventCreationDecider.shouldCreateSpans(any(TransactionData.class))).thenReturn(true);
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, localSettings, new HashMap<String, Object>());
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, localSettings);
    serviceManager.setConfigService(configService);
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.setTransactionService(new TransactionService());
    serviceManager.setThreadService(new ThreadService());
    final MockSpanEventReservoirManager reservoirManager = new MockSpanEventReservoirManager(configService);
    Consumer<SpanEvent> backendConsumer = spanEvent -> reservoirManager.getOrCreateReservoir(APP_NAME).add(spanEvent);
    SpanErrorBuilder defaultSpanErrorBuilder = new SpanErrorBuilder(new ErrorAnalyzerImpl(agentConfig.getErrorCollectorConfig()), new ErrorMessageReplacer(agentConfig.getStripExceptionConfig()));
    Map<String, SpanErrorBuilder> map = new HashMap<>();
    map.put(agentConfig.getApplicationName(), defaultSpanErrorBuilder);
    EnvironmentService environmentService = mock(EnvironmentService.class, RETURNS_DEEP_STUBS);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
    when(transactionDataToDistributedTraceIntrinsics.buildDistributedTracingIntrinsics(any(TransactionData.class), anyBoolean())).thenReturn(Collections.<String, Object>emptyMap());
    TracerToSpanEvent tracerToSpanEvent = new TracerToSpanEvent(map, environmentService, transactionDataToDistributedTraceIntrinsics, defaultSpanErrorBuilder);
    SpanEventsServiceImpl spanEventsService = SpanEventsServiceImpl.builder().agentConfig(agentConfig).reservoirManager(reservoirManager).collectorSender(mock(CollectorSpanEventSender.class)).eventBackendStorage(backendConsumer).spanEventCreationDecider(spanEventCreationDecider).tracerToSpanEvent(tracerToSpanEvent).build();
    serviceManager.setSpansEventService(spanEventsService);
    serviceManager.setAttributesService(new AttributesService());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) MockitoAnnotations(org.mockito.MockitoAnnotations) After(org.junit.After) Map(java.util.Map) Before(org.junit.Before) ErrorMessageReplacer(com.newrelic.agent.errors.ErrorMessageReplacer) Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test) SpanEvent(com.newrelic.agent.model.SpanEvent) com.newrelic.agent.config(com.newrelic.agent.config) com.newrelic.agent(com.newrelic.agent) Mockito(org.mockito.Mockito) ErrorAnalyzerImpl(com.newrelic.agent.errors.ErrorAnalyzerImpl) SERVER_SPAN_HARVEST_CONFIG(com.newrelic.agent.config.SpanEventsConfig.SERVER_SPAN_HARVEST_CONFIG) SamplingPriorityQueue(com.newrelic.agent.interfaces.SamplingPriorityQueue) Consumer(com.newrelic.agent.interfaces.backport.Consumer) SpanCategory(com.newrelic.agent.model.SpanCategory) Collections(java.util.Collections) ServiceFactory(com.newrelic.agent.service.ServiceFactory) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) ErrorAnalyzerImpl(com.newrelic.agent.errors.ErrorAnalyzerImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) SpanEvent(com.newrelic.agent.model.SpanEvent) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) ErrorMessageReplacer(com.newrelic.agent.errors.ErrorMessageReplacer) Before(org.junit.Before)

Example 69 with SpanEvent

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

the class TracerToSpanEventTest method testDistributedTraceIntrinicsAreAddedAndFiltered.

@Test
public void testDistributedTraceIntrinicsAreAddedAndFiltered() {
    Map<String, Object> distributedTraceIntrinsics = new HashMap<>();
    distributedTraceIntrinsics.put("dt-intrinsic", "yuppers");
    distributedTraceIntrinsics.put("parentSpanId", "that's a no from me");
    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 : HashMap(java.util.HashMap) SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 70 with SpanEvent

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

the class DistributedSamplingPriorityQueueTest method testPriorityExternalSort.

@Test
public void testPriorityExternalSort() {
    DistributedSamplingPriorityQueue<SpanEvent> eventPool = new DistributedSamplingPriorityQueue<>(10, 0, 0, CUSTOM_COMPARATOR);
    seedEventPool(eventPool);
    List<SpanEvent> spanEvents = eventPool.asList();
    // first, assert using what we get back from "asList()";
    assertPriorityExternalEvents(spanEvents);
    spanEvents = new ArrayList<>();
    SpanEvent event;
    while ((event = eventPool.poll()) != null) {
        spanEvents.add(event);
    }
    // second, assert using what we get back from "poll()";
    assertPriorityExternalEvents(spanEvents);
}
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