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
1515import os
1616import sys
1717import uuid
1818from datetime import datetime
1919from functools import wraps
2020from os .path import expanduser , join
2121from pathlib import Path
22- from typing import List , Tuple
22+ from typing import List , Optional , Tuple
2323
2424import requests
2525
2828TELEMETRY_ENDPOINT = (
2929 "https://us-central1-kf-feast.cloudfunctions.net/bq_telemetry_logger"
3030)
31+ _logger = logging .getLogger (__name__ )
3132
3233
3334class 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