Search in sources :

Example 16 with MetricNameFormat

use of com.newrelic.agent.tracers.metricname.MetricNameFormat 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)

Example 17 with MetricNameFormat

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

the class CrossProcessStateCatApiTest method trustAppAndGetTracer.

private CatTestCustomTracer trustAppAndGetTracer(String accountID) {
    ImmutableMap<String, Object> crossProcessSettings = ImmutableMap.<String, Object>builder().put(CrossProcessConfigImpl.ENCODING_KEY, ENCODING_KEY).put(CrossProcessConfigImpl.ENABLED, Boolean.TRUE).put(CrossProcessConfigImpl.TRUSTED_ACCOUNT_IDS, accountID).put(CrossProcessConfigImpl.CROSS_PROCESS_ID, accountID + "#878").build();
    // Disable DT for CAT specific tests
    ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
    Map<String, Object> settings = new HashMap<>();
    settings.put(AgentConfigImpl.CROSS_APPLICATION_TRACER, crossProcessSettings);
    settings.put(AgentConfigImpl.APP_NAME, "TransactionAppNamingTest");
    settings.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
    ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
    serviceManager.setConfigService(configService);
    Transaction.clearTransaction();
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature classMethodSignature = new ClassMethodSignature("className", "methodName", "methodDesc");
    MetricNameFormat metricNameFormat = new DefaultMetricNameFormat(classMethodSignature, "", "something");
    CatTestCustomTracer tracer = new CatTestCustomTracer(transaction, classMethodSignature, null, metricNameFormat, TracerFlags.DISPATCHER | TracerFlags.GENERATE_SCOPED_METRIC);
    transaction.getTransactionActivity().tracerStarted(tracer);
    cps = transaction.getCrossProcessState();
    return tracer;
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) 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)

Example 18 with MetricNameFormat

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

the class ExternalComponentTracerTest method test.

@Test
public void test() {
    MetricNameFormat format = getExternalMetricFormatter(false);
    Assert.assertEquals("External/localhost/socket", format.getMetricName());
    Assert.assertEquals("External/localhost/socket/get", format.getTransactionSegmentName());
    Assert.assertEquals("http://www.example.com:8080/hithere/hi.html", format.getTransactionSegmentUri());
    format = getExternalMetricFormatter(true);
    Assert.assertEquals("External/localhost/socket/get", format.getMetricName());
    Assert.assertEquals("External/localhost/socket/get", format.getTransactionSegmentName());
    Assert.assertEquals("http://www.example.com:8080/hithere/hi.html", format.getTransactionSegmentUri());
}
Also used : MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) Test(org.junit.Test)

Example 19 with MetricNameFormat

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

the class ExternalComponentTracerTest method multipleOperations.

@Test
public void multipleOperations() {
    MetricNameFormat format = getExternalMetricFormatter(false, "http:localhost:8080/newservlet", new String[] { "open", "dude" });
    Assert.assertEquals("External/localhost/socket", format.getMetricName());
    Assert.assertEquals("External/localhost/socket/open/dude", format.getTransactionSegmentName());
    Assert.assertEquals("http:localhost:8080/newservlet", format.getTransactionSegmentUri());
}
Also used : MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) Test(org.junit.Test)

Example 20 with MetricNameFormat

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

the class MetricNameFormatTest method simpleFormat.

@Test
public void simpleFormat() {
    MetricNameFormat formatter = new SimpleMetricNameFormat("Foo/Bar");
    Assert.assertEquals("Foo/Bar", formatter.getMetricName());
    Assert.assertEquals("Foo/Bar", formatter.getTransactionSegmentName());
    formatter = new SimpleMetricNameFormat("Foo/Bean", "FooBar/Dude/Man");
    Assert.assertEquals("Foo/Bean", formatter.getMetricName());
    Assert.assertEquals("FooBar/Dude/Man", formatter.getTransactionSegmentName());
}
Also used : DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) Test(org.junit.Test)

Aggregations

MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)21 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)13 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)12 Tracer (com.newrelic.agent.tracers.Tracer)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Transaction (com.newrelic.agent.Transaction)8 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)8 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)8 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)8 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)7 Test (org.junit.Test)7 ExitTracer (com.newrelic.agent.bridge.ExitTracer)6 AgentBridge (com.newrelic.agent.bridge.AgentBridge)4 NoOpTransaction (com.newrelic.agent.bridge.NoOpTransaction)4 TransactionActivity (com.newrelic.agent.TransactionActivity)3 ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)3 DefaultMetricNameFormat (com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat)3 SkipTracer (com.newrelic.agent.tracers.SkipTracer)2 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)2 JSONObject (org.json.simple.JSONObject)2