use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class RandomTransactionSampler method harvest.
@Override
public List<TransactionTrace> harvest(String appName) {
TransactionData td = expensiveTransaction.get();
if (td == FINISHED) {
return Collections.emptyList();
}
if (td == null) {
return Collections.emptyList();
}
if (td.getApplicationName() != appName) {
return Collections.emptyList();
}
if (shouldFinish()) {
td = expensiveTransaction.getAndSet(FINISHED);
stop();
} else {
td = expensiveTransaction.getAndSet(null);
}
tracesSent++;
return getTransactionTrace(td);
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionTraceSampler method noticeTransaction.
@Override
public boolean noticeTransaction(TransactionData td) {
if (!exceedsThreshold(td)) {
return false;
}
TransactionData maxTrace = expensiveTransaction.get();
if (maxTrace != null && getScore(maxTrace) >= getScore(td)) {
return false;
}
readLock.lock();
try {
return noticeTransactionUnderLock(td);
} finally {
readLock.unlock();
}
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionTraceSampler method noticeTransactionUnderLock.
private boolean noticeTransactionUnderLock(TransactionData td) {
Long lastScore = tracedTransactions.get(td.getBlameMetricName());
if (lastScore != null && getScore(td) <= lastScore) {
return false;
}
while (true) {
TransactionData current = expensiveTransaction.get();
if (current != null && getScore(current) >= getScore(td)) {
return false;
}
if (expensiveTransaction.compareAndSet(current, td)) {
if (Agent.LOG.isLoggable(Level.FINER)) {
String msg = MessageFormat.format("Captured expensive transaction trace for {0} {1}", td.getApplicationName(), td);
Agent.LOG.finer(msg);
}
return true;
}
}
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionTraceSampler method harvest.
@Override
public List<TransactionTrace> harvest(String appName) {
TransactionData td = null;
writeLock.lock();
try {
td = harvestUnderLock(appName);
} finally {
writeLock.unlock();
}
if (td == null) {
return Collections.emptyList();
}
if (Agent.LOG.isLoggable(Level.FINER)) {
String msg = MessageFormat.format("Sending transaction trace for {0} {1}", td.getApplicationName(), td);
Agent.LOG.finer(msg);
}
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
List<TransactionTrace> traces = new ArrayList<>(1);
traces.add(trace);
return traces;
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionTraceServiceTest method transactionSamplers.
@Test
public void transactionSamplers() throws Exception {
Map<String, Object> configMap = createConfigMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
createServiceManager(configMap);
TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
ITransactionSampler transactionSampler = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
tds.add(td);
return true;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
ITransactionSampler transactionSampler2 = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
tds.add(td);
return true;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
ttService.addTransactionTraceSampler(transactionSampler);
ttService.addTransactionTraceSampler(transactionSampler2);
TransactionData td = createTransactionData("/en/betting/Baseball/*", APP_NAME, 100L);
ttService.dispatcherTransactionFinished(td, null);
ttService.afterHarvest(APP_NAME);
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService(APP_NAME);
List<TransactionTrace> traces = rpmService.getTraces();
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/en/betting/Baseball/*", traces.get(0).getRequestUri());
Assert.assertEquals(100L, traces.get(0).getDuration());
traces.clear();
traces = rpmService.getTraces();
Assert.assertEquals(0, traces.size());
ttService.removeTransactionTraceSampler(transactionSampler);
ttService.removeTransactionTraceSampler(transactionSampler2);
ttService.dispatcherTransactionFinished(td, null);
ttService.afterHarvest(APP_NAME);
Assert.assertEquals(0, transactionSampler.harvest(APP_NAME).size());
Assert.assertEquals(0, transactionSampler2.harvest(APP_NAME).size());
}
Aggregations