Search in sources :

Example 46 with OtherRootTracer

use of com.newrelic.agent.tracers.OtherRootTracer 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)

Example 47 with OtherRootTracer

use of com.newrelic.agent.tracers.OtherRootTracer 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)

Example 48 with OtherRootTracer

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

the class BasicRequestDispatcherTracerTest method createDispatcher.

private WebRequestDispatcher createDispatcher(Request httpRequest) throws Exception {
    Transaction tx = Transaction.getTransaction();
    Response httpResponse = new MockHttpResponse();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()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 : Response(com.newrelic.api.agent.Response) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 49 with OtherRootTracer

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

the class DistributedTraceServiceImplTest method configureAndCreatePayload.

private DistributedTracePayload configureAndCreatePayload(boolean excludeNewRelicHeader, boolean spanEventsEnabled) {
    Map<String, Object> config = new HashMap<>();
    config.put(AgentConfigImpl.APP_NAME, "Test");
    Map<String, Object> dtConfig = new HashMap<>();
    dtConfig.put(DistributedTracingConfig.ENABLED, true);
    // This will need to change when we implement JAVA-5559
    if (excludeNewRelicHeader) {
        dtConfig.put(DistributedTracingConfig.EXCLUDE_NEWRELIC_HEADER, "true");
    }
    config.put(AgentConfigImpl.DISTRIBUTED_TRACING, dtConfig);
    Map<String, Object> spansConfig = new HashMap<>();
    spansConfig.put(SpanEventsConfig.ENABLED, spanEventsEnabled);
    spansConfig.put(SpanEventsConfig.COLLECT_SPAN_EVENTS, true);
    config.put(AgentConfigImpl.SPAN_EVENTS, spansConfig);
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(config);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
    serviceManager.setConfigService(configService);
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    Map<String, Object> connectInfo = new HashMap<>();
    connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "accountId");
    connectInfo.put(DistributedTracingConfig.PRIMARY_APPLICATION_ID, "primaryApplicationId");
    connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "trustKey");
    connectInfo.put(DistributedTracingConfig.EXCLUDE_NEWRELIC_HEADER, excludeNewRelicHeader);
    AgentConfig connectData = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
    DistributedTraceServiceImplTest.distributedTraceService.connected(serviceManager.getRPMServiceManager().getRPMService(), connectData);
    Transaction.clearTransaction();
    txn = Transaction.getTransaction(true);
    final ClassMethodSignature cms = new ClassMethodSignature("class", "method", "methodDesc");
    final OtherRootTracer tracer = new OtherRootTracer(txn, cms, null, new SimpleMetricNameFormat("metricName"));
    txn.getTransactionActivity().tracerStarted(tracer);
    return distributedTraceService.createDistributedTracePayload(tracer);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 50 with OtherRootTracer

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

the class TransactionActivityTest method txaNoTxn.

@Test
public void txaNoTxn() {
    TransactionActivity txa = TransactionActivity.create(null, Integer.MAX_VALUE);
    ClassMethodSignature classMethodSignature = new ClassMethodSignature("class", "method", "methodDesc");
    OtherRootTracer tracer = new OtherRootTracer(txa, classMethodSignature, null, null, TracerFlags.TRANSACTION_TRACER_SEGMENT | TracerFlags.ASYNC, 0);
    tracer.isTransactionSegment();
    // Make sure methods that touch this txa's txn don't throw NPEs.
    txa.tracerStarted(tracer);
    txa.addTracer(tracer);
    txa.tracerFinished(tracer, 0);
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionActivity(com.newrelic.agent.TransactionActivity) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Aggregations

OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)51 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)45 Transaction (com.newrelic.agent.Transaction)35 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)34 Test (org.junit.Test)31 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)15 Tracer (com.newrelic.agent.tracers.Tracer)15 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)11 Response (com.newrelic.api.agent.Response)10 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)8 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 TransactionDataList (com.newrelic.agent.TransactionDataList)6