Search in sources :

Example 1 with SqlTraceConfig

use of com.newrelic.agent.config.SqlTraceConfig in project newrelic-java-agent by newrelic.

the class SlowQueryInfoTest method testDTAttributes.

@Test
public void testDTAttributes() {
    Map<String, Object> settings = new HashMap<>();
    Map<String, Object> dtMap = new HashMap<>();
    dtMap.put("enabled", true);
    settings.put("distributed_tracing", dtMap);
    Map<String, Object> spanConfig = new HashMap<>();
    spanConfig.put("collect_span_events", true);
    settings.put("span_events", spanConfig);
    setupServiceManager(settings);
    DistributedTraceServiceImpl dts = (DistributedTraceServiceImpl) ServiceFactory.getServiceManager().getDistributedTraceService();
    Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put("distributed_tracing", ImmutableMap.builder().put("primary_application_id", "1app23").put("trusted_account_key", "1tak23").put("account_id", "1acct234").build()).build();
    dts.connected(null, AgentConfigFactory.createAgentConfig(configMap, null, null));
    Transaction.clearTransaction();
    Transaction transaction = Transaction.getTransaction();
    transaction.getTransactionActivity().tracerStarted(new OtherRootTracer(transaction, new ClassMethodSignature("class", "method", "desc"), null, new SimpleMetricNameFormat("test")));
    String inboundPayload = "{\n" + "  \"v\": [\n" + "    0,\n" + "    2\n" + "  ],\n" + "  \"d\": {\n" + "    \"ty\": \"App\",\n" + "    \"ac\": \"1acct789\",\n" + "    \"ap\": \"1app23\",\n" + "    \"id\": \"27856f70d3d314b7\",\n" + "    \"tr\": \"3221bf09aa0bcf0d\",\n" + "    \"tk\": \"1tak23\",\n" + "    \"pr\": 1.0002,\n" + "    \"sa\": true,\n" + "    \"tx\": \"123456\",\n" + "    \"ti\": 1482959525577\n" + "  }\n" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    String obfuscatedQuery = "select ? from ?";
    HashMap<String, Object> sqlMap = new HashMap<>();
    ServerProp serverProp = ServerProp.createPropObject(SqlTraceConfigImpl.DEFAULT_USE_LONGER_SQL_ID);
    sqlMap.put(SqlTraceConfigImpl.USE_LONGER_SQL_ID, serverProp);
    SqlTraceConfig sqlTraceConfig = SqlTraceConfigImpl.createSqlTraceConfig(sqlMap);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", obfuscatedQuery, sqlTraceConfig);
    assertNotNull(transaction.getSpanProxy().getInboundDistributedTracePayload());
    Map<String, Object> parameters = slowQueryInfo.getParameters();
    assertEquals("App", parameters.get("parent.type"));
    assertEquals("1app23", parameters.get("parent.app"));
    assertEquals("1acct789", parameters.get("parent.account"));
    assertNotNull(parameters.get("parent.transportType"));
    assertNotNull(parameters.get("parent.transportDuration"));
    assertNotNull(parameters.get("guid"));
    assertEquals("3221bf09aa0bcf0d", parameters.get("traceId"));
    assertNotNull(parameters.get("priority"));
    assertEquals(true, parameters.get("sampled"));
}
Also used : HashMap(java.util.HashMap) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) TransactionData(com.newrelic.agent.TransactionData) ServerProp(com.newrelic.agent.config.ServerProp) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) Test(org.junit.Test)

Example 2 with SqlTraceConfig

use of com.newrelic.agent.config.SqlTraceConfig in project newrelic-java-agent by newrelic.

the class SlowQueryInfoTest method testLongerSqlId.

