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"));
}
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;
}
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());
}
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());
}
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());
}
Aggregations