Skip to content

Commit

Permalink
fail silently + better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vcai122 committed Jan 31, 2025
1 parent e112bec commit 472436b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions analytics/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,23 @@ def _refresh_headers(self):
}

def submit_transaction(self, txn: AnalyticsTxn):
# TODO: We should make this fail safely, as to not interrupt the everyday
# business logic products do.
# However, given that we do not have appropriate logging infrastructure

# Offer a 30 second buffer to refresh
if time.time() >= self.expires_at - 30:
# TODO: According to @judtinzhang there is a subtle bug here with regards
# to tokens
_refresh_if_outdated()
self._refresh_expires_at()
self._refresh_headers()

self.executor.submit(self.send_message, txn.to_json())
try:
# Offer a 30 second buffer to refresh
# TODO: According to @judtinzhang, the reason we need this buffer is due to a
# subtle bug on DLA with regards to tokens.
if time.time() >= self.expires_at - 30:
_refresh_if_outdated()
self._refresh_expires_at()
self._refresh_headers()

self.executor.submit(self.send_message, txn.to_json())
except Exception:
# As to not interrupt everyday business logic products do when the analytics
# server is down, we should not raise an exception.

# TODO: However, we should be logging this error so that we can investigate.
# We should set up a logging infrastructure to do this.
pass

def _send_message(self, json):
self.session.post(url=self.ANALYTICS_URL, json=json, headers=self.headers)
Expand Down
2 changes: 1 addition & 1 deletion analytics/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AnalyticsEntry(ABC):
get_value_use_before: function to get the value to be recorded using the before context
compute_before: function to compute some context before the view/function is called
filter_do_record: function to determine if the entry should be recorded,
defaults to record if exception is thrown
defaults to not record if exception is thrown
* Only one type of value "getter" should be supplied.
"""
Expand Down

0 comments on commit 472436b

Please sign in to comment.