Search in sources :

Example 21 with ClassMethodSignature

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

the class TransactionTraceTest method serializeAgentOnlyEnabled.

@SuppressWarnings("unchecked")
@Test
public void serializeAgentOnlyEnabled() throws Exception {
    setUp(true, true, false);
    Tracer rootTracer = new TestMethodExitTracer();
    Map<String, Object> parameters = Collections.emptyMap();
    Tracer tracer = Mockito.mock(Tracer.class);
    Mockito.when(tracer.getClassMethodSignature()).thenReturn(new ClassMethodSignature(getClass().getName(), "testMethod", "testSignature"));
    Mockito.when(tracer.getAgentAttributes()).thenReturn(parameters);
    long rootTracerDurationInMilliseconds = 100L;
    Mockito.when(tracer.getDurationInMilliseconds()).thenReturn(rootTracerDurationInMilliseconds);
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key3", "value3");
    Map<String, Object> intrinsics = new HashMap<>();
    intrinsics.put("key4", "value4");
    intrinsics.put("key5", 5L);
    long startTime = System.currentTimeMillis();
    String frontendMetricName = "Frontend/dude";
    String requestUri = "/dude";
    String appName = "dude";
    TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, tracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Collections.singletonList(rootTracer)).setRequestParams(requestParams).setAgentParams(agentParams).setIntrinsics(intrinsics).build();
    TransactionTrace trace = TransactionTrace.getTransactionTrace(transactionData, SqlObfuscator.getDefaultSqlObfuscator());
    JSONParser parser = new JSONParser();
    // Get the raw data
    JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(trace);
    // Manually create an "inflated" version for comparison with simple compression
    JSONArray inflatedJsonArray = new JSONArray();
    inflatedJsonArray.addAll(jsonArray);
    // Extract and inflate
    Object decodedTTData = decodeTransactionTraceData(inflatedJsonArray.get(4));
    // Store back in array to compare with simple compression below
    inflatedJsonArray.set(4, decodedTTData);
    Assert.assertNotNull(jsonArray);
    // Second, serialize with simple compression off (data will be deflated)
    byte[] jsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
    JSONArray parsedJsonByteArray = (JSONArray) parser.parse(new String(jsonByteArray, StandardCharsets.UTF_8));
    Assert.assertEquals(jsonArray, parsedJsonByteArray);
    // Third, turn on simple compression and compare with raw data above
    setUp(true, true, true);
    byte[] simpleCompressionJsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
    JSONArray parsedSimpleCompressionJsonByteArray = (JSONArray) parser.parse(new String(simpleCompressionJsonByteArray, StandardCharsets.UTF_8));
    Assert.assertEquals(inflatedJsonArray, parsedSimpleCompressionJsonByteArray);
    JSONArray jsonRootSegment = (JSONArray) decodedTTData;
    Assert.assertEquals(requestUri, jsonArray.get(3));
    Assert.assertEquals(5, jsonRootSegment.size());
    JSONObject atts = (JSONObject) jsonRootSegment.get(4);
    Assert.assertEquals(2, atts.size());
    Map<String, Object> innerAtts = (Map<String, Object>) atts.get("agentAttributes");
    Assert.assertEquals(3, innerAtts.size());
    Assert.assertEquals("value1", innerAtts.get("request.parameters.key1"));
    Assert.assertEquals("value3", innerAtts.get("key3"));
    innerAtts = (Map<String, Object>) atts.get("intrinsics");
    Assert.assertEquals(3, innerAtts.size());
    Assert.assertEquals("value4", innerAtts.get("key4"));
    Assert.assertEquals(5L, innerAtts.get("key5"));
    Assert.assertNotNull(innerAtts.get("totalTime"));
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) MethodExitTracer(com.newrelic.agent.tracers.MethodExitTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) JSONArray(org.json.simple.JSONArray) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 22 with ClassMethodSignature

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

the class SqlTraceServiceTest method startSqlTracer.

private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {

        @Override
        public long getDuration() {
            return duration;
        }

        @Override
        public Object getSql() {
            return sql;
        }
    };
    sqlTracer.setConnectionFactory(new ConnectionFactory() {

        @Override
        public Connection getConnection() throws SQLException {
            return null;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return UnknownDatabaseVendor.INSTANCE;
        }
    });
    sqlTracer.setRawSql(sql);
    tx.getTransactionActivity().tracerStarted(sqlTracer);
    return sqlTracer;
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) UnknownDatabaseVendor(com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 23 with ClassMethodSignature

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

the class SqlTraceServiceTest method startDispatcherTracer.

private Tracer startDispatcherTracer(String appName) throws Exception {
    Transaction tx = Transaction.getTransaction();
    MockHttpRequest httpRequest = new MockHttpRequest();
    MockHttpResponse httpResponse = new MockHttpResponse();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    Tracer requestDispatcherTracer = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
    tx.getTransactionActivity().tracerStarted(requestDispatcherTracer);
    tx.setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, appName);
    return requestDispatcherTracer;
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Example 24 with ClassMethodSignature

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

the class MetricNameFormatTest method classMethodMetricNameFormat.

@Test
public void classMethodMetricNameFormat() {
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Bar", "getName()", "()V");
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", ClassMethodMetricNameFormat.getMetricName(sig, this));
    Assert.assertEquals("Test/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", ClassMethodMetricNameFormat.getMetricName(sig, this, "Test"));
    ClassMethodMetricNameFormat formatter = new ClassMethodMetricNameFormat(sig, this.getClass().getName());
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getMetricName());
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getTransactionSegmentName());
    Assert.assertEquals("Spring/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", new ClassMethodMetricNameFormat(sig, this.getClass().getName(), "Spring").getMetricName());
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Test(org.junit.Test)

Example 25 with ClassMethodSignature

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

the class MetricNameFormatTest method defaultFormat.

@Test
public void defaultFormat() {
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Bar", "getName()", "()V");
    DefaultMetricNameFormat formatter = new DefaultMetricNameFormat(sig, this, "Java/{0}/{1}");
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getMetricName());
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getTransactionSegmentName());
    formatter = new DefaultMetricNameFormat(sig, this, "Class/{0}");
    Assert.assertEquals("Class/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest", formatter.getMetricName());
    formatter = new DefaultMetricNameFormat(sig, this, "Method/{1}");
    Assert.assertEquals("Method/getName()", formatter.getMetricName());
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) Test(org.junit.Test)

Aggregations

ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)112 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)69 Transaction (com.newrelic.agent.Transaction)60 Test (org.junit.Test)55 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)46 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)44 Tracer (com.newrelic.agent.tracers.Tracer)41 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)26 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)23 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 HashMap (java.util.HashMap)17 TransactionData (com.newrelic.agent.TransactionData)16 JSONObject (org.json.simple.JSONObject)15 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)13 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)12 JSONArray (org.json.simple.JSONArray)11 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)10 Response (com.newrelic.api.agent.Response)10 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)9