Search in sources :

Example 96 with ClassMethodSignature

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

the class CrossProcessStateCatApiTest method trustAppAndGetTracer.

private CatTestCustomTracer trustAppAndGetTracer(String accountID) {
    ImmutableMap<String, Object> crossProcessSettings = ImmutableMap.<String, Object>builder().put(CrossProcessConfigImpl.ENCODING_KEY, ENCODING_KEY).put(CrossProcessConfigImpl.ENABLED, Boolean.TRUE).put(CrossProcessConfigImpl.TRUSTED_ACCOUNT_IDS, accountID).put(CrossProcessConfigImpl.CROSS_PROCESS_ID, accountID + "#878").build();
    // Disable DT for CAT specific tests
    ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
    Map<String, Object> settings = new HashMap<>();
    settings.put(AgentConfigImpl.CROSS_APPLICATION_TRACER, crossProcessSettings);
    settings.put(AgentConfigImpl.APP_NAME, "TransactionAppNamingTest");
    settings.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
    ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
    serviceManager.setConfigService(configService);
    Transaction.clearTransaction();
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature classMethodSignature = new ClassMethodSignature("className", "methodName", "methodDesc");
    MetricNameFormat metricNameFormat = new DefaultMetricNameFormat(classMethodSignature, "", "something");
    CatTestCustomTracer tracer = new CatTestCustomTracer(transaction, classMethodSignature, null, metricNameFormat, TracerFlags.DISPATCHER | TracerFlags.GENERATE_SCOPED_METRIC);
    transaction.getTransactionActivity().tracerStarted(tracer);
    cps = transaction.getCrossProcessState();
    return tracer;
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) Matchers.anyString(org.mockito.Matchers.anyString) DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat)

Example 97 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature 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 98 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature 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 99 with ClassMethodSignature

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

the class TransactionTraceTest method serializeAttsDisabledWithIntrinsics.

@SuppressWarnings("unchecked")
@Test
public void serializeAttsDisabledWithIntrinsics() throws Exception {
    setUp(false, 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);
    Mockito.when(tracer.getEndTime()).thenReturn(5000000000L);
    Mockito.when(tracer.getDuration()).thenReturn(3000000000L);
    ;
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key2", "value2");
    Map<String, Object> errorParams = new HashMap<>();
    errorParams.put("error1", "valueError");
    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";
    String transactionGuid = "guid";
    TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, tracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Collections.singletonList(rootTracer)).setRequestParams(requestParams).setUserParams(userParams).setAgentParams(agentParams).setErrorParams(errorParams).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(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());
    Assert.assertEquals(startTime, jsonArray.get(0));
    Assert.assertEquals(5000L, jsonArray.get(1));
    Assert.assertEquals(frontendMetricName, jsonArray.get(2));
    Object serializedRequestUri = jsonArray.get(3);
    Assert.assertEquals(null, serializedRequestUri);
    Assert.assertEquals(transactionGuid, jsonArray.get(5));
    Assert.assertNull(jsonArray.get(6));
    // obsolete forcePersist flag
    Assert.assertEquals(false, jsonArray.get(7));
    Assert.assertEquals(5, jsonRootSegment.size());
    Assert.assertEquals(startTime, jsonRootSegment.get(0));
    JSONObject emptyObject = (JSONObject) jsonRootSegment.get(1);
    Assert.assertEquals(0, emptyObject.size());
    emptyObject = (JSONObject) jsonRootSegment.get(2);
    Assert.assertEquals(0, emptyObject.size());
    JSONObject atts = (JSONObject) jsonRootSegment.get(4);
    Assert.assertEquals(1, atts.size());
    Map<String, Object> 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 100 with ClassMethodSignature

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

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