use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testMultiTransactionSpanEvents.
@Test
public void testMultiTransactionSpanEvents() {
DistributedTraceServiceImpl dts = (DistributedTraceServiceImpl) ServiceFactory.getServiceManager().getDistributedTraceService();
Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put("cross_application_tracer", ImmutableMap.builder().put("cross_process_id", "12345#whatever").put("trusted_account_key", "67890").build()).build();
dts.connected(null, AgentConfigFactory.createAgentConfig(configMap, null, null));
DefaultTracer firstTracer = prepareTracer();
BoundTransactionApiImpl firstTxn = new BoundTransactionApiImpl(firstTracer.getTransaction());
DistributedTracePayload payload = firstTxn.createDistributedTracePayload();
firstTracer.finish(0, null);
Transaction.clearTransaction();
DefaultTracer secondTracer = prepareTracer();
BoundTransactionApiImpl secondTxn = new BoundTransactionApiImpl(secondTracer.getTransaction());
secondTxn.acceptDistributedTracePayload(payload);
DistributedTracePayload secondPayload = secondTxn.createDistributedTracePayload();
secondTracer.finish(0, null);
Transaction.clearTransaction();
DefaultTracer thirdTracer = prepareTracer();
BoundTransactionApiImpl thirdTxn = new BoundTransactionApiImpl(thirdTracer.getTransaction());
thirdTxn.acceptDistributedTracePayload(secondPayload);
DistributedTracePayload thirdPayload = thirdTxn.createDistributedTracePayload();
thirdTracer.finish(0, null);
Transaction.clearTransaction();
DefaultTracer fourthTracer = prepareTracer();
BoundTransactionApiImpl fourthTxn = new BoundTransactionApiImpl(fourthTracer.getTransaction());
fourthTxn.acceptDistributedTracePayload(thirdPayload);
fourthTracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(firstTracer.getTransaction(), 1024), new TransactionStats());
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(secondTracer.getTransaction(), 1024), new TransactionStats());
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(thirdTracer.getTransaction(), 1024), new TransactionStats());
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(fourthTracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(4, spanEvents.size());
// Make sure traceIds of all span events matches trace id of first payload sent
DistributedTracePayloadImpl parsedPayload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), ServiceFactory.getDistributedTraceService(), Agent.LOG).parse(null, payload.text());
assertNotNull(parsedPayload);
for (SpanEvent event : spanEvents) {
assertEquals("Span events must have same trace id", parsedPayload.traceId, event.getTraceId());
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testParent.
@Test
public void testParent() {
DefaultTracer tracer = prepareTracer();
Tracer child = new DefaultTracer(tracer.getTransaction(), new ClassMethodSignature("com.package.modern.Customer", "child", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
tracer.getTransactionActivity().tracerStarted(child);
Tracer child2 = new DefaultTracer(tracer.getTransaction(), new ClassMethodSignature("com.package.modern.Customer", "child2", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
child.getTransactionActivity().tracerStarted(child2);
child2.reportAsExternal(DatastoreParameters.product("YourSQL").collection("collection").operation("query").instance("databaseServer", 1234).databaseName("dbName").build());
child2.finish(0, null);
child.finish(0, null);
Tracer sibiling = new DefaultTracer(tracer.getTransaction(), new ClassMethodSignature("com.package.modern.Customer", "sibiling", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
tracer.getTransactionActivity().tracerStarted(sibiling);
sibiling.reportAsExternal(HttpParameters.library("library").uri(URI.create("https://myservice:8080/api")).procedure("call").noInboundHeaders().build());
sibiling.finish(0, null);
tracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(4, spanEvents.size());
SpanEvent rootSpan = null;
SpanEvent childSpan = null;
SpanEvent child2Span = null;
SpanEvent siblingSpan = null;
for (SpanEvent spanEvent : spanEvents) {
if (spanEvent.getGuid().equals(tracer.getGuid())) {
rootSpan = spanEvent;
} else if (spanEvent.getGuid().equals(child.getGuid())) {
childSpan = spanEvent;
} else if (spanEvent.getGuid().equals(child2.getGuid())) {
child2Span = spanEvent;
} else if (spanEvent.getGuid().equals(sibiling.getGuid())) {
siblingSpan = spanEvent;
}
}
assertNotNull(rootSpan);
assertNotNull(childSpan);
assertNotNull(child2Span);
assertNotNull(siblingSpan);
assertEquals(tracer.getTransaction().getGuid(), rootSpan.getTransactionId());
assertEquals(tracer.getTransaction().getGuid(), childSpan.getTransactionId());
assertEquals(tracer.getTransaction().getGuid(), child2Span.getTransactionId());
assertEquals(tracer.getTransaction().getGuid(), siblingSpan.getTransactionId());
assertNull(rootSpan.getParentId());
assertEquals(true, rootSpan.getIntrinsics().get("nr.entryPoint"));
assertEquals(rootSpan.getGuid(), childSpan.getParentId());
assertEquals(child.getGuid(), child2Span.getParentId());
assertNull(child2Span.getIntrinsics().get("nr.entryPoint"));
assertEquals(rootSpan.getGuid(), siblingSpan.getParentId());
assertNull(siblingSpan.getIntrinsics().get("nr.entryPoint"));
assertEquals("YourSQL", child2Span.getIntrinsics().get("component"));
assertEquals("databaseServer", child2Span.getIntrinsics().get("peer.hostname"));
assertEquals("dbName", child2Span.getIntrinsics().get("db.instance"));
assertEquals("databaseServer:1234", child2Span.getIntrinsics().get("peer.address"));
assertEquals("client", child2Span.getIntrinsics().get("span.kind"));
assertEquals("library", siblingSpan.getIntrinsics().get("component"));
assertEquals("client", siblingSpan.getIntrinsics().get("span.kind"));
assertEquals("call", siblingSpan.getAgentAttributes().get("http.method"));
assertEquals("https://myservice:8080/api", siblingSpan.getAgentAttributes().get("http.url"));
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class ExternalTracerTest method before.
public void before(String ymlPath) throws Exception {
String configPath = getFullPath(ymlPath);
System.setProperty("newrelic.config.file", configPath);
MockCoreService.getMockAgentAndBootstrapTheServiceManager();
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(appName);
eventPool.clear();
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method testSpanEventDatastore.
@Test
public void testSpanEventDatastore() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
DefaultSqlTracer tracer = newInstanceDBTracer("SELECT price, name FROM BOOKS WHERE price <= 79.99", connection, "MySQL", "mysql");
tracer.finish(Opcodes.ARETURN, new DummyResultSet());
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertEquals("datastore", spanEvent.getIntrinsics().get("category"));
assertEquals("MySQL", spanEvent.getIntrinsics().get("component"));
assertEquals("dbserver.nerd.us", spanEvent.getIntrinsics().get("peer.hostname"));
assertEquals("dbserver.nerd.us:9945", spanEvent.getIntrinsics().get("peer.address"));
assertEquals("SELECT price, name FROM BOOKS WHERE price <= 79.99", spanEvent.getIntrinsics().get("db.statement"));
assertEquals("books", spanEvent.getIntrinsics().get("db.collection"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
assertEquals("Datastore/statement/MySQL/books/select", spanEvent.getName());
assertNotNull(spanEvent.getTraceId());
assertNotNull(spanEvent.getGuid());
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEventDatastore.
@Test
public void testSpanEventDatastore() {
DefaultTracer tracer = prepareTracer();
tracer.reportAsExternal(DatastoreParameters.product("YourSQL").collection("collection").operation("query").instance("databaseServer", 1234).databaseName("dbName").build());
tracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertNull(spanEvent.getParentId());
assertEquals("YourSQL", spanEvent.getIntrinsics().get("component"));
assertEquals("databaseServer", spanEvent.getIntrinsics().get("peer.hostname"));
assertEquals("dbName", spanEvent.getIntrinsics().get("db.instance"));
assertEquals("databaseServer:1234", spanEvent.getIntrinsics().get("peer.address"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
}
Aggregations