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"));
}
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());
}
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());
}
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);
}
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);
}
Aggregations