Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obfuscate sql for external #559

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
better name and documentation
XiXiaPdx authored and meiao committed Jan 5, 2022
commit f456603b78aa74fec10d164f9205f65dfe0d8f17
Original file line number Diff line number Diff line change
@@ -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);
}