diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/tracers/DefaultSqlTracer.java b/newrelic-agent/src/main/java/com/newrelic/agent/tracers/DefaultSqlTracer.java index 67dc2e458b..8e1aa8bfec 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/tracers/DefaultSqlTracer.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/tracers/DefaultSqlTracer.java @@ -270,7 +270,7 @@ protected void recordMetrics(TransactionStats transactionStats) { if (sqlObject != null) { slowQuerySql = new PreparedStatementSql(sql, params).toString(); if (queryExceedsSlowQueryThreshold(appName)) { - slowQuerySql = obfuscateRawSql(slowQuerySql, appName); + slowQuerySql = getNoRawOrObfuscatedSql(slowQuerySql, appName); } } @@ -304,7 +304,16 @@ protected void recordMetrics(TransactionStats transactionStats) { super.recordMetrics(transactionStats); } - private String obfuscateRawSql(String rawSql, String appName) { + /** + * This method is named this way because the docs on toObfuscatedQueryString imply obfuscation certainty. + * The reality is the SqlQueryConverter implementation of this method has introduced conditional + * logic that respects the agent configuration setting `record_sql`. + * + * If OBFUSCATED, sql is obfuscated. + * If RAW, sql is returned, unchanged. + * If OFF, null is returned. + */ + private String getNoRawOrObfuscatedSql(String rawSql, String appName) { SqlQueryConverter converter = new SqlQueryConverter(appName, getDatabaseVendor()); return converter.toObfuscatedQueryString(rawSql); }