Skip to content

Commit

Permalink
Merge pull request #2191 from newrelic/txndata-apdex-fix
Browse files Browse the repository at this point in the history
Correct Apdex on transaction event if an error is present
  • Loading branch information
jtduffy authored Jan 6, 2025
2 parents 0704419 + 24dcc36 commit 13ad7f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.newrelic.agent.attributes.AttributesService;
import com.newrelic.api.agent.Logs;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TransportType;
import com.newrelic.agent.config.AgentConfig;
import com.newrelic.agent.config.AgentConfigImpl;
Expand All @@ -31,6 +32,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

public class TransactionData {
private final Transaction tx;
Expand Down Expand Up @@ -166,6 +168,10 @@ public boolean hasReportableErrorThatIsNotIgnored() {
return tx.isErrorReportableAndNotIgnored();
}

public boolean hasErrorThatIsNotExpected() {
return tx.isErrorNotExpected();
}

/**
* A rough approximation of the transaction size (how much memory we are using with our tracers)
*/
Expand Down Expand Up @@ -257,11 +263,20 @@ public ApdexPerfZone getApdexPerfZone() {
if (!isWebTransaction() && !tx.getAgentConfig().isApdexTSet(getPriorityTransactionName().getName())) {
return null;
}

if (isApdexFrustrating()) {
return ApdexPerfZone.FRUSTRATING;
}

long responseTimeInMillis = tx.getTransactionTimer().getResponseTimeInMilliseconds() + tx.getExternalTime();
long apdexTInMillis = tx.getAgentConfig().getApdexTInMillis(getPriorityTransactionName().getName());
return ApdexPerfZoneDetermination.getZone(responseTimeInMillis, apdexTInMillis);
}

public boolean isApdexFrustrating() {
return hasReportableErrorThatIsNotIgnored() && hasErrorThatIsNotExpected();
}

public String parentType() {
if (!receivedInboundDistributedPayload()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.newrelic.agent.config.AgentConfigImpl;
import com.newrelic.agent.config.TransactionTracerConfig;
import com.newrelic.agent.dispatchers.Dispatcher;
import com.newrelic.agent.model.ApdexPerfZone;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.agent.sql.SlowQueryListener;
import com.newrelic.agent.tracers.Tracer;
Expand Down Expand Up @@ -327,4 +328,21 @@ public void toString2() {
Assert.assertEquals(MessageFormat.format(" {0}ms {1}", String.valueOf(expected), ex), result);
}

@Test
public void isApdexFrustrating_returnsTrue_whenErrorIsPresent() {
Mockito.when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
Mockito.when(tx.isErrorNotExpected()).thenReturn(true);

TransactionData txd = getTxData(tx);
Assert.assertTrue(txd.isApdexFrustrating());
}

@Test
public void isApdexFrustrating_returnsFalse_whenNoErrorIsPresent() {
Mockito.when(tx.isErrorReportableAndNotIgnored()).thenReturn(false);
Mockito.when(tx.isErrorNotExpected()).thenReturn(false);

TransactionData txd = getTxData(tx);
Assert.assertFalse(txd.isApdexFrustrating());
}
}

0 comments on commit 13ad7f1

Please sign in to comment.