From 6a72b3683e617658ad5d74959f5563b27d8967fe Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 28 Sep 2016 09:07:25 -0700 Subject: [PATCH] send Download Started event --- lbrynet/analytics/events.py | 29 ++++++++++++++++++++++++++++ lbrynet/lbrynet_daemon/LBRYDaemon.py | 6 +++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lbrynet/analytics/events.py b/lbrynet/analytics/events.py index 3f6e58135..8b1c63287 100644 --- a/lbrynet/analytics/events.py +++ b/lbrynet/analytics/events.py @@ -1,6 +1,21 @@ +import logging + from lbrynet.analytics import utils +log = logging.getLogger(__name__) + + +def get_sd_hash(stream_info): + if not stream_info: + return None + try: + return stream_info['sources']['lbry_sd_hash'] + except (KeyError, TypeError, ValueError): + log.debug('Failed to get sd_hash from %s', stream_info, exc_info=True) + return None + + class Events(object): def __init__(self, context, lbry_id, session_id): self.context = context @@ -19,6 +34,20 @@ class Events(object): 'timestamp': utils.now() } + def download_started(self, name, stream_info=None): + return { + 'userId': 'lbry', + 'event': 'Download Started', + 'properties': { + 'lbry_id': self.lbry_id, + 'session_id': self.session_id, + 'name': name, + 'stream_info': get_sd_hash(stream_info) + }, + 'context': self.context, + 'timestamp': utils.now() + } + def make_context(platform, wallet, is_dev=False): # TODO: distinguish between developer and release instances diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index 17157e38b..ce7ea97af 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -561,10 +561,13 @@ class LBRYDaemon(jsonrpc.JSONRPC): self.send_heartbeat.start(60) def _send_heartbeat(self): - log.debug('Sending heartbeat') heartbeat = self._events.heartbeat() self.analytics_api.track(heartbeat) + def _send_download_started(self, name, stream_info=None): + event = self._events.download_started(name, stream_info) + self.analytics_api.track(event) + def _get_platform(self): r = { "processor": platform.processor(), @@ -1129,6 +1132,7 @@ class LBRYDaemon(jsonrpc.JSONRPC): Add a lbry file to the file manager, start the download, and return the new lbry file. If it already exists in the file manager, return the existing lbry file """ + self._send_download_started(name) helper = _DownloadNameHelper( self, name, timeout, download_directory, file_name, wait_for_write)