|
34 | 34 |
|
35 | 35 | logger = logging.getLogger(__name__)
|
36 | 36 |
|
| 37 | +unsafe_logger = logging.getLogger("databricks.sql.unsafe") |
| 38 | +unsafe_logger.setLevel(logging.DEBUG) |
| 39 | + |
| 40 | +# To capture these logs in client code, add a non-NullHandler. |
| 41 | +# See our e2e test suite for an example with logging.FileHandler |
| 42 | +unsafe_logger.addHandler(logging.NullHandler()) |
| 43 | + |
| 44 | +# Disable propagation so that handlers for `databricks.sql` don't pick up these messages |
| 45 | +unsafe_logger.propagate = False |
| 46 | + |
37 | 47 | THRIFT_ERROR_MESSAGE_HEADER = "x-thriftserver-error-message"
|
38 | 48 | DATABRICKS_ERROR_OR_REDIRECT_HEADER = "x-databricks-error-or-redirect-message"
|
39 | 49 | DATABRICKS_REASON_HEADER = "x-databricks-reason-phrase"
|
@@ -318,13 +328,25 @@ def attempt_request(attempt):
|
318 | 328 |
|
319 | 329 | error, error_message, retry_delay = None, None, None
|
320 | 330 | try:
|
321 |
| - logger.debug("Sending request: {}".format(request)) |
| 331 | + # The MagicMocks in our unit tests have a `name` property instead of `__name__`. |
| 332 | + logger.debug( |
| 333 | + "Sending request: {}(<REDACTED>)".format( |
| 334 | + getattr( |
| 335 | + method, "__name__", getattr(method, "name", "UnknownMethod") |
| 336 | + ) |
| 337 | + ) |
| 338 | + ) |
| 339 | + unsafe_logger.debug("Sending request: {}".format(request)) |
322 | 340 | response = method(request)
|
323 | 341 |
|
324 | 342 | # Calling `close()` here releases the active HTTP connection back to the pool
|
325 | 343 | self._transport.close()
|
326 | 344 |
|
327 |
| - logger.debug("Received response: {}".format(response)) |
| 345 | + # We need to call type(response) here because thrift doesn't implement __name__ attributes for thrift responses |
| 346 | + logger.debug( |
| 347 | + "Received response: {}(<REDACTED>)".format(type(response).__name__) |
| 348 | + ) |
| 349 | + unsafe_logger.debug("Received response: {}".format(response)) |
328 | 350 | return response
|
329 | 351 |
|
330 | 352 | except urllib3.exceptions.HTTPError as err:
|
|
0 commit comments