Search in sources :

Example 6 with ClassMethodMetricNameFormat

use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.

the class JsonTracer method generateRootBackgroundTracer.

private DefaultTracer generateRootBackgroundTracer(Long initTime) {
    long time = getStartTime(initTime);
    ClassMethodSignature sig = new ClassMethodSignature("clazz", tracerName, "()");
    Object reference = new Object();
    int flags = TracerFlags.DISPATCHER;
    if (startTimeNs != 0) {
        flags = TracerFlags.ASYNC;
    }
    DefaultTracer tracer = new OtherRootTracer(Transaction.getTransaction().getTransactionActivity(), sig, reference, new ClassMethodMetricNameFormat(sig, reference), flags, time);
    Transaction.getTransaction().getTransactionActivity().tracerStarted(tracer);
    return tracer;
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JSONObject(org.json.simple.JSONObject) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 7 with ClassMethodMetricNameFormat

use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.

the class AbstractExceptionHandlerPointCut method doGetTracer.

@Override
public final Tracer doGetTracer(final Transaction transaction, ClassMethodSignature sig, Object errorHandler, Object[] args) {
    final Throwable throwable = getThrowable(sig, args);
    if (throwable == null) {
        return null;
    }
    return new DefaultTracer(transaction, sig, errorHandler, new ClassMethodMetricNameFormat(sig, errorHandler)) {

        @Override
        protected void doFinish(int opcode, Object returnValue) {
            // Should this be TransactionErrorPriority.TRACER?
            transaction.setThrowable(throwable, TransactionErrorPriority.API, false);
            super.doFinish(opcode, returnValue);
        }
    };
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer)

Example 8 with ClassMethodMetricNameFormat

use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.

the class CrossProcessStateCatApiTest method testCatApiResponseExternalMetrics.

@Test
public void testCatApiResponseExternalMetrics() throws UnsupportedEncodingException {
    Transaction transactionOne = Mockito.mock(Transaction.class);
    Mockito.when(transactionOne.getAgentConfig()).thenReturn(ServiceFactory.getConfigService().getDefaultAgentConfig());
    TransactionActivity txaOne = Mockito.mock(TransactionActivity.class);
    CrossProcessConfig cpsOneConfig = getCrossProcessConfig("CrossProcessId", "");
    setUpTransaction(transactionOne, txaOne, new Object(), new MockDispatcher(), cpsOneConfig, "guid");
    MetricNameFormat nameFormat = new ClassMethodMetricNameFormat(new ClassMethodSignature("className", "methodName", "()V"), null, "");
    CatTestCustomTracer requestTracer = new CatTestCustomTracer(transactionOne, new ClassMethodSignature("className", "methodName", "()V"), new Object(), nameFormat, TracerFlags.DISPATCHER);
    when(txaOne.getLastTracer()).thenReturn(requestTracer);
    CrossProcessTransactionStateImpl cpsOne = CrossProcessTransactionStateImpl.create(transactionOne);
    Transaction transactionTwo = Mockito.mock(Transaction.class);
    Mockito.when(transactionTwo.getAgentConfig()).thenReturn(ServiceFactory.getConfigService().getDefaultAgentConfig());
    TransactionActivity txaTwo = Mockito.mock(TransactionActivity.class);
    CrossProcessConfig cpsTwoConfig = getCrossProcessConfig("CrossProcessId", "");
    setUpTransaction(transactionTwo, txaTwo, new Object(), new MockDispatcher(), cpsTwoConfig, "guid");
    InboundHeaderState ihs = Mockito.mock(InboundHeaderState.class);
    when(ihs.isTrustedCatRequest()).thenReturn(true);
    when(transactionTwo.getInboundHeaderState()).thenReturn(ihs);
    CrossProcessTransactionStateImpl cpsTwo = CrossProcessTransactionStateImpl.create(transactionTwo);
    String requestMetadata = cpsOne.getRequestMetadata();
    // Transaction one generates requestMetadata. This metadata is embedded in payload and sent to transaction two.
    // Transaction two gets requestMetadata from payload and provides it to agent.
    cpsTwo.processRequestMetadata(requestMetadata);
    String responseMetadata = cpsTwo.getResponseMetadata();
    // Transaction two generates responseMetadata and sends it to transaction one.
    // Transaction one receives response.
    cpsOne.processResponseMetadata(responseMetadata, null);
    Set<String> rollupMetricNames = requestTracer.getRollupMetricNames();
    assertTrue(rollupMetricNames.contains("External/all"));
    assertTrue(rollupMetricNames.contains("External/allOther"));
    assertTrue(rollupMetricNames.contains("External/Unknown/all"));
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) CrossProcessConfig(com.newrelic.agent.config.CrossProcessConfig) Matchers.anyString(org.mockito.Matchers.anyString) DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Test(org.junit.Test)

Aggregations

ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)8 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)6 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 CrossProcessConfig (com.newrelic.agent.config.CrossProcessConfig)1 Tracer (com.newrelic.agent.tracers.Tracer)1 DefaultMetricNameFormat (com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat)1 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)1 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)1 MethodTracer (com.newrelic.api.agent.MethodTracer)1 Matchers.anyString (org.mockito.Matchers.anyString)1