Search in sources :

Example 1 with OtherTransSimpleMetricNameFormat

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

the class TransactionTimesTest method createDispatcherTracer.

// Create a Tracer for tests that require one.
private OtherRootTracer createDispatcherTracer() {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    return new OtherRootTracer(tx, sig, this, new OtherTransSimpleMetricNameFormat("myMetricName"));
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 2 with OtherTransSimpleMetricNameFormat

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

the class TransactionTraceTest method testExecContext.

@Test
public void testExecContext() throws Exception {
    setUp(false, true, false);
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = new OtherRootTracer(tx, new ClassMethodSignature("Test", "root", "()V"), this, new OtherTransSimpleMetricNameFormat("myMetricName"));
    DefaultTracer tracer1 = new DefaultTracer(tx, new ClassMethodSignature("Test", "dude", "()V"), this);
    DefaultTracer tracer2 = new DefaultTracer(tx, new ClassMethodSignature("Test", "dude2", "()V"), this);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    tx.getTransactionActivity().tracerStarted(tracer1);
    tx.getTransactionActivity().tracerStarted(tracer2);
    tracer2.finish(0, null);
    tracer1.finish(0, null);
    rootTracer.finish(0, null);
    long startTime = System.currentTimeMillis();
    String frontendMetricName = "Frontend/dude";
    String requestUri = "/dude";
    String appName = "dude";
    TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, rootTracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Arrays.asList(rootTracer, tracer1, tracer2)).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(false, 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(8, jsonArray.size());
    JSONArray rootSeg = (JSONArray) jsonRootSegment.get(3);
    Assert.assertNotNull(rootSeg);
    verifyAllTraceSegmentsHaveExecContext(rootSeg);
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) MethodExitTracer(com.newrelic.agent.tracers.MethodExitTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) JSONArray(org.json.simple.JSONArray) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) Test(org.junit.Test)

Aggregations

Transaction (com.newrelic.agent.Transaction)2 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)2 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)2 OtherTransSimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat)2 TransactionData (com.newrelic.agent.TransactionData)1 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1 Test (org.junit.Test)1