diff --git a/core/dbt/rpc.py b/core/dbt/rpc.py index f6999e328ed..595a701c0a2 100644 --- a/core/dbt/rpc.py +++ b/core/dbt/rpc.py @@ -22,6 +22,7 @@ from dbt.logger import RPC_LOGGER as logger from dbt.logger import add_queue_handler import dbt.exceptions +import dbt.tracking class RPCException(JSONRPCDispatchException): @@ -58,6 +59,12 @@ def from_error(cls, err): return cls(err.code, err.message, err.data, err.data.get('logs')) +def track_rpc_request(task): + dbt.tracking.track_rpc_request({ + "task": task + }) + + def invalid_params(data): return RPCException( code=JSONRPCInvalidParams.CODE, @@ -429,6 +436,7 @@ def handle(cls, http_request, task_manager): except JSONRPCInvalidRequestException: return JSONRPC20Response(error=JSONRPCInvalidRequest()._data) + track_rpc_request(request.method) dispatcher = RequestDispatcher( http_request, request, diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index c1376bd70f6..6307a2da08d 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -4,6 +4,8 @@ from snowplow_tracker import SelfDescribingJson from datetime import datetime +from dbt.adapters.factory import get_adapter + import pytz import platform import uuid @@ -18,11 +20,12 @@ COLLECTOR_URL = "fishtownanalytics.sinter-collect.com" COLLECTOR_PROTOCOL = "https" -INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-0' +INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-1' PLATFORM_SPEC = 'iglu:com.dbt/platform/jsonschema/1-0-0' RUN_MODEL_SPEC = 'iglu:com.dbt/run_model/jsonschema/1-0-1' 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' DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV' @@ -116,6 +119,11 @@ def get_run_type(args): def get_invocation_context(user, config, args): + try: + adapter_type = get_adapter(config).type() + except Exception: + adapter_type = None + return { "project_id": None if config is None else config.hashed_name(), "user_id": user.id, @@ -126,6 +134,7 @@ def get_invocation_context(user, config, args): "version": str(dbt_version.installed), "run_type": get_run_type(args), + "adapter_type": adapter_type, } @@ -233,6 +242,18 @@ def track_model_run(options): ) +def track_rpc_request(options): + context = [SelfDescribingJson(RPC_REQUEST_SPEC, options)] + + track( + active_user, + category="dbt", + action='rpc_request', + label=active_user.invocation_id, + context=context + ) + + def track_package_install(options): context = [SelfDescribingJson(PACKAGE_INSTALL_SPEC, options)] track( diff --git a/test/integration/033_event_tracking_test/test_events.py b/test/integration/033_event_tracking_test/test_events.py index 48d191355c9..eca355f969f 100644 --- a/test/integration/033_event_tracking_test/test_events.py +++ b/test/integration/033_event_tracking_test/test_events.py @@ -92,7 +92,8 @@ def build_context( self, command, progress, - result_type=None + result_type=None, + adapter_type='postgres' ): def populate( @@ -103,7 +104,7 @@ def populate( ): return [ { - 'schema': 'iglu:com.dbt/invocation/jsonschema/1-0-0', + 'schema': 'iglu:com.dbt/invocation/jsonschema/1-0-1', 'data': { 'project_id': project_id, 'user_id': user_id, @@ -116,7 +117,8 @@ def populate( 'options': None, # TODO : Add options to compile cmd! 'result_type': result_type, - 'result': None + 'result': None, + 'adapter_type': adapter_type } }, { @@ -252,9 +254,9 @@ def test__event_tracking_deps(self): ] expected_contexts = [ - self.build_context('deps', 'start'), + self.build_context('deps', 'start', adapter_type=None), package_context, - self.build_context('deps', 'end', result_type='ok') + self.build_context('deps', 'end', result_type='ok', adapter_type=None) ] self.run_event_test(["deps"], expected_calls, expected_contexts)