Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow telemetry configuration to fail gracefully #1612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sdk/python/feast/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from pkg_resources import DistributionNotFound, get_distribution

from .client import Client
Expand All @@ -16,6 +18,12 @@
from .repo_config import RepoConfig
from .value_type import ValueType

logging.basicConfig(
format="%(asctime)s %(levelname)s:%(message)s",
datefmt="%m/%d/%Y %I:%M:%S %p",
level=logging.INFO,
)

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
Expand Down
50 changes: 27 additions & 23 deletions sdk/python/feast/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import sys
import uuid
from datetime import datetime
from functools import wraps
from os.path import expanduser, join
from pathlib import Path
from typing import List, Tuple
from typing import List, Optional, Tuple

import requests

Expand All @@ -28,11 +28,12 @@
TELEMETRY_ENDPOINT = (
"https://us-central1-kf-feast.cloudfunctions.net/bq_telemetry_logger"
)
_logger = logging.getLogger(__name__)


class Telemetry:
def __init__(self):
self._telemetry_enabled = False
self._telemetry_enabled: bool = False
self.check_env_and_configure()

def check_env_and_configure(self):
Expand All @@ -45,35 +46,39 @@ def check_env_and_configure(self):
self._telemetry_enabled = telemetry_enabled

if self._telemetry_enabled:
feast_home_dir = join(expanduser("~"), ".feast")
Path(feast_home_dir).mkdir(exist_ok=True)
telemetry_filepath = join(feast_home_dir, "telemetry")

self._is_test = os.getenv("FEAST_IS_TELEMETRY_TEST", "False") == "True"
self._telemetry_counter = {"get_online_features": 0}

if os.path.exists(telemetry_filepath):
with open(telemetry_filepath, "r") as f:
self._telemetry_id = f.read()
else:
self._telemetry_id = str(uuid.uuid4())
try:
feast_home_dir = join(expanduser("~"), ".feast")
Path(feast_home_dir).mkdir(exist_ok=True)
telemetry_filepath = join(feast_home_dir, "telemetry")

with open(telemetry_filepath, "w") as f:
f.write(self._telemetry_id)
print(
"Feast is an open source project that collects anonymized error reporting and usage statistics. To opt out or learn"
" more see https://docs.feast.dev/reference/telemetry"
self._is_test = (
os.getenv("FEAST_IS_TELEMETRY_TEST", "False") == "True"
)
self._telemetry_counter = {"get_online_features": 0}

if os.path.exists(telemetry_filepath):
with open(telemetry_filepath, "r") as f:
self._telemetry_id = f.read()
else:
self._telemetry_id = str(uuid.uuid4())

with open(telemetry_filepath, "w") as f:
f.write(self._telemetry_id)
print(
"Feast is an open source project that collects anonymized error reporting and usage statistics. To opt out or learn"
" more see https://docs.feast.dev/reference/telemetry"
)
except Exception as e:
_logger.debug(f"Unable to configure telemetry {e}")

@property
def telemetry_id(self):
def telemetry_id(self) -> Optional[str]:
if os.getenv("FEAST_FORCE_TELEMETRY_UUID"):
return os.getenv("FEAST_FORCE_TELEMETRY_UUID")
return self._telemetry_id

def log(self, function_name: str):
self.check_env_and_configure()

if self._telemetry_enabled and self.telemetry_id:
if function_name == "get_online_features":
if self._telemetry_counter["get_online_features"] % 10000 != 0:
Expand All @@ -99,7 +104,6 @@ def log(self, function_name: str):

def log_exception(self, error_type: str, traceback: List[Tuple[str, int, str]]):
self.check_env_and_configure()

if self._telemetry_enabled and self.telemetry_id:
json = {
"error_type": error_type,
Expand Down