Repository: dbt-labs/dbt-snowflake
Pull request #1209 (2024-10-16 10:56:17)

Add snowflake telemetry.
Related to https://github.com/dbt-labs/dbt-adapters/issues/301

### Problem

We need a snowflake override to get the data for snowflake.

### Solution

Override the base class method.

### Checklist

- [x] I have read [the contributing guide](https://github.com/dbt-labs/dbt-core/blob/main/CONTRIBUTING.md) and understand what's expected of me
- [x] I have run this code in development and it appears to resolve the stated issue
- [x] This PR includes tests, or tests are not required/relevant for this PR
- [x] This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX


VersusFacit: <img width="933" alt="image" src="https://github.com/user-attachments/assets/ebd51c1b-13bf-492c-bb46-7c040f40eeb7">

The core function is using the Snowflake override successfully :D 

My local env for testing.

<img width="401" alt="image" src="https://github.com/user-attachments/assets/3a2c5e18-22f3-4182-9dd7-e4b55f64445b">

VersusFacit: I suppose it's worth adding a unit test (done) because this gives us extra security with base adapter / core calls that could be tripped up through many layers of indirection.

Patch:
diff --git a/.changes/unreleased/Under the Hood-20241016-035544.yaml b/.changes/unreleased/Under the Hood-20241016-035544.yaml
new file mode 100644
index 0000000..59e4f70
--- /dev/null
+++ b/.changes/unreleased/Under the Hood-20241016-035544.yaml
@@ -0,0 +1,6 @@
+kind: Under the Hood
+body: Add telemetry function
+time: 2024-10-16T03:55:44.144174-07:00
+custom:
+    Author: versusfacit
+    Issue: "301"
diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py
index 6320893..89c21f5 100644
--- a/dbt/adapters/snowflake/impl.py
+++ b/dbt/adapters/snowflake/impl.py
@@ -4,6 +4,7 @@ from typing import Mapping, Any, Optional, List, Union, Dict, FrozenSet, Tuple,
 from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport
 from dbt.adapters.base.meta import available
 from dbt.adapters.capability import CapabilityDict, CapabilitySupport, Support, Capability
+from dbt.adapters.contracts.relation import RelationConfig
 from dbt.adapters.sql import SQLAdapter
 from dbt.adapters.sql.impl import (
     LIST_SCHEMAS_MACRO_NAME,
@@ -25,6 +26,7 @@ from dbt.adapters.snowflake.relation_configs import (
     SnowflakeRelationType,
     TableFormat,
 )
+
 from dbt.adapters.snowflake import SnowflakeColumn
 from dbt.adapters.snowflake import SnowflakeConnectionManager
 from dbt.adapters.snowflake import SnowflakeRelation
@@ -419,3 +421,18 @@ CALL {proc_name}();
     def debug_query(self):
         """Override for DebugTask method"""
         self.execute("select 1 as id")
+
+    @classmethod
+    def _get_adapter_specific_run_info(cls, config: RelationConfig) -> Dict[str, Any]:
+        table_format: Optional[str] = None
+        if (
+            config
+            and hasattr(config, "_extra")
+            and (relation_format := config._extra.get("table_format"))
+        ):
+            table_format = relation_format
+
+        return {
+            "adapter_type": "snowflake",
+            "table_format": table_format,
+        }
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 9060037..0ceb365 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,6 +1,6 @@
 # install latest changes in dbt-core
 git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
-git+https://github.com/dbt-labs/dbt-adapters.git
+git+https://github.com/dbt-labs/dbt-adapters.git@ADAP-301/add-adapter-telemetry
 git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter
 git+https://github.com/dbt-labs/dbt-common.git
 
diff --git a/setup.py b/setup.py
index c071634..fcea433 100644
--- a/setup.py
+++ b/setup.py
@@ -58,7 +58,7 @@ setup(
     include_package_data=True,
     install_requires=[
         "dbt-common>=1.10,<2.0",
-        "dbt-adapters>=1.7,<2.0",
+        "dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git@ADAP-301/add-adapter-telemetry",
         "snowflake-connector-python[secure-local-storage]~=3.0",
         # add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
         "dbt-core>=1.8.0",


Test patch:
diff --git a/tests/unit/test_adapter_telemetry.py b/tests/unit/test_adapter_telemetry.py
new file mode 100644
index 0000000..498676b
--- /dev/null
+++ b/tests/unit/test_adapter_telemetry.py
@@ -0,0 +1,27 @@
+from unittest import mock
+
+import dbt.adapters.snowflake.__version__
+
+from dbt.adapters.snowflake.impl import SnowflakeAdapter
+from dbt.adapters.base.relation import AdapterTrackingRelationInfo
+
+
+def test_telemetry_with_snowflake_details():
+    mock_model_config = mock.MagicMock()
+    mock_model_config._extra = mock.MagicMock()
+    mock_model_config._extra = {
+        "adapter_type": "snowflake",
+        "table_format": "iceberg",
+    }
+
+    res = SnowflakeAdapter.get_adapter_run_info(mock_model_config)
+
+    assert res.adapter_name == "snowflake"
+    assert res.base_adapter_version == dbt.adapters.__about__.version
+    assert res.adapter_version == dbt.adapters.snowflake.__version__.version
+    assert res.model_adapter_details == {
+        "adapter_type": "snowflake",
+        "table_format": "iceberg",
+    }
+
+    assert type(res) is AdapterTrackingRelationInfo