use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class SegmentTest method testSpanParenting.
@Test
public void testSpanParenting() {
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
Transaction.clearTransaction();
Tracer rootTracer = makeTransaction();
rootTracer.getTransactionActivity().getTransaction().setPriorityIfNotNull(1.0f);
rootTracer.setMetricName("RootTracer");
Transaction tx = rootTracer.getTransactionActivity().getTransaction();
Segment segment = tx.startSegment("custom", "segment");
final HashMap<String, String> headers = new HashMap<>();
segment.addOutboundRequestHeaders(new OutboundHeaders() {
@Override
public HeaderType getHeaderType() {
return HeaderType.HTTP;
}
@Override
public void setHeader(String name, String value) {
headers.put(name, value);
}
});
String payload = headers.get("newrelic");
segment.end();
rootTracer.finish(Opcodes.ARETURN, null);
Transaction.clearTransaction();
Tracer secondRootTracer = makeTransaction();
secondRootTracer.setMetricName("SecondRootTracer");
Transaction secondTxn = secondRootTracer.getTransactionActivity().getTransaction();
secondTxn.acceptDistributedTracePayload(payload);
secondRootTracer.finish(Opcodes.ARETURN, null);
List<SpanEvent> spanEvents = eventPool.asList();
Assert.assertNotNull(spanEvents);
assertEquals(3, spanEvents.size());
SpanEvent rootTracerSpanEvent = findSpanByName(spanEvents, "RootTracer");
SpanEvent segmentSpanEvent = findSpanByName(spanEvents, "custom/segment");
SpanEvent secondRootTracerSpanEvent = findSpanByName(spanEvents, "SecondRootTracer");
assertEquals(rootTracerSpanEvent.getTraceId(), segmentSpanEvent.getTraceId());
assertEquals(segmentSpanEvent.getTraceId(), secondRootTracerSpanEvent.getTraceId());
assertEquals(rootTracerSpanEvent.getGuid(), segmentSpanEvent.getParentId());
assertEquals(segmentSpanEvent.getGuid(), secondRootTracerSpanEvent.getParentId());
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method testSpanEventDatastoreTruncationAtExactLimit.
@Test
public void testSpanEventDatastoreTruncationAtExactLimit() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 1957);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, 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(2000, spanEvent.getIntrinsics().get("db.statement").toString().length());
// Should not end with ... since it's exactly at the limit
assertTrue(spanEvent.getIntrinsics().get("db.statement").toString().endsWith("aaa"));
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 DefaultSqlTracerTest method testSpanEventDatastoreTruncation.
@Test
public void testSpanEventDatastoreTruncation() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 4000);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, 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(2000, spanEvent.getIntrinsics().get("db.statement").toString().length());
assertTrue(spanEvent.getIntrinsics().get("db.statement").toString().endsWith("a..."));
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 testSpanEvent.
@Test
public void testSpanEvent() {
DefaultTracer tracer = prepareTracer();
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(tracer.getGuid(), spanEvent.getGuid());
assertEquals(tracer.getTransaction().getGuid(), spanEvent.getTransactionId());
assertEquals("Java/class/method", spanEvent.getName());
assertEquals(true, spanEvent.getIntrinsics().get("nr.entryPoint"));
assertEquals((float) tracer.getDurationInMilliseconds() / TimeConversion.MILLISECONDS_PER_SECOND, spanEvent.getDuration(), 0.001f);
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testIntrinsicTransactionAttrsCopiedToSpan.
@Test
public void testIntrinsicTransactionAttrsCopiedToSpan() {
// setup
Map<String, Object> intrinsicAttributes = new HashMap<>();
intrinsicAttributes.put("hot", "sauce");
intrinsicAttributes.put("saucy", "burrito");
expectedAgentAttributes.put("hot", "sauce");
expectedAgentAttributes.put("saucy", "burrito");
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
when(txnData.getIntrinsicAttributes()).thenReturn(intrinsicAttributes);
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);
}
Aggregations