use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DefaultTracer method setMetricNameFormatInfo.
@Override
public void setMetricNameFormatInfo(String metricName, String transactionSegmentName, String transactionSegmentUri) {
MetricNameFormat format = new SimpleMetricNameFormat(metricName, transactionSegmentName, transactionSegmentUri);
setMetricNameFormat(format);
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DatabaseServiceTest method instanceSlowSqlAttribute.
@Test
public void instanceSlowSqlAttribute() throws Exception {
Map<String, Object> configMap = createStagingMap();
Map<String, Object> ttConfigMap = createMap();
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
ttConfigMap.put(TransactionTracerConfigImpl.EXPLAIN_THRESHOLD, 0);
configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttConfigMap);
Map<String, Object> dsConfigMap = createMap();
dsConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, true);
configMap.put(AgentConfigImpl.DATASTORE_TRACER, dsConfigMap);
Map<String, Object> stConfigMap = createMap();
stConfigMap.put(SqlTraceConfigImpl.ENABLED, true);
configMap.put(AgentConfigImpl.SLOW_SQL, stConfigMap);
createServiceManager(configMap);
final Connection connection = Mockito.mock(Connection.class);
final String databaseName = "myDatabase";
Mockito.when(connection.getCatalog()).thenReturn(databaseName);
DatastoreInstanceDetection.detectConnectionAddress();
InetSocketAddress address = new InetSocketAddress("address", 8080);
DatastoreInstanceDetection.associateAddress(connection, address);
DatastoreInstanceDetection.stopDetectingConnectionAddress();
Transaction transaction = Transaction.getTransaction(true);
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.setRawSql("select * from metrics");
tracer.provideConnection(connection);
ConnectionFactory connectionFactory = createConnectionFactory(connection);
tracer.setConnectionFactory(connectionFactory);
AgentHelper.setLastTracer(tracer);
tracer.finish(Opcodes.ARETURN, new DummyResultSet());
Assert.assertEquals(address.getHostName(), tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_HOST));
Assert.assertEquals(String.valueOf(address.getPort()), tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID));
Assert.assertEquals(databaseName, tracer.getAgentAttribute(DatastoreMetrics.DB_INSTANCE));
Transaction.clearTransaction();
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class WebRequestDispatcherTest method createDispatcher.
private WebRequestDispatcher createDispatcher(MockHttpRequest httpRequest) throws Exception {
Transaction tx = Transaction.getTransaction();
Response httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "methodName", "()V");
DefaultTracer tracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(tracer);
WebRequestDispatcher dispatcher = new WebRequestDispatcher(httpRequest, httpResponse, tx);
tx.setDispatcher(dispatcher);
return dispatcher;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat 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());
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method testDistributedTracingAtts.
@Test
public void testDistributedTracingAtts() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> config = new HashMap<>();
Map<String, Object> dtConfig = new HashMap<>();
dtConfig.put("enabled", true);
config.put("distributed_tracing", dtConfig);
Map<String, Object> spanConfig = new HashMap<>();
spanConfig.put("collect_span_events", true);
config.put("span_events", spanConfig);
config.put(AgentConfigImpl.APP_NAME, "TransactionTraceTest");
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
serviceManager.setConfigService(configService);
serviceManager.setAttributesService(new AttributesService());
serviceManager.setTransactionTraceService(new TransactionTraceService());
serviceManager.setTransactionService(new TransactionService());
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
serviceManager.setDistributedTraceService(distributedTraceService);
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
serviceManager.setRPMServiceManager(new MockRPMServiceManager());
Transaction.clearTransaction();
Transaction transaction = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("class", "method", "desc");
OtherRootTracer tracer = new OtherRootTracer(transaction, sig, null, new SimpleMetricNameFormat("metric"));
transaction.getTransactionActivity().tracerStarted(tracer);
tracer.finish(Opcodes.ARETURN, null);
TransactionData td = new TransactionData(transaction, 0);
((DistributedTraceServiceImpl) ServiceFactory.getDistributedTraceService()).dispatcherTransactionFinished(td, new TransactionStats());
TransactionTrace trace = TransactionTrace.getTransactionTrace(td, SqlObfuscator.getDefaultSqlObfuscator());
Writer writer = new StringWriter();
trace.writeJSONString(writer);
JSONArray serializedTrace = (JSONArray) AgentHelper.serializeJSON(trace);
JSONArray traceDetails = (JSONArray) decodeTransactionTraceData(serializedTrace.get(4));
JSONObject atts = (JSONObject) traceDetails.get(4);
Map<String, Object> intrinsics = (Map<String, Object>) atts.get("intrinsics");
Assert.assertTrue(intrinsics.containsKey("traceId"));
Assert.assertTrue(intrinsics.containsKey("guid"));
Assert.assertTrue(intrinsics.containsKey("priority"));
Assert.assertTrue(intrinsics.containsKey("sampled"));
}
Aggregations