use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method attributesDisabledWithIntrinsics.
@SuppressWarnings("unchecked")
@Test
public void attributesDisabledWithIntrinsics() throws Exception {
Map<String, Object> config = createConfig("java.lang.Exception");
setConfigAttributes(config, false, true);
EventTestHelper.createServiceManager(config);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
rpmService.setIsConnected(true);
TransactionService txService = ServiceFactory.getTransactionService();
Throwable error = new ArrayIndexOutOfBoundsException();
Map<String, String> requestParams = new HashMap<>();
requestParams.put("key1", "value1");
Map<String, Object> agentParams = new HashMap<>();
agentParams.put("key2", 2L);
Map<String, Object> userParams = new HashMap<>();
userParams.put("key3", "value3");
Map<String, Object> errorParams = new HashMap<>();
errorParams.put("key4", "value4");
Map<String, Object> intrinsics = new HashMap<>();
intrinsics.put("key5", "value5");
TransactionData data = createTransactionData(true, 0, error, false, requestParams, userParams, agentParams, errorParams, intrinsics);
TransactionStats transactionStats = new TransactionStats();
txService.transactionFinished(data, transactionStats);
List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, new StatsEngineImpl());
Assert.assertEquals(1, actualErrors.size());
JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(actualErrors.get(0));
Assert.assertNotNull(serializedError);
Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
Assert.assertEquals(2, params.size());
Assert.assertNotNull(params.get("stack_trace"));
Assert.assertNotNull(params.get("intrinsics"));
Map<String, Object> actual = (Map<String, Object>) params.get("intrinsics");
Assert.assertEquals(6, actual.size());
Assert.assertEquals("value5", actual.get("key5"));
Assert.assertEquals(false, actual.get("error.expected"));
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class WebRequestDispatcherTest method initializeTest.
private void initializeTest(boolean isHighSecurity) throws Exception {
List<Map<String, String>> requestHeaderList = ImmutableList.<Map<String, String>>builder().add(makeHeaderMap(HEADER_WITH_ALIAS, HEADER_ALIAS)).add(makeHeaderMap(HEADER_WITHOUT_ALIAS, null)).add(makeHeaderMap(UNUSED_HEADER, null)).build();
Map<String, Object> headerConfigs = new HashMap<>();
headerConfigs.put(TransactionEventsConfig.CUSTOM_REQUEST_HEADERS, requestHeaderList);
Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put(AgentConfigImpl.TRANSACTION_EVENTS, headerConfigs).put(AgentConfigImpl.APP_NAME, APP_NAME).put(AgentConfigImpl.HIGH_SECURITY, isHighSecurity).build();
createServiceManager(AgentConfigImpl.createAgentConfig(configMap), configMap);
Transaction.clearTransaction();
stats = new TransactionStats();
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testTransactionABParenting.
/**
* Transaction A has spans 1, 2, and 3. Span 2 is active when a distributed tracing payload is created.
* Transaction B has spans 5 and 6. The payload from span 2 is accepted when span 5 is active.
*
* Verify that all the parenting attributes are correct.
*/
@Test
public void testTransactionABParenting() {
DistributedTraceServiceImpl dts = (DistributedTraceServiceImpl) ServiceFactory.getServiceManager().getDistributedTraceService();
Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put("distributed_tracing", ImmutableMap.builder().put("account_id", "12345").put("trusted_account_key", "67890").put("primary_application_id", "789").build()).build();
dts.connected(null, AgentConfigFactory.createAgentConfig(configMap, null, null));
TransactionActivity.clear();
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
DefaultTracer span1Tracer = new OtherRootTracer(tx, new ClassMethodSignature("class", "span1", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
tx.getTransactionActivity().tracerStarted(span1Tracer);
tx.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, true, "Transaction A");
DefaultTracer span2Tracer = new OtherRootTracer(tx, new ClassMethodSignature("class", "span2", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
tx.getTransactionActivity().tracerStarted(span2Tracer);
DistributedTracePayload payload = new BoundTransactionApiImpl(span2Tracer.getTransaction()).createDistributedTracePayload();
DefaultTracer span3Tracer = new OtherRootTracer(tx, new ClassMethodSignature("class", "span3", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
tx.getTransactionActivity().tracerStarted(span3Tracer);
span3Tracer.finish(Opcodes.ARETURN, null);
span2Tracer.finish(Opcodes.ARETURN, null);
span1Tracer.finish(Opcodes.ARETURN, null);
TransactionActivity.clear();
Transaction.clearTransaction();
Transaction txB = Transaction.getTransaction();
DefaultTracer span5Tracer = new OtherRootTracer(txB, new ClassMethodSignature("class", "span5", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
txB.getTransactionActivity().tracerStarted(span5Tracer);
span5Tracer.getTransaction().acceptDistributedTracePayload(payload);
txB.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, true, "Transaction B");
txB.setThrowable(new Throwable(), TransactionErrorPriority.API, false);
DefaultTracer span6Tracer = new OtherRootTracer(txB, new ClassMethodSignature("class", "span6", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
txB.getTransactionActivity().tracerStarted(span6Tracer);
span6Tracer.finish(Opcodes.ARETURN, null);
span5Tracer.finish(Opcodes.ARETURN, null);
// assert traceId
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
final TransactionData tdA = new TransactionData(tx, 1024);
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(tdA, new TransactionStats());
final TransactionData tdB = new TransactionData(txB, 1024);
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(tdB, new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertEquals(5, spanEvents.size());
TransactionEvent txAEvent = ServiceFactory.getTransactionEventsService().createEvent(tdA, new TransactionStats(), tdA.getBlameMetricName());
TransactionEvent txBEvent = ServiceFactory.getTransactionEventsService().createEvent(tdB, new TransactionStats(), tdB.getBlameMetricName());
SpanEvent span1 = getSpanByName(eventPool, "Java/class/span1");
SpanEvent span2 = getSpanByName(eventPool, "Java/class/span2");
SpanEvent span3 = getSpanByName(eventPool, "Java/class/span3");
SpanEvent span5 = getSpanByName(eventPool, "Java/class/span5");
SpanEvent span6 = getSpanByName(eventPool, "Java/class/span6");
DistributedTracePayloadImpl parsedPayload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), ServiceFactory.getDistributedTraceService(), Agent.LOG).parse(null, payload.text());
assertEquals(tx.getGuid(), parsedPayload.txnId);
assertEquals(tx.sampled(), parsedPayload.sampled.booleanValue());
assertEquals(tx.getPriority(), parsedPayload.priority, 0.0f);
assertEquals(span2Tracer.getGuid(), parsedPayload.guid);
assertEquals(span2.getGuid(), parsedPayload.guid);
assertEquals(txAEvent.getTripId(), parsedPayload.traceId);
assertEquals(txBEvent.getTripId(), parsedPayload.traceId);
assertEquals(span1.getTraceId(), span2.getTraceId());
assertEquals(span2.getTraceId(), span3.getTraceId());
assertEquals(span3.getTraceId(), span5.getTraceId());
assertEquals(span5.getTraceId(), span6.getTraceId());
assertEquals(txAEvent.getGuid(), span1.getTransactionId());
assertEquals(span1.getGuid(), span2.getParentId());
assertEquals(txAEvent.getGuid(), span2.getTransactionId());
assertEquals(span2.getGuid(), span3.getParentId());
assertEquals(txAEvent.getGuid(), span3.getTransactionId());
assertEquals(txAEvent.getGuid(), txBEvent.getParentId());
assertEquals(span2.getGuid(), txBEvent.getParenSpanId());
assertEquals(span2.getGuid(), span5.getParentId());
assertEquals(txBEvent.getGuid(), span5.getTransactionId());
assertEquals(span5.getGuid(), span6.getParentId());
assertEquals(txBEvent.getGuid(), span6.getTransactionId());
ServiceFactory.getTransactionService().transactionFinished(tdB, new TransactionStats());
ErrorServiceImpl errorService = (ErrorServiceImpl) txB.getRPMService().getErrorService();
DistributedSamplingPriorityQueue<ErrorEvent> reservoir = errorService.getReservoir(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName());
List<ErrorEvent> errorEvents = reservoir.asList();
assertEquals(1, errorEvents.size());
ErrorEvent errorEvent = errorEvents.get(0);
Map<String, Object> errorDtAtts = errorEvent.getDistributedTraceIntrinsics();
assertEquals(txBEvent.getTripId(), errorDtAtts.get("traceId"));
assertEquals(txBEvent.getGuid(), errorEvent.getTransactionGuid());
}
use of com.newrelic.agent.stats.TransactionStats 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.stats.TransactionStats 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"));
}
Aggregations