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

Add debug logging #768

Merged
merged 12 commits into from
Sep 26, 2023
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20230925-120144.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: allow for adding snowflake-python-collector logs to dbt output
time: 2023-09-25T12:01:44.778426-07:00
custom:
Author: colin-rogers-dbt
Issue: "768"
8 changes: 8 additions & 0 deletions dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import base64
import datetime
import os

import pytz
import re
from contextlib import contextmanager
Expand Down Expand Up @@ -47,6 +49,12 @@


logger = AdapterLogger("Snowflake")

if os.getenv("DBT_SNOWFLAKE_CONNECTOR_DEBUG_LOGGING"):
for logger_name in ["snowflake.connector", "botocore", "boto3"]:
logger.debug(f"Setting {logger_name} to DEBUG")
logger.set_adapter_dependency_log_level(logger_name, "DEBUG")

_TOKEN_REQUEST_URL = "https://{}.snowflakecomputing.com/oauth/token-request"

ERROR_REDACTION_PATTERNS = {
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_connections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from importlib import reload
from unittest.mock import Mock
import dbt.adapters.snowflake.connections as connections
import dbt.events


def test_connections_sets_logs_in_response_to_env_var(monkeypatch):
"""Test that setting the DBT_SNOWFLAKE_CONNECTOR_DEBUG_LOGGING environment variable happens on import"""
log_mock = Mock()
monkeypatch.setattr(dbt.events, "AdapterLogger", Mock(return_value=log_mock))
monkeypatch.setattr(os, "environ", {"DBT_SNOWFLAKE_CONNECTOR_DEBUG_LOGGING": "true"})
reload(connections)

assert log_mock.debug.call_count == 3
assert log_mock.set_adapter_dependency_log_level.call_count == 3


def test_connections_does_not_set_logs_in_response_to_env_var(monkeypatch):
log_mock = Mock()
monkeypatch.setattr(dbt.events, "AdapterLogger", Mock(return_value=log_mock))
reload(connections)

assert log_mock.debug.call_count == 0
assert log_mock.set_adapter_dependency_log_level.call_count == 0