We would expect that SQL queries would be treated the same way throughout the product. If they are not, the intuitive location to display the complete, untruncated SQL query is the Datastores slow query page.
In internal discussions, we identified the following discrepancies:
SQL statements for Transaction Segments are truncated only if the statement is an INSERT. When they are truncated, they obey the insert_sql_max_length setting.
SQL statements for Slow Query SQL Traces are always truncated. They obey the insert_sql_max_length setting.
SQL statements for Span Events (captured as db.statement) are always truncated. They are hardcoded to truncate either to 4095 chars for agents >= 8.12 or to 2000 chars for agents < 8.12. They do not obey the insert_sql_max_length setting.
It also appears that not all of our APM agents limit SQL query size in the same way. Additional work is needed to determine if this is consistent with agent specification.
Description
SQL queries displayed on the Datastores page in APM are truncated at 2,000 characters by default, as per https://docs.newrelic.com/docs/apm/agents/java-agent/configuration/java-agent-configuration-config-file/#insert_sql_max_length
However, SQL queries displayed on the Transaction Trace SQL queries tab are not. More specifically, they are truncated only if the statement is an insert: https://github.com/newrelic/newrelic-java-agent/blob/070842710cd23b460c0bb3c0492b52c0fd3e576b/newrelic-agent/src/main/java/com/newrelic/agent/trace/TransactionSegment.java#L255
Expected Behavior
We would expect that SQL queries would be treated the same way throughout the product. If they are not, the intuitive location to display the complete, untruncated SQL query is the Datastores slow query page.
Troubleshooting or [NR Diag]
In internal discussions, we identified the following discrepancies:
SQL statements for Transaction Segments are truncated only if the statement is an INSERT. When they are truncated, they obey the insert_sql_max_length setting.
SQL statements for Slow Query SQL Traces are always truncated. They obey the insert_sql_max_length setting.
SQL statements for Span Events (captured as db.statement) are always truncated. They are hardcoded to truncate either to 4095 chars for agents >= 8.12 or to 2000 chars for agents < 8.12. They do not obey the insert_sql_max_length setting.
It also appears that not all of our APM agents limit SQL query size in the same way. Additional work is needed to determine if this is consistent with agent specification.