Skip to content

Commit

Permalink
Replace tracking events: project_id, adapter_info (dbt-labs#7231)
Browse files Browse the repository at this point in the history
  • Loading branch information
iknox-fa authored Mar 29, 2023
1 parent 050161c commit 4741434
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230327-193850.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Recreates missing tracking events
time: 2023-03-27T19:38:50.657292-05:00
custom:
Author: iknox-fa
Issue: 6097 6098
24 changes: 24 additions & 0 deletions core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ def __init__(self, args, config, project=None):
self.config = config
self.project = config if isinstance(config, Project) else project

if dbt.tracking.active_user is not None:

# N.B. The none checking below is largely due to incomplete projects used in the testing
# and to support tasks that don't require a complete project or a complete config (debug, init).
project_id = None if self.project is None else self.project.hashed_name()
adapter_type = (
getattr(self.config.credentials, "type", None)
if hasattr(self.config, "credentials")
else None
)
adapter_unique_id = (
self.config.credentials.hashed_unique_field()
if hasattr(self.config, "credentials")
else None
)

dbt.tracking.track_project_id({"project_id": project_id})
dbt.tracking.track_adapter_info(
{
"adapter_type": adapter_type,
"adapter_unique_id": adapter_unique_id,
}
)

@classmethod
def pre_init_hook(cls, args):
"""A hook called before the task is initialized."""
Expand Down
46 changes: 37 additions & 9 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@

COLLECTOR_URL = "fishtownanalytics.sinter-collect.com"
COLLECTOR_PROTOCOL = "https"
DBT_INVOCATION_ENV = "DBT_INVOCATION_ENV"

INVOCATION_SPEC = "iglu:com.dbt/invocation/jsonschema/1-0-2"
PLATFORM_SPEC = "iglu:com.dbt/platform/jsonschema/1-0-0"
RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-2"
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"
ADAPTER_INFO_SPEC = "iglu:com.dbt/adapter_info/jsonschema/1-0-1"
DEPRECATION_WARN_SPEC = "iglu:com.dbt/deprecation_warn/jsonschema/1-0-0"
LOAD_ALL_TIMING_SPEC = "iglu:com.dbt/load_all_timing/jsonschema/1-0-3"
RESOURCE_COUNTS = "iglu:com.dbt/resource_counts/jsonschema/1-0-0"
EXPERIMENTAL_PARSER = "iglu:com.dbt/experimental_parser/jsonschema/1-0-0"
INVOCATION_ENV_SPEC = "iglu:com.dbt/invocation_env/jsonschema/1-0-0"
INVOCATION_SPEC = "iglu:com.dbt/invocation/jsonschema/1-0-2"
LOAD_ALL_TIMING_SPEC = "iglu:com.dbt/load_all_timing/jsonschema/1-0-3"
PACKAGE_INSTALL_SPEC = "iglu:com.dbt/package_install/jsonschema/1-0-0"
PARTIAL_PARSER = "iglu:com.dbt/partial_parser/jsonschema/1-0-1"
PLATFORM_SPEC = "iglu:com.dbt/platform/jsonschema/1-0-0"
PROJECT_ID_SPEC = "iglu:com.dbt/project_id/jsonschema/1-0-1"
RESOURCE_COUNTS = "iglu:com.dbt/resource_counts/jsonschema/1-0-0"
RPC_REQUEST_SPEC = "iglu:com.dbt/rpc_request/jsonschema/1-0-1"
RUNNABLE_TIMING = "iglu:com.dbt/runnable/jsonschema/1-0-0"
DBT_INVOCATION_ENV = "DBT_INVOCATION_ENV"
RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-2"


class TimeoutEmitter(Emitter):
Expand Down Expand Up @@ -210,6 +212,32 @@ def track(user, *args, **kwargs):
fire_event(SendEventFailure())


def track_project_id(options):
assert active_user is not None, "Cannot track project_id when active user is None"
context = [SelfDescribingJson(PROJECT_ID_SPEC, options)]

track(
active_user,
category="dbt",
action="project_id",
label=get_invocation_id(),
context=context,
)


def track_adapter_info(options):
assert active_user is not None, "Cannot track adapter_info when active user is None"
context = [SelfDescribingJson(ADAPTER_INFO_SPEC, options)]

track(
active_user,
category="dbt",
action="adapter_info",
label=get_invocation_id(),
context=context,
)


def track_invocation_start(invocation_context):
data = {"progress": "start", "result_type": None, "result": None}
data.update(invocation_context)
Expand Down
3 changes: 3 additions & 0 deletions events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The events outlined here exist to support "very very old versions of dbt-core, which expected to look directly at the HEAD branch of this github repo to find validation schemas".

Eventually these should go away (see https://github.com/dbt-labs/dbt-core/issues/7228)

0 comments on commit 4741434

Please sign in to comment.