Skip to content

Commit

Permalink
Gate new logging with level checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jtduffy committed Oct 16, 2023
1 parent c44bdd3 commit aa2a763
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ private static boolean setTxNameUsingServletName(ServletConfig servletConfig, Se
return false;
}
txName = normalizeServletName(txName, servlet);
NewRelic.getAgent().getLogger().log(Level.FINEST, "Servlet24/ServletHelper::setTxNameUsingServletName: calling transaction.setTransactionName with " +
"priority: SERVLET_NAME and override false, category: Servlet, txn {0}, ",
AgentBridge.getAgent().getTransaction().toString());

if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
NewRelic.getAgent().getLogger().log(Level.FINEST, "Servlet24/ServletHelper::setTxNameUsingServletName: calling transaction.setTransactionName with " +
"priority: SERVLET_NAME and override false, category: Servlet, txn {0}, ",
AgentBridge.getAgent().getTransaction().toString());
}

AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, NO_OVERRIDE,
SERVLET_NAME_CATEGORY, txName);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,15 @@ private static boolean setTxNameUsingServletName(ServletConfig servletConfig, Se
return false;
}
txName = normalizeServletName(txName, servlet);
NewRelic.getAgent().getLogger().log(Level.FINEST, "Servlet5/ServletHelper::setTxNameUsingServletName: calling transaction.setTransactionName with " +
"priority: SERVLET_NAME and override false, category: Servlet, txn {0}, ",
AgentBridge.getAgent().getTransaction().toString());

if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
NewRelic.getAgent()
.getLogger()
.log(Level.FINEST, "Servlet5/ServletHelper::setTxNameUsingServletName: calling transaction.setTransactionName with " +
"priority: SERVLET_NAME and override false, category: Servlet, txn {0}, ",
AgentBridge.getAgent().getTransaction().toString());
}

AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, NO_OVERRIDE,
SERVLET_NAME_CATEGORY, txName);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ private static boolean setTxNameUsingServletName(ServletConfig servletConfig, Se
return false;
}
txName = normalizeServletName(txName, servlet);
NewRelic.getAgent().getLogger().log(Level.FINEST, "Servlet6/ServletHelper::setTxNameUsingServletName: calling transaction.setTransactionName with " +
"priority: SERVLET_NAME and override false, category: Servlet, txn {0}, ",
AgentBridge.getAgent().getTransaction().toString());

if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
NewRelic.getAgent()
.getLogger()
.log(Level.FINEST, "Servlet6/ServletHelper::setTxNameUsingServletName: calling transaction.setTransactionName with " +
"priority: SERVLET_NAME and override false, category: Servlet, txn {0}, ",
AgentBridge.getAgent().getTransaction().toString());
}

AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, NO_OVERRIDE,
SERVLET_NAME_CATEGORY, txName);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ public static void processAnnotations(Transaction transaction, RequestMethod[] m
AgentBridge.getAgent().getLogger().log(Level.FINE, "No path was specified for SpringController {0}", matchedAnnotationClass.getName());
} else {
String fullPath = SpringControllerUtility.getPath(rootPath, methodPath, httpMethod);
NewRelic.getAgent().getLogger().log(Level.FINEST, "SpringControllerUtility::processAnnotations (4.3.0): calling transaction.setTransactionName to [{0}] " +
"with FRAMEWORK_HIGH and override true, txn {1}, ",
AgentBridge.getAgent().getTransaction().toString());
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
NewRelic.getAgent()
.getLogger()
.log(Level.FINEST, "SpringControllerUtility::processAnnotations (4.3.0): calling transaction.setTransactionName to [{0}] " +
"with FRAMEWORK_HIGH and override true, txn {1}, ",
AgentBridge.getAgent().getTransaction().toString());
}
transaction.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "SpringController",
fullPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,11 @@ public boolean conditionalSetPriorityTransactionName(TransactionNamingPolicy pol
synchronized (lock) {
MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SET_TRANSACTION_NAME);

Agent.LOG.log(Level.FINEST, "newrelic.agent.Transaction::conditionalSetPriorityTransactionName: Attempting to set txn name: " +
"TxnNamingPolicy: {0}, name: {1}, category: {2}, TxnNamePriority {3}",
policy.toString(), name, category, priority.toString());
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "newrelic.agent.Transaction::conditionalSetPriorityTransactionName: Attempting to set txn name: " +
"TxnNamingPolicy: {0}, name: {1}, category: {2}, TxnNamePriority {3}",
policy.toString(), name, category, priority.toString());
}

