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