Repository: dbt-labs/dbt-core

Issue:
track deprecations
### Describe the feature
Currently, dbt tracks anonymized information about a few metrics on dbt runs (package installs, invocations, running models, ...). It would be nice to add tracking around deprecation warnings triggering.

As a dbt developer, I'd like to know how many people are using deprecated behavior so we can inform our decision making on when to remove it.

### Describe alternatives you've considered
Right now we guess about it.

### Who will this benefit?
Anyone making product/feature decisions.


Discussion:
I agree this is valuable, especially as we look to make good on deprecating some long-overdue things.

I think there are two viable Snowplow implementations:

1. Structured event, one per distinct deprecation:
category: 'dbt'
action: 'deprecation'
label: [named deprecation, per [this list](https://github.com/fishtown-analytics/dbt/blob/dev/marian-anderson/core/dbt/deprecations.py#L165-L173)]

2. Unstructured event, fired once per invocation, containing all `active_deprecations` as an array. We can flatten it in the database. I think that would require a new custom context, though.

I lean toward the latter, though I know it's more setup. @drewbanin Do you have a preference either way?
yep - let's do it. I'd like to make an unstructured event with a single field in it's schema for the deprecation name. I think this is a more sustainable long-term approach than using a bunch of untyped structured events. If there are multiple deprecation warnings in a run, we should just fire one event per deprecation IMO!

Resolving patch:
diff --git a/core/dbt/deprecations.py b/core/dbt/deprecations.py
--- a/core/dbt/deprecations.py
+++ b/core/dbt/deprecations.py
@@ -3,6 +3,8 @@
 import dbt.exceptions
 from dbt import ui
 
+import dbt.tracking
+
 
 class DBTDeprecation:
     _name: ClassVar[Optional[str]] = None
@@ -16,6 +18,11 @@ def name(self) -> str:
             'name not implemented for {}'.format(self)
         )
 
+    def track_deprecation_warn(self) -> None:
+        dbt.tracking.track_deprecation_warn({
+            "deprecation_name": self.name
+        })
+
     @property
     def description(self) -> str:
         if self._description is not None:
@@ -31,6 +38,7 @@ def show(self, *args, **kwargs) -> None:
                 desc, prefix='* Deprecation Warning: '
             )
             dbt.exceptions.warn_or_error(msg)
+            self.track_deprecation_warn()
             active_deprecations.add(self.name)
 
 
diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py
--- a/core/dbt/tracking.py
+++ b/core/dbt/tracking.py
@@ -26,6 +26,7 @@
 INVOCATION_ENV_SPEC = 'iglu:com.dbt/invocation_env/jsonschema/1-0-0'
 PACKAGE_INSTALL_SPEC = 'iglu:com.dbt/package_install/jsonschema/1-0-0'
 RPC_REQUEST_SPEC = 'iglu:com.dbt/rpc_request/jsonschema/1-0-1'
+DEPRECATION_WARN_SPEC = 'iglu:com.dbt/deprecation_warn/jsonschema/1-0-0'
 
 DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'
 
@@ -321,6 +322,25 @@ def track_package_install(config, args, options):
     )
 
 
+def track_deprecation_warn(options):
+
+    assert active_user is not None, \
+        'Cannot track deprecation warnings when active user is None'
+
+    context = [
+        SelfDescribingJson(DEPRECATION_WARN_SPEC, options)
+    ]
+
+    track(
+        active_user,
+        category="dbt",
+        action='deprecation',
+        label=active_user.invocation_id,
+        property_='warn',
+        context=context
+    )
+
+
 def track_invocation_end(
         config=None, args=None, result_type=None
 ):


Test patch: