use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.
the class TransactionDataTest method getDispatcher.
@Test
public void getDispatcher() {
Dispatcher expected = Mockito.mock(Dispatcher.class);
Mockito.when(tx.getDispatcher()).thenReturn(expected);
TransactionData txd = getTxData(tx);
Dispatcher result = txd.getDispatcher();
Assert.assertSame(expected, result);
}
use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.
the class IgnoreApdexInvocationHandler method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Transaction transaction = Transaction.getTransaction(false);
if (transaction != null) {
Dispatcher dispatcher = transaction.getDispatcher();
if (dispatcher != null) {
dispatcher.setIgnoreApdex(true);
if (Agent.LOG.isLoggable(Level.FINER)) {
String msg = MessageFormat.format("Set Ignore apdex to \"{0}\"", true);
Agent.LOG.log(Level.FINER, msg, new Exception());
}
}
}
return null;
}
use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.
the class NewRelicApiImplementation method setTransactionName.
/**
* Set the name of the current transaction.
*
* @param category
* @param name The name of the transaction in URI format. example: /store/order
*/
@Override
public void setTransactionName(String category, String name) {
if (StringUtils.isEmpty(category)) {
category = MetricNames.CUSTOM;
}
if (name == null || name.length() == 0) {
Agent.LOG.log(Level.FINER, "Unable to set the transaction name to an empty string");
return;
}
if (!name.startsWith("/")) {
name = "/" + name;
}
Transaction tx = Transaction.getTransaction(false);
if (tx == null) {
return;
}
Dispatcher dispatcher = tx.getDispatcher();
if (dispatcher == null) {
if (Agent.LOG.isFinerEnabled()) {
Agent.LOG.finer(MessageFormat.format("Unable to set the transaction name to \"{0}\" in NewRelic API - no transaction", name));
}
return;
}
boolean isWebTransaction = dispatcher.isWebTransaction();
TransactionNamingPolicy policy = TransactionNamingPolicy.getSameOrHigherPriorityTransactionNamingPolicy();
com.newrelic.agent.bridge.TransactionNamePriority namePriority = MetricNames.URI.equals(category) ? com.newrelic.agent.bridge.TransactionNamePriority.REQUEST_URI : com.newrelic.agent.bridge.TransactionNamePriority.CUSTOM_HIGH;
if (Agent.LOG.isLoggable(Level.FINER)) {
if (policy.canSetTransactionName(tx, namePriority)) {
String msg = MessageFormat.format("Setting {1} transaction name to \"{0}\" in NewRelic API", name, isWebTransaction ? "web" : "background");
Agent.LOG.finer(msg);
} else {
Agent.LOG.finer("Unable to set the transaction name to " + name);
}
}
synchronized (tx) {
policy.setTransactionName(tx, name, category, namePriority);
}
}
use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.
the class NewRelicApiImplementation method setAccountName.
/**
* Set the account name to associate with the RUM JavaScript footer for the current web transaction.
*/
@Override
public void setAccountName(String name) {
Transaction tx = Transaction.getTransaction(false);
if (tx != null) {
Dispatcher dispatcher = tx.getDispatcher();
if (dispatcher == null) {
Agent.LOG.finer(MessageFormat.format("Unable to set the account name to \"{0}\" in NewRelic API - no transaction", name));
return;
}
if (!dispatcher.isWebTransaction()) {
Agent.LOG.finer(MessageFormat.format("Unable to set the account name to \"{0}\" in NewRelic API - transaction is not a web transaction", name));
return;
}
if (Agent.LOG.isLoggable(Level.FINER)) {
String msg = MessageFormat.format("Attempting to set account name to \"{0}\" in NewRelic API", name);
Agent.LOG.finer(msg);
}
attributeSender.addAttribute("account", name, "setAccountName");
MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SET_ACCOUNT_NAME);
}
}
use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method createTransactionData.
private TransactionData createTransactionData(Map<String, Object> intrinsicAttributes, long startTimeInMillis, long responseTimeInNanos, DistributedTracePayloadImpl payload) {
long payloadTimestamp = payload != null ? payload.timestamp : 0;
Transaction tx = Mockito.mock(Transaction.class);
SpanProxy spanProxy = new SpanProxy();
spanProxy.acceptDistributedTracePayload(payload);
CrossProcessTransactionState crossProcessTransactionState = Mockito.mock(CrossProcessTransactionState.class);
Dispatcher dispatcher = Mockito.mock(Dispatcher.class);
TransactionTimer timer = Mockito.mock(TransactionTimer.class);
when(tx.getIntrinsicAttributes()).thenReturn(intrinsicAttributes);
when(tx.getSpanProxy()).thenReturn(spanProxy);
when(crossProcessTransactionState.getTripId()).thenReturn("abc123");
when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
when(dispatcher.isWebTransaction()).thenReturn(true);
when(tx.getDispatcher()).thenReturn(dispatcher);
when((tx.getTransportDurationInMillis())).thenReturn(startTimeInMillis - payloadTimestamp);
when(timer.getResponseTimeInNanos()).thenReturn(responseTimeInNanos);
when(tx.getTransactionTimer()).thenReturn(timer);
when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
when(tx.getTransportType()).thenReturn(TransportType.HTTPS);
return new TransactionData(tx, 0);
}
Aggregations