fix download analytics error

This commit is contained in:
Jack Robison 2017-06-02 14:00:13 -04:00
parent 522cb9cb82
commit f5b4d9f384
3 changed files with 25 additions and 25 deletions

View file

@ -18,7 +18,7 @@ at anytime.
*
### Fixed
*
* Download analytics error
*
### Deprecated

View file

@ -52,19 +52,19 @@ class Manager(object):
def send_server_startup_error(self, message):
self.analytics_api.track(self._event(SERVER_STARTUP_ERROR, {'message': message}))
def send_download_started(self, id_, name, stream_info=None):
def send_download_started(self, id_, name, claim_dict=None):
self.analytics_api.track(
self._event(DOWNLOAD_STARTED, self._download_properties(id_, name, stream_info))
self._event(DOWNLOAD_STARTED, self._download_properties(id_, name, claim_dict))
)
def send_download_errored(self, id_, name, stream_info=None):
def send_download_errored(self, id_, name, claim_dict=None):
self.analytics_api.track(
self._event(DOWNLOAD_ERRORED, self._download_properties(id_, name, stream_info))
self._event(DOWNLOAD_ERRORED, self._download_properties(id_, name, claim_dict))
)
def send_download_finished(self, id_, name, stream_info=None):
def send_download_finished(self, id_, name, claim_dict=None):
self.analytics_api.track(
self._event(DOWNLOAD_FINISHED, self._download_properties(id_, name, stream_info))
self._event(DOWNLOAD_FINISHED, self._download_properties(id_, name, claim_dict))
)
def send_claim_action(self, action):
@ -159,13 +159,13 @@ class Manager(object):
return properties
@staticmethod
def _download_properties(id_, name, stream_info=None):
def _download_properties(id_, name, claim_dict=None):
sd_hash = None
if stream_info:
if claim_dict:
try:
sd_hash = stream_info['stream']['source']['source']
sd_hash = claim_dict.source_hash
except (KeyError, TypeError, ValueError):
log.debug('Failed to get sd_hash from %s', stream_info, exc_info=True)
log.debug('Failed to get sd_hash from %s', claim_dict, exc_info=True)
return {
'download_id': id_,
'name': name,
@ -235,12 +235,12 @@ class Api(object):
if not self._enabled:
return defer.succeed('analytics disabled')
def _log_error(failure):
log.warning('Failed to send track event. %s', failure.getTraceback())
def _log_error(failure, event):
log.warning('Failed to send track event. %s (%s)', failure.getTraceback(), str(event))
log.debug('Sending track event: %s', event)
d = self._post('/track', event)
d.addErrback(_log_error)
d.addErrback(_log_error, event)
return d
@classmethod

View file

@ -644,7 +644,7 @@ class Daemon(AuthJSONRPCServer):
return finished_d
@defer.inlineCallbacks
def _download_name(self, name, stream_info, claim_id, timeout=None, download_directory=None,
def _download_name(self, name, claim_dict, claim_id, timeout=None, download_directory=None,
file_name=None):
"""
Add a lbry file to the file manager, start the download, and return the new lbry file.
@ -657,7 +657,7 @@ class Daemon(AuthJSONRPCServer):
defer.returnValue(result)
else:
download_id = utils.random_string()
self.analytics_manager.send_download_started(download_id, name, stream_info)
self.analytics_manager.send_download_started(download_id, name, claim_dict)
self.streams[claim_id] = GetStream(self.sd_identifier, self.session,
self.session.wallet, self.lbry_file_manager,
@ -665,17 +665,17 @@ class Daemon(AuthJSONRPCServer):
conf.settings['data_rate'], timeout,
download_directory, file_name)
try:
download = self.streams[claim_id].start(stream_info, name)
self.streams[claim_id].finished_deferred.addCallback(
lambda _: self.analytics_manager.send_download_finished(download_id,
name,
stream_info))
download = self.streams[claim_id].start(claim_dict, name)
lbry_file = yield download
f_d = self.streams[claim_id].finished_deferred
f_d.addCallback(lambda _: self.analytics_manager.send_download_finished(download_id,
name,
claim_dict))
result = yield self._get_lbry_file_dict(lbry_file, full_status=True)
del self.streams[claim_id]
except Exception as err:
log.warning('Failed to get %s: %s', name, err)
self.analytics_manager.send_download_errored(download_id, name, stream_info)
self.analytics_manager.send_download_errored(download_id, name, claim_dict)
del self.streams[claim_id]
result = {'error': err.message}
defer.returnValue(result)
@ -960,7 +960,7 @@ class Daemon(AuthJSONRPCServer):
lbry_file_dict = yield self._get_lbry_file_dict(lbry_file, full_status=full_status)
file_dicts.append(lbry_file_dict)
lbry_files = file_dicts
log.info("Collected %i lbry files", len(lbry_files))
log.debug("Collected %i lbry files", len(lbry_files))
defer.returnValue(lbry_files)
# TODO: do this and get_blobs_for_sd_hash in the stream info manager
@ -1597,7 +1597,7 @@ class Daemon(AuthJSONRPCServer):
name = resolved['name']
claim_id = resolved['claim_id']
stream_info = ClaimDict.load_dict(resolved['value'])
claim_dict = ClaimDict.load_dict(resolved['value'])
if claim_id in self.streams:
log.info("Already waiting on lbry://%s to start downloading", name)
@ -1614,7 +1614,7 @@ class Daemon(AuthJSONRPCServer):
log.info('Already have a file for %s', name)
result = yield self._get_lbry_file_dict(lbry_file, full_status=True)
else:
result = yield self._download_name(name, stream_info, claim_id, timeout=timeout,
result = yield self._download_name(name, claim_dict, claim_id, timeout=timeout,
download_directory=download_directory,
file_name=file_name)
response = yield self._render_response(result)