Skip to content

Commit a2581c5

Browse files
authored
Allow telemetry configuration to fail gracefully (feast-dev#1612)
* Allow telemetry configuration to fail gracefully Signed-off-by: Achal Shah <achals@gmail.com> * make format Signed-off-by: Achal Shah <achals@gmail.com> * Configure logging in the __init__ module for feast so that all downstream logging messages are formatted properly Signed-off-by: Achal Shah <achals@gmail.com> * Reorder config Signed-off-by: Achal Shah <achals@gmail.com> * Fix integration tests Signed-off-by: Achal Shah <achals@gmail.com>
1 parent 63db728 commit a2581c5

2 files changed

Lines changed: 35 additions & 23 deletions

File tree

sdk/python/feast/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
from pkg_resources import DistributionNotFound, get_distribution
24

35
from .client import Client
@@ -16,6 +18,12 @@
1618
from .repo_config import RepoConfig
1719
from .value_type import ValueType
1820

21+
logging.basicConfig(
22+
format="%(asctime)s %(levelname)s:%(message)s",
23+
datefmt="%m/%d/%Y %I:%M:%S %p",
24+
level=logging.INFO,
25+
)
26+
1927
try:
2028
__version__ = get_distribution(__name__).version
2129
except DistributionNotFound:

sdk/python/feast/telemetry.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import logging
1515
import os
1616
import sys
1717
import uuid
1818
from datetime import datetime
1919
from functools import wraps
2020
from os.path import expanduser, join
2121
from pathlib import Path
22-
from typing import List, Tuple
22+
from typing import List, Optional, Tuple
2323

2424
import requests
2525

@@ -28,11 +28,12 @@
2828
TELEMETRY_ENDPOINT = (
2929
"https://us-central1-kf-feast.cloudfunctions.net/bq_telemetry_logger"
3030
)
31+
_logger = logging.getLogger(__name__)
3132

3233

3334
class Telemetry:
3435
def __init__(self):
35-
self._telemetry_enabled = False
36+
self._telemetry_enabled: bool = False
3637
self.check_env_and_configure()
3738

3839
def check_env_and_configure(self):
@@ -45,35 +46,39 @@ def check_env_and_configure(self):
4546
self._telemetry_enabled = telemetry_enabled
4647

4748
if self._telemetry_enabled:
48-
feast_home_dir = join(expanduser("~"), ".feast")
49-
Path(feast_home_dir).mkdir(exist_ok=True)
50-
telemetry_filepath = join(feast_home_dir, "telemetry")
51-
52-
self._is_test = os.getenv("FEAST_IS_TELEMETRY_TEST", "False") == "True"
53-
self._telemetry_counter = {"get_online_features": 0}
54-
55-
if os.path.exists(telemetry_filepath):
56-
with open(telemetry_filepath, "r") as f:
57-
self._telemetry_id = f.read()
58-
else:
59-
self._telemetry_id = str(uuid.uuid4())
49+
try:
50+
feast_home_dir = join(expanduser("~"), ".feast")
51+
Path(feast_home_dir).mkdir(exist_ok=True)
52+
telemetry_filepath = join(feast_home_dir, "telemetry")
6053

61-
with open(telemetry_filepath, "w") as f:
62-
f.write(self._telemetry_id)
63-
print(
64-
"Feast is an open source project that collects anonymized error reporting and usage statistics. To opt out or learn"
65-
" more see https://docs.feast.dev/reference/telemetry"
54+
self._is_test = (
55+
os.getenv("FEAST_IS_TELEMETRY_TEST", "False") == "True"
6656
)
57+
self._telemetry_counter = {"get_online_features": 0}
58+
59+
if os.path.exists(telemetry_filepath):
60+
with open(telemetry_filepath, "r") as f:
61+
self._telemetry_id = f.read()
62+
else:
63+
self._telemetry_id = str(uuid.uuid4())
64+
65+
with open(telemetry_filepath, "w") as f:
66+
f.write(self._telemetry_id)
67+
print(
68+
"Feast is an open source project that collects anonymized error reporting and usage statistics. To opt out or learn"
69+
" more see https://docs.feast.dev/reference/telemetry"
70+
)
71+
except Exception as e:
72+
_logger.debug(f"Unable to configure telemetry {e}")
6773

6874
@property
69-
def telemetry_id(self):
75+
def telemetry_id(self) -> Optional[str]:
7076
if os.getenv("FEAST_FORCE_TELEMETRY_UUID"):
7177
return os.getenv("FEAST_FORCE_TELEMETRY_UUID")
7278
return self._telemetry_id
7379

7480
def log(self, function_name: str):
7581
self.check_env_and_configure()
76-
7782
if self._telemetry_enabled and self.telemetry_id:
7883
if function_name == "get_online_features":
7984
if self._telemetry_counter["get_online_features"] % 10000 != 0:
@@ -99,7 +104,6 @@ def log(self, function_name: str):
99104

100105
def log_exception(self, error_type: str, traceback: List[Tuple[str, int, str]]):
101106
self.check_env_and_configure()
102-
103107
if self._telemetry_enabled and self.telemetry_id:
104108
json = {
105109
"error_type": error_type,

0 commit comments

Comments
 (0)