Search in sources :

Example 56 with SimpleMetricNameFormat

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);
}
Also used : SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 57 with SimpleMetricNameFormat

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();
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) InetSocketAddress(java.net.InetSocketAddress) Connection(java.sql.Connection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 58 with SimpleMetricNameFormat

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;
}
Also used : MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 59 with SimpleMetricNameFormat

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

Example 60 with SimpleMetricNameFormat

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"));
}
Also used : HashMap(java.util.HashMap) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) StringWriter(java.io.StringWriter) TransactionData(com.newrelic.agent.TransactionData) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) TransactionService(com.newrelic.agent.TransactionService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) JSONArray(org.json.simple.JSONArray) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockConfigService(com.newrelic.agent.MockConfigService) ConfigService(com.newrelic.agent.config.ConfigService) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) JSONObject(org.json.simple.JSONObject) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Writer(java.io.Writer) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Aggregations

SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)70 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)46 Transaction (com.newrelic.agent.Transaction)43 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)34 Test (org.junit.Test)32 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)11 Response (com.newrelic.api.agent.Response)10 Tracer (com.newrelic.agent.tracers.Tracer)9 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)8 Request (com.newrelic.api.agent.Request)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)8 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)8 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)8 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)7 TransactionDataList (com.newrelic.agent.TransactionDataList)6