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