From 274aea9f8f13abc32f3283909ab570081c9b9bbb Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Mon, 17 Aug 2020 11:36:09 -0400 Subject: [PATCH 1/2] Track deprecation warnings --- CHANGELOG.md | 1 + core/dbt/deprecations.py | 6 ++++++ core/dbt/tracking.py | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 192ed191c71..10a8c5d778b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Under the hood - Upgraded snowflake-connector-python dependency to 2.2.10 and enabled the SSO token cache ([#2613](https://github.com/fishtown-analytics/dbt/issues/2613), [#2689](https://github.com/fishtown-analytics/dbt/issues/2689), [#2698](https://github.com/fishtown-analytics/dbt/pull/2698)) +- Add deprecation warnings to anonymous usage tracking ([#2688](https://github.com/fishtown-analytics/dbt/issues/2688), [#2710](https://github.com/fishtown-analytics/dbt/issues/2710)) ### Features - Add better retry support when using the BigQuery adapter ([#2694](https://github.com/fishtown-analytics/dbt/pull/2694), follow-up to [#1963](https://github.com/fishtown-analytics/dbt/pull/1963)) diff --git a/core/dbt/deprecations.py b/core/dbt/deprecations.py index 7fae52431c2..1781ee0e9b0 100644 --- a/core/dbt/deprecations.py +++ b/core/dbt/deprecations.py @@ -16,6 +16,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 +36,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 index 133a6c13838..d9ea3ec0a91 100644 --- 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 ): From a573a2ada1303b238444552004bd4c5a41b439c6 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Mon, 17 Aug 2020 17:00:07 -0400 Subject: [PATCH 2/2] Explicitly import dbt.tracking module --- core/dbt/deprecations.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/dbt/deprecations.py b/core/dbt/deprecations.py index 1781ee0e9b0..da8f1f79c25 100644 --- 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