Skip to content

Commit 24dcc36

Browse files
committed
Correct Apdex on transaction event if an error is present
1 parent 0704419 commit 24dcc36

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

newrelic-agent/src/main/java/com/newrelic/agent/TransactionData.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.newrelic.agent.attributes.AttributesService;
1111
import com.newrelic.api.agent.Logs;
12+
import com.newrelic.api.agent.NewRelic;
1213
import com.newrelic.api.agent.TransportType;
1314
import com.newrelic.agent.config.AgentConfig;
1415
import com.newrelic.agent.config.AgentConfigImpl;
@@ -31,6 +32,7 @@
3132
import java.util.Collection;
3233
import java.util.Map;
3334
import java.util.Set;
35+
import java.util.logging.Level;
3436

3537
public class TransactionData {
3638
private final Transaction tx;
@@ -166,6 +168,10 @@ public boolean hasReportableErrorThatIsNotIgnored() {
166168
return tx.isErrorReportableAndNotIgnored();
167169
}
168170

171+
public boolean hasErrorThatIsNotExpected() {
172+
return tx.isErrorNotExpected();
173+
}
174+
169175
/**
170176
* A rough approximation of the transaction size (how much memory we are using with our tracers)
171177
*/
@@ -257,11 +263,20 @@ public ApdexPerfZone getApdexPerfZone() {
257263
if (!isWebTransaction() && !tx.getAgentConfig().isApdexTSet(getPriorityTransactionName().getName())) {
258264
return null;
259265
}
266+
267+
if (isApdexFrustrating()) {
268+
return ApdexPerfZone.FRUSTRATING;
269+
}
270+
260271
long responseTimeInMillis = tx.getTransactionTimer().getResponseTimeInMilliseconds() + tx.getExternalTime();
261272
long apdexTInMillis = tx.getAgentConfig().getApdexTInMillis(getPriorityTransactionName().getName());
262273
return ApdexPerfZoneDetermination.getZone(responseTimeInMillis, apdexTInMillis);
263274
}
264275

276+
public boolean isApdexFrustrating() {
277+
return hasReportableErrorThatIsNotIgnored() && hasErrorThatIsNotExpected();
278+
}
279+
265280
public String parentType() {
266281
if (!receivedInboundDistributedPayload()) {
267282
return null;

newrelic-agent/src/test/java/com/newrelic/agent/TransactionDataTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.newrelic.agent.config.AgentConfigImpl;
1414
import com.newrelic.agent.config.TransactionTracerConfig;
1515
import com.newrelic.agent.dispatchers.Dispatcher;
16+
import com.newrelic.agent.model.ApdexPerfZone;
1617
import com.newrelic.agent.service.ServiceFactory;
1718
import com.newrelic.agent.sql.SlowQueryListener;
1819
import com.newrelic.agent.tracers.Tracer;
@@ -327,4 +328,21 @@ public void toString2() {
327328
Assert.assertEquals(MessageFormat.format(" {0}ms {1}", String.valueOf(expected), ex), result);
328329
}
329330

331+
@Test
332+
public void isApdexFrustrating_returnsTrue_whenErrorIsPresent() {
333+
Mockito.when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
334+
Mockito.when(tx.isErrorNotExpected()).thenReturn(true);
335+
336+
TransactionData txd = getTxData(tx);
337+
Assert.assertTrue(txd.isApdexFrustrating());
338+
}
339+
340+
@Test
341+
public void isApdexFrustrating_returnsFalse_whenNoErrorIsPresent() {
342+
Mockito.when(tx.isErrorReportableAndNotIgnored()).thenReturn(false);
343+
Mockito.when(tx.isErrorNotExpected()).thenReturn(false);
344+
345+
TransactionData txd = getTxData(tx);
346+
Assert.assertFalse(txd.isApdexFrustrating());
347+
}
330348
}

0 commit comments

Comments
 (0)