use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class SpanEventsServiceFactory method build.
public SpanEventsService build() {
ReservoirManager.EventSender<SpanEvent> collectorSpanEventSender = new CollectorSpanEventSender(rpmServiceManager);
AgentConfig agentConfig = configService.getDefaultAgentConfig();
Consumer<SpanEvent> eventStorageBackend = buildStorageBackendConsumer(reservoirManager);
SpanErrorBuilder defaultSpanErrorBuilder = buildDefaultSpanErrorBuilder(agentConfig);
Map<String, SpanErrorBuilder> errorBuilderForApp = buildSpanEventErrorBuilder(agentConfig, defaultSpanErrorBuilder);
configureUpdateOnConfigChange(errorBuilderForApp);
TracerToSpanEvent tracerToSpanEvent = new TracerToSpanEvent(errorBuilderForApp, environmentService, transactionDataToDistributedTraceIntrinsics, defaultSpanErrorBuilder);
SpanEventsServiceImpl result = SpanEventsServiceImpl.builder().agentConfig(agentConfig).reservoirManager(reservoirManager).collectorSender(collectorSpanEventSender).eventBackendStorage(eventStorageBackend).spanEventCreationDecider(spanEventCreationDecider).tracerToSpanEvent(tracerToSpanEvent).build();
configService.addIAgentConfigListener(result);
transactionService.addTransactionListener(result);
return result;
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DataCollectionConfigCrossAgentTest method createAndVerifySpanEvents.
private void createAndVerifySpanEvents(Long expectedCount, Long expectedEndpointCount) {
SpanEventsService spanEventsService = setUpSpanEventsService();
long eventsToCreate = 1;
if (expectedCount > 1) {
eventsToCreate = expectedCount;
}
for (long i = 0; i < eventsToCreate; i++) {
spanEventsService.storeEvent(new SpanEventFactory(APP_NAME).setName("Span").build());
}
// Verify that the correct number of events were stored in the reservoir
SamplingPriorityQueue<SpanEvent> eventQueue = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
assertNotNull(eventQueue);
assertEquals(expectedCount.intValue(), eventQueue.size());
// Verify that we sent (or didn't send) the appropriate events
spanEventsService.harvestEvents(APP_NAME);
int spanEventsSeen = ((MockRPMService) serviceManager.getRPMServiceManager().getRPMService(APP_NAME)).getSpanEventsSeen();
assertEquals(expectedEndpointCount.intValue(), spanEventsSeen);
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DistributedTraceCrossAgentTest method runTest.
@Test
public void runTest() throws ParseException, IOException {
String accountKey = (String) jsonTest.get("trusted_account_key");
String accountId = (String) jsonTest.get("account_id");
String transportType = (String) jsonTest.get("transport_type");
Boolean webTransaction = (Boolean) jsonTest.get("web_transaction");
Boolean raisesException = (Boolean) jsonTest.get("raises_exception");
Boolean forceSampledTrue = (Boolean) jsonTest.get("force_sampled_true");
Long majorVersion = (Long) jsonTest.get("major_version");
Long minorVersion = (Long) jsonTest.get("minor_version");
Boolean spanEventsEnabled = (Boolean) jsonTest.get("span_events_enabled");
replaceConfig(spanEventsEnabled);
Assert.assertEquals(majorVersion.intValue(), ServiceFactory.getDistributedTraceService().getMajorSupportedCatVersion());
Assert.assertEquals(minorVersion.intValue(), ServiceFactory.getDistributedTraceService().getMinorSupportedCatVersion());
JSONArray outbound_payloads = (JSONArray) jsonTest.get("outbound_payloads");
JSONArray inbound_payloads = (JSONArray) jsonTest.get("inbound_payloads");
ArrayList expectedMetrics = (ArrayList) jsonTest.get("expected_metrics");
Map<String, Object> intrinsics = (Map<String, Object>) jsonTest.get("intrinsics");
Map<String, Object> commonAssertions = (Map<String, Object>) intrinsics.get("common");
ArrayList targetEvents = (ArrayList) intrinsics.get("target_events");
Map<String, Object> transactionAssertions = (Map<String, Object>) intrinsics.get("Transaction");
Map<String, Object> spanAssertions = (Map<String, Object>) intrinsics.get("Span");
Map<String, Object> connectInfo = new HashMap<>();
connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, accountId);
connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, accountKey);
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
distributedTraceService.connected(null, agentConfig);
Transaction.clearTransaction();
TransactionActivity.clear();
spanEventsService.clearReservoir();
Transaction tx = Transaction.getTransaction();
TransactionData transactionData = new TransactionData(tx, 0);
TransactionStats transactionStats = transactionData.getTransaction().getTransactionActivity().getTransactionStats();
SamplingPriorityQueue<SpanEvent> eventPool = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
Tracer rootTracer;
if (webTransaction) {
rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "WebTransaction");
} else {
rootTracer = TransactionAsyncUtility.createOtherTracer("OtherTransaction");
}
tx.getTransactionActivity().tracerStarted(rootTracer);
if (raisesException) {
tx.setThrowable(new Throwable(), TransactionErrorPriority.API, false);
}
setTransportType(tx, transportType);
if (inbound_payloads != null) {
for (Object payload : inbound_payloads) {
tx.acceptDistributedTracePayload(payload.toString());
}
} else {
tx.acceptDistributedTracePayload((String) null);
}
if (forceSampledTrue) {
tx.setPriorityIfNotNull(new Random().nextFloat() + 1.0f);
}
if (outbound_payloads != null) {
for (Object assertion : outbound_payloads) {
JSONObject payloadAssertions = (JSONObject) assertion;
DistributedTracePayload payload = new BoundTransactionApiImpl(tx).createDistributedTracePayload();
assertOutboundPayload(payloadAssertions, payload);
}
}
rootTracer.finish(Opcodes.RETURN, 0);
distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
((SpanEventsServiceImpl) spanEventsService).dispatcherTransactionFinished(transactionData, transactionStats);
List<SpanEvent> spans = eventPool.asList();
TransactionEvent transactionEvent = ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, "wat");
JSONObject txnEvents = serializeAndParseEvents(transactionEvent);
assertExpectedMetrics(expectedMetrics, transactionStats);
for (Object event : targetEvents) {
if (event.toString().startsWith("Transaction") && transactionAssertions != null) {
assertTransactionEvents(transactionAssertions, txnEvents);
assertTransactionEvents(commonAssertions, txnEvents);
} else if (event.toString().startsWith("Span") && spanAssertions != null) {
assertNotEquals("Expected some spans!", 0, spans.size());
assertSpanEvents(spanAssertions, spans);
assertSpanEvents(commonAssertions, spans);
}
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DistributedTracingTest method testCrossApplicationTracingDisabled.
@Test
public void testCrossApplicationTracingDisabled() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("cross_application_disabled_test");
TransactionService transactionService = ServiceFactory.getTransactionService();
final CountDownLatch latch = new CountDownLatch(1);
TransactionStatsListener listener = new TransactionStatsListener() {
@Override
public void dispatcherTransactionStatsFinished(TransactionData transactionData, TransactionStats transactionStats) {
// Use this to ensure that the transaction fully finished and that it
// didn't bail out early (transaction stats listeners are fired at the end of tx processing)
latch.countDown();
}
};
try {
transactionService.addTransactionStatsListener(listener);
noCreateOrAcceptPayload();
// Wait up to 30 seconds for the transaction to finish, if it doesn't then it means we encountered an issue and it never finished
latch.await(30, TimeUnit.SECONDS);
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(1, 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());
}
TransactionDataList transactionList = holder.getTransactionList();
assertNotNull(transactionList);
assertEquals(1, transactionList.size());
} finally {
transactionService.removeTransactionStatsListener(listener);
holder.close();
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class RootSpanStatusErrorsTest method assertRootSpanAttributes.
private void assertRootSpanAttributes(Integer expectedStatus, String errorClass) {
SamplingPriorityQueue<SpanEvent> reservoir = ServiceFactory.getSpanEventService().getOrCreateDistributedSamplingReservoir(APP_NAME);
assertTrue(reservoir.asList().size() > 0);
List<String> seenNames = new LinkedList<>();
for (SpanEvent event : reservoir.asList()) {
if (!event.getName().startsWith("Java/")) {
seenNames.add(event.getName());
continue;
}
assertEquals("wrong error.status attribute", expectedStatus, event.getAgentAttributes().get("error.status"));
assertEquals("wrong error.class attribute", errorClass, event.getAgentAttributes().get("error.class"));
return;
}
assertEquals("Did not find root span!", Collections.emptyList(), seenNames);
}
Aggregations