Skip to content

Commit

Permalink
Adjusted obfuscation error logging to be more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyW23 committed Sep 19, 2022
1 parent 167ba02 commit 9b7423e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions mysql/datadog_checks/mysql/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def _obfuscate_and_sanitize_row(self, row):
self._finalize_row(row, obfuscate_sql_with_metadata(row["sql_text"], self._obfuscator_options))
except Exception as e:
if self._config.log_unobfuscated_queries:
self._log.warning("Failed to obfuscate query '%s' | err=[%s]", row["sql_text"], e)
self._log.warning("Failed to obfuscate query=[%s] | err=[%s]", row["sql_text"], e)
else:
self._log.debug("Failed to obfuscate | err=[%s]", e)
self._log.debug("Failed to obfuscate query | err=[%s]", e)
row["sql_text"] = "ERROR: failed to obfuscate"
return row

Expand Down
8 changes: 4 additions & 4 deletions mysql/datadog_checks/mysql/statement_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,13 @@ def _collect_plan_for_statement(self, row):
try:
statement = obfuscate_sql_with_metadata(row['sql_text'], self._obfuscate_options)
statement_digest_text = obfuscate_sql_with_metadata(row['digest_text'], self._obfuscate_options)
except Exception:
except Exception as e:
# do not log raw sql_text to avoid leaking sensitive data into logs unless log_unobfuscated_queries is set
# digest_text is safe as parameters are obfuscated by the database
if self._config.log_unobfuscated_queries:
self._log.warning("Failed to obfuscate statement: %s", row['sql_text'])
self._log.warning("Failed to obfuscate query=[%s] | err=[%s]", row['sql_text'], e)
else:
self._log.debug("Failed to obfuscate statement: %s", row['digest_text'])
self._log.debug("Failed to obfuscate query=[%s] | err=[%s]", row['digest_text'], e)
self._check.count(
"dd.mysql.query_samples.error",
1,
Expand Down Expand Up @@ -545,7 +545,7 @@ def _collect_plan_for_statement(self, row):
obfuscated_plan = datadog_agent.obfuscate_sql_exec_plan(plan)
except Exception as e:
if self._config.log_unobfuscated_plans:
self._log.warning("Failed to obfuscate plan '%s': %s", plan, e)
self._log.warning("Failed to obfuscate plan=[%s] | err=[%s]", plan, e)
raise e
plan_signature = compute_exec_plan_signature(normalized_plan)

Expand Down
2 changes: 1 addition & 1 deletion mysql/datadog_checks/mysql/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _normalize_queries(self, rows):
statement = obfuscate_sql_with_metadata(row['digest_text'], self._obfuscate_options)
obfuscated_statement = statement['query'] if row['digest_text'] is not None else None
except Exception as e:
self.log.warning("Failed to obfuscate query '%s': %s", row['digest_text'], e)
self.log.warning("Failed to obfuscate query=[%s] | err=[%s]", row['digest_text'], e)
continue

normalized_row['digest_text'] = obfuscated_statement
Expand Down

0 comments on commit 9b7423e

Please sign in to comment.