Skip to content

Commit

Permalink
Merge pull request #1543 from newrelic/1530-txn-name-logging
Browse files Browse the repository at this point in the history
Additional transaction naming logging
  • Loading branch information
jtduffy authored Oct 16, 2023
2 parents ed52520 + aa2a763 commit c157fca
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ private static boolean setTxNameUsingServletName(ServletConfig servletConfig, Se
return false;
}
txName = normalizeServletName(txName, servlet);
NewRelic.getAgent().getLogger().log(Level.FINER, "Setting transaction name using servlet name: {0}", txName);

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,7 +184,15 @@ private static boolean setTxNameUsingServletName(ServletConfig servletConfig, Se
return false;
}
txName = normalizeServletName(txName, servlet);
NewRelic.getAgent().getLogger().log(Level.FINER, "Setting transaction name using servlet name: {0}", txName);

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,7 +181,15 @@ private static boolean setTxNameUsingServletName(ServletConfig servletConfig, Se
return false;
}
txName = normalizeServletName(txName, servlet);
NewRelic.getAgent().getLogger().log(Level.FINER, "Setting transaction name using servlet name: {0}", txName);

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 @@ -10,6 +10,7 @@
import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.agent.bridge.Transaction;
import com.newrelic.agent.bridge.TransactionNamePriority;
import com.newrelic.api.agent.NewRelic;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

Expand Down Expand Up @@ -80,6 +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);
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,6 +738,12 @@ public boolean conditionalSetPriorityTransactionName(TransactionNamingPolicy pol
synchronized (lock) {
MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SET_TRANSACTION_NAME);

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()) {
Agent.LOG.log(Level.FINEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public boolean registerAsyncActivity(Object asyncContext) {
public boolean setTransactionName(TransactionNamePriority namePriority, boolean override, String category,
String... parts) {
Transaction tx = getTransactionIfExists();
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 @@ -160,6 +164,10 @@ public void ignoreErrors() {
public boolean setTransactionName(com.newrelic.agent.bridge.TransactionNamePriority namePriority, boolean override,
String category, String... parts) {
Transaction tx = getTransactionIfExists();
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 @@ -7,8 +7,12 @@

package com.newrelic.agent.transaction;

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;

class HigherPriorityTransactionNamingPolicy extends TransactionNamingPolicy {

Expand All @@ -20,6 +24,13 @@ public boolean canSetTransactionName(Transaction tx, TransactionNamePriority pri
if (priority == null) {
return false;
}

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 @@ -7,8 +7,12 @@

package com.newrelic.agent.transaction;

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;

class SameOrHigherPriorityTransactionNamingPolicy extends TransactionNamingPolicy {

Expand All @@ -20,6 +24,13 @@ public boolean canSetTransactionName(Transaction tx, TransactionNamePriority pri
if (priority == null) {
return false;
}

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 @@ -7,7 +7,11 @@

package com.newrelic.agent.transaction;

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

import java.util.logging.Level;

public class TransactionNamingUtility {
/**
Expand Down Expand Up @@ -39,9 +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)) {
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 {
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 c157fca

Please sign in to comment.