Skip to content

Commit 2ea08ed

Browse files
committed
dont log sensitive query details
1 parent 5a4b3e8 commit 2ea08ed

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/pgwire_handlers.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl SimpleQueryHandler for LoggingSimpleQueryHandler {
9393
name = "postgres.query.simple",
9494
skip_all,
9595
fields(
96-
query.text = %query,
96+
query.text = Empty,
9797
query.type = Empty,
9898
query.operation = Empty,
9999
db.system = "postgresql",
@@ -136,10 +136,13 @@ impl SimpleQueryHandler for LoggingSimpleQueryHandler {
136136
span.record("query.operation", operation);
137137
span.record("db.operation", operation);
138138

139-
// Log DML queries
140-
if query_type == "DML" && (operation == "UPDATE" || operation == "DELETE") {
141-
info!("{} query executed: {}", operation, query);
142-
}
139+
// Truncate sensitive data from DML queries
140+
let sanitized_query = match operation {
141+
"INSERT" => query_lower.find(" values").map(|i| format!("{} VALUES ...", &query[..i])).unwrap_or_else(|| query.to_string()),
142+
"UPDATE" => query_lower.find(" set").map(|i| format!("{} SET ...", &query[..i])).unwrap_or_else(|| query.to_string()),
143+
_ => query.to_string(),
144+
};
145+
span.record("query.text", &sanitized_query.as_str());
143146

144147
// Delegate to inner handler with the span context
145148
// Use the current span as parent to ensure proper context propagation
@@ -229,7 +232,6 @@ impl ExtendedQueryHandler for LoggingExtendedQueryHandler {
229232

230233
// Get query text and determine type
231234
let query = &portal.statement.statement.0;
232-
span.record("query.text", &query.as_str());
233235

234236
let query_lower = query.trim().to_lowercase();
235237
let (query_type, operation) = if query_lower.starts_with("select") || query_lower.contains(" select ") {
@@ -254,10 +256,13 @@ impl ExtendedQueryHandler for LoggingExtendedQueryHandler {
254256
span.record("query.operation", operation);
255257
span.record("db.operation", operation);
256258

257-
// Log DML queries
258-
if query_type == "DML" && (operation == "UPDATE" || operation == "DELETE") {
259-
info!("{} query executed (extended): {}", operation, query);
260-
}
259+
// Truncate sensitive data from DML queries
260+
let sanitized_query = match operation {
261+
"INSERT" => query_lower.find(" values").map(|i| format!("{} VALUES ...", &query[..i])).unwrap_or_else(|| query.to_string()),
262+
"UPDATE" => query_lower.find(" set").map(|i| format!("{} SET ...", &query[..i])).unwrap_or_else(|| query.to_string()),
263+
_ => query.to_string(),
264+
};
265+
span.record("query.text", &sanitized_query.as_str());
261266

262267
// Delegate to inner handler with the span context
263268
// Use the current span as parent to ensure proper context propagation

0 commit comments

Comments
 (0)