if (policy.canSetTransactionName(this, priority)) {
if (Agent.LOG.isFinestEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ public boolean registerAsyncActivity(Object asyncContext) {
public boolean setTransactionName(TransactionNamePriority namePriority, boolean override, String category,
String... parts) {
Transaction tx = getTransactionIfExists();
Agent.LOG.log(Level.FINEST, "newrelic.agent.TransactionApiImpl::setTransactionName (1) - txn: {0}, override: {1}, category: {2}, parts: {3}",
(tx != null ? tx.toString() : "N/A"), override, category, String.join("/", parts));
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "newrelic.agent.TransactionApiImpl::setTransactionName (1) - txn: {0}, override: {1}, category: {2}, parts: {3}",
(tx != null ? tx.toString() : "N/A"), override, category, String.join("/", parts));
}
return (tx != null) ? tx.setTransactionName(namePriority, override, category, parts) : false;
}

Expand Down Expand Up @@ -162,8 +164,10 @@ public void ignoreErrors() {
public boolean setTransactionName(com.newrelic.agent.bridge.TransactionNamePriority namePriority, boolean override,
String category, String... parts) {
Transaction tx = getTransactionIfExists();
Agent.LOG.log(Level.FINEST, "newrelic.agent.TransactionApiImpl::setTransactionName (2) - txn: {0}, override: {1}, category: {2}, parts: {3}",
(tx != null ? tx.toString() : "N/A"), override, category, String.join("/", parts));
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "newrelic.agent.TransactionApiImpl::setTransactionName (2) - txn: {0}, override: {1}, category: {2}, parts: {3}",
(tx != null ? tx.toString() : "N/A"), override, category, String.join("/", parts));
}
return (tx != null) ? tx.setTransactionName(namePriority, override, category, parts) : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.newrelic.agent.Agent;
import com.newrelic.agent.Transaction;
import com.newrelic.agent.bridge.TransactionNamePriority;
import com.newrelic.api.agent.NewRelic;

import java.util.logging.Level;

Expand All @@ -24,9 +25,11 @@ public boolean canSetTransactionName(Transaction tx, TransactionNamePriority pri
return false;
}

Agent.LOG.log(Level.FINEST, "agent.transaction.HigherPriorityTransactionNamingPolicy::canSetTransactionName: " +
"txn: {0}, txnPriorityTxnName: {1}, txnNamingScheme: {2}, priority: {3}",
tx.toString(), tx.getPriorityTransactionName().toString(), tx.getNamingScheme().toString(), priority.toString());
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "agent.transaction.HigherPriorityTransactionNamingPolicy::canSetTransactionName: " +
"txn: {0}, txnPriorityTxnName: {1}, txnNamingScheme: {2}, priority: {3}",
tx.toString(), tx.getPriorityTransactionName().toString(), tx.getNamingScheme().toString(), priority.toString());
}

PriorityTransactionName ptn = tx.getPriorityTransactionName();
return TransactionNamingUtility.comparePriority(priority, ptn.getPriority(), tx.getNamingScheme()) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.newrelic.agent.Agent;
import com.newrelic.agent.Transaction;
import com.newrelic.agent.bridge.TransactionNamePriority;
import com.newrelic.api.agent.NewRelic;

import java.util.logging.Level;

Expand All @@ -24,9 +25,11 @@ public boolean canSetTransactionName(Transaction tx, TransactionNamePriority pri
return false;
}

Agent.LOG.log(Level.FINEST, "agent.transaction.SameOrHigherPriorityTransactionNamingPolicy::canSetTransactionName: " +
"txn: {0}, txnPriorityTxnName: {1}, txnNamingScheme: {2}, priority: {3}",
tx.toString(), tx.getPriorityTransactionName().toString(), tx.getNamingScheme().toString(), priority.toString());
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "agent.transaction.SameOrHigherPriorityTransactionNamingPolicy::canSetTransactionName: " +
"txn: {0}, txnPriorityTxnName: {1}, txnNamingScheme: {2}, priority: {3}",
tx.toString(), tx.getPriorityTransactionName().toString(), tx.getNamingScheme().toString(), priority.toString());
}

PriorityTransactionName ptn = tx.getPriorityTransactionName();
return TransactionNamingUtility.comparePriority(priority, ptn.getPriority(), tx.getNamingScheme()) >= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.newrelic.agent.Agent;
import com.newrelic.agent.bridge.TransactionNamePriority;
import com.newrelic.api.agent.NewRelic;

import java.util.logging.Level;

Expand Down Expand Up @@ -42,15 +43,19 @@ public static boolean isLessThan(TransactionNamePriority one, TransactionNamePri
public static int comparePriority(TransactionNamePriority one, TransactionNamePriority two,
TransactionNamingScheme scheme) {
if (TransactionNamingScheme.RESOURCE_BASED.equals(scheme)) {
Agent.LOG.log(Level.FINEST, "agent.transaction.TransactionNamingUtility::comparePriority: pathPriorityOneValue: {0}, " +
"pathPriorityTwoValue: {1}; return val will be {2}",
one.pathPriority, two.pathPriority, one.pathPriority - two.pathPriority);
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "agent.transaction.TransactionNamingUtility::comparePriority: pathPriorityOneValue: {0}, " +
"pathPriorityTwoValue: {1}; return val will be {2}",
one.pathPriority, two.pathPriority, one.pathPriority - two.pathPriority);
}
return one.pathPriority - two.pathPriority;
}
else {
Agent.LOG.log(Level.FINEST, "agent.transaction.TransactionNamingUtility::comparePriority: legacyPriorityOneValue: {0}, " +
"legacyPriorityTwoValue: {1}; return val will be {2}",
one.legacyPriority, two.legacyPriority, one.legacyPriority - two.legacyPriority);
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
Agent.LOG.log(Level.FINEST, "agent.transaction.TransactionNamingUtility::comparePriority: legacyPriorityOneValue: {0}, " +
"legacyPriorityTwoValue: {1}; return val will be {2}",
one.legacyPriority, two.legacyPriority, one.legacyPriority - two.legacyPriority);
}
return one.legacyPriority - two.legacyPriority;
}
}
Expand Down

0 comments on commit aa2a763

Please sign in to comment.