@Test
public void testLongerSqlId() {
    setupServiceManager(new HashMap<String, Object>());
    Transaction transaction = Transaction.getTransaction();
    HashMap<String, Object> sqlMap = new HashMap<>();
    ServerProp serverProp = ServerProp.createPropObject(!SqlTraceConfigImpl.DEFAULT_USE_LONGER_SQL_ID);
    sqlMap.put(SqlTraceConfigImpl.USE_LONGER_SQL_ID, serverProp);
    SqlTraceConfig sqlTraceConfig = SqlTraceConfigImpl.createSqlTraceConfig(sqlMap);
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setUri("http://jvm.agent.uri");
    transaction.setDispatcher(dispatcher);
    String obfuscatedQuery = "select ? from ?";
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", obfuscatedQuery, sqlTraceConfig);
    SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
    long hashedQuery = (long) obfuscatedQuery.hashCode();
    long longerHash = SlowQueryInfo.createLongerHashCode(hashedQuery);
    assertEquals(longerHash, sqlTrace.getId());
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionData(com.newrelic.agent.TransactionData) ServerProp(com.newrelic.agent.config.ServerProp) Test(org.junit.Test)

Example 3 with SqlTraceConfig

use of com.newrelic.agent.config.SqlTraceConfig in project newrelic-java-agent by newrelic.

the class SlowQueryInfoTest method testEmptyTxnUrlRequestUriDisabled.

@Test
public void testEmptyTxnUrlRequestUriDisabled() {
    Map<String, Object> attributeMap = new HashMap<>();
    attributeMap.put("exclude", "request.*");
    Map<String, Object> settings = new HashMap<>();
    settings.put("attributes", attributeMap);
    setupServiceManager(settings);
    SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
    Transaction transaction = Transaction.getTransaction();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setUri("http://jvm.agent.uri");
    transaction.setDispatcher(dispatcher);
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
    SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
    assertEquals(null, sqlTrace.getUri());
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 4 with SqlTraceConfig

use of com.newrelic.agent.config.SqlTraceConfig in project newrelic-java-agent by newrelic.

the class SlowQueryInfoTest method testTxnUrl.

@Test
public void testTxnUrl() {
    setupServiceManager(new HashMap<String, Object>());
    Transaction transaction = Transaction.getTransaction();
    SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setUri("http://jvm.agent.uri");
    transaction.setDispatcher(dispatcher);
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
    SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
    assertEquals("http://jvm.agent.uri", sqlTrace.getUri());
}
Also used : SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 5 with SqlTraceConfig

use of com.newrelic.agent.config.SqlTraceConfig in project newrelic-java-agent by newrelic.

the class SlowQueryInfoTest method testStandardSqlId.

@Test
public void testStandardSqlId() {
    setupServiceManager(new HashMap<String, Object>());
    Transaction transaction = Transaction.getTransaction();
    HashMap<String, Object> sqlMap = new HashMap<>();
    ServerProp serverProp = ServerProp.createPropObject(SqlTraceConfigImpl.DEFAULT_USE_LONGER_SQL_ID);
    sqlMap.put(SqlTraceConfigImpl.USE_LONGER_SQL_ID, serverProp);
    SqlTraceConfig sqlTraceConfig = SqlTraceConfigImpl.createSqlTraceConfig(sqlMap);
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setUri("http://jvm.agent.uri");
    transaction.setDispatcher(dispatcher);
    String obfuscatedQuery = "select ? from ?";
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", obfuscatedQuery, sqlTraceConfig);
    SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
    long hashedObfuscatedQuery = (long) obfuscatedQuery.hashCode();
    assertEquals(hashedObfuscatedQuery, sqlTrace.getId());
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionData(com.newrelic.agent.TransactionData) ServerProp(com.newrelic.agent.config.ServerProp) Test(org.junit.Test)

Aggregations

Transaction (com.newrelic.agent.Transaction)5 TransactionData (com.newrelic.agent.TransactionData)5 SqlTraceConfig (com.newrelic.agent.config.SqlTraceConfig)5 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)5 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)5 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)5 Tracer (com.newrelic.agent.tracers.Tracer)5 Test (org.junit.Test)5 MockDispatcher (com.newrelic.agent.MockDispatcher)4 HashMap (java.util.HashMap)4 ServerProp (com.newrelic.agent.config.ServerProp)3 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)1 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)1