use of com.newrelic.agent.service.analytics.SpanEventsServiceImpl 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.service.analytics.SpanEventsServiceImpl 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.service.analytics.SpanEventsServiceImpl 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"));
}
use of com.newrelic.agent.service.analytics.SpanEventsServiceImpl in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanParentingEvent.
@Test
public void testSpanParentingEvent() {
DefaultTracer tracer = prepareTracer();
tracer.finish(0, null);
SpanProxy spanProxy = tracer.getTransaction().getSpanProxy();
W3CTraceParentHeader.create(spanProxy, "12341234123412341234123412341234", "0101010101010101", false);
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);
Assert.assertNotEquals("0101010101010101", spanEvent.getParentId());
}
Aggregations