Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 5 additions & 7 deletions giskard/utils/analytics_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import platform
import sys
import threading
from traceback import TracebackException
from types import TracebackType
import uuid
from functools import wraps
from threading import ExceptHookArgs, Lock
from traceback import TracebackException
from types import TracebackType
from typing import Dict, Optional, Type

import requests
Expand All @@ -31,11 +31,8 @@ def inner_function(*args, **kwargs):

try:
return f(*args, **kwargs)
except BaseException as e: # NOSONAR
try:
_report_error(e, error_type="tracking error")
except BaseException: # NOSONAR
pass
except BaseException: # NOSONAR
pass

return inner_function

Expand Down Expand Up @@ -149,6 +146,7 @@ def track(self, event_name, properties=None, meta=None, force=False):
return self._track(event_name, properties=properties, meta=meta, force=force)

@threaded
@analytics_method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, this was removed to avoid infinite loops. Can we add a test to ensure that this is not happening (since _report_error has been removed in the decorator, this should be the case) and make sure we will not reintroduce this in the future?

EDIT: maybe the test that is present already covers this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was actually the presence of

 _report_error(e, error_type="tracking error")

that was causing an infinite loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an extra test for analytics_method

def _track(self, event_name, properties=None, meta=None, force=False):
self.initialize_giskard_version()
self.initialize_user_properties()
Expand Down
9 changes: 9 additions & 0 deletions tests/communications/test_analytics_collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from mixpanel import Consumer

from utils.analytics_collector import GiskardAnalyticsCollector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from utils.analytics_collector import GiskardAnalyticsCollector
from tests.utils.analytics_collector import GiskardAnalyticsCollector



def test_tracking_doesnt_throw_errors():
ac = GiskardAnalyticsCollector()
ac.mp._consumer = Consumer(events_url="https://invalid.url")
ac.track("test")