Commit a5574792 by Nimisha Asthagiri

Fix mobile Warning errors in tracking logs.

parent b858644c
...@@ -19,8 +19,6 @@ log = logging.getLogger(__name__) ...@@ -19,8 +19,6 @@ log = logging.getLogger(__name__)
ERROR_UNAUTHORIZED = 'Unauthorized' ERROR_UNAUTHORIZED = 'Unauthorized'
WARNING_IGNORED_SOURCE = 'Source ignored'
WARNING_IGNORED_TYPE = 'Type ignored'
ERROR_MISSING_USER_ID = 'Required user_id missing from context' ERROR_MISSING_USER_ID = 'Required user_id missing from context'
ERROR_USER_NOT_EXIST = 'Specified user does not exist' ERROR_USER_NOT_EXIST = 'Specified user does not exist'
ERROR_INVALID_USER_ID = 'Unable to parse userId as an integer' ERROR_INVALID_USER_ID = 'Unable to parse userId as an integer'
...@@ -67,7 +65,7 @@ def segmentio_event(request): ...@@ -67,7 +65,7 @@ def segmentio_event(request):
try: try:
track_segmentio_event(request) track_segmentio_event(request)
except EventValidationError as err: except EventValidationError as err:
log.warning( log.debug(
'Unable to process event received from Segment: message="%s" event="%s"', 'Unable to process event received from Segment: message="%s" event="%s"',
str(err), str(err),
request.body request.body
...@@ -133,29 +131,30 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements ...@@ -133,29 +131,30 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
source_map = getattr(settings, 'TRACKING_SEGMENTIO_SOURCE_MAP', {}) source_map = getattr(settings, 'TRACKING_SEGMENTIO_SOURCE_MAP', {})
event_source = source_map.get(library_name) event_source = source_map.get(library_name)
if not event_source: if not event_source:
raise EventValidationError(WARNING_IGNORED_SOURCE) return
else: else:
context['event_source'] = event_source context['event_source'] = event_source
# Ignore event types that are unsupported
segment_event_type = full_segment_event.get('type')
allowed_types = [a.lower() for a in getattr(settings, 'TRACKING_SEGMENTIO_ALLOWED_TYPES', [])]
if not segment_event_type or (segment_event_type.lower() not in allowed_types):
return
if 'name' not in segment_properties: if 'name' not in segment_properties:
raise EventValidationError(ERROR_MISSING_NAME) raise EventValidationError(ERROR_MISSING_NAME)
if 'data' not in segment_properties: # Ignore event names that are unsupported
raise EventValidationError(ERROR_MISSING_DATA)
# Ignore event types and names that are unsupported
segment_event_type = full_segment_event.get('type')
segment_event_name = segment_properties['name'] segment_event_name = segment_properties['name']
allowed_types = [a.lower() for a in getattr(settings, 'TRACKING_SEGMENTIO_ALLOWED_TYPES', [])]
disallowed_substring_names = [ disallowed_substring_names = [
a.lower() for a in getattr(settings, 'TRACKING_SEGMENTIO_DISALLOWED_SUBSTRING_NAMES', []) a.lower() for a in getattr(settings, 'TRACKING_SEGMENTIO_DISALLOWED_SUBSTRING_NAMES', [])
] ]
if (
not segment_event_type or if any(disallowed_subs_name in segment_event_name.lower() for disallowed_subs_name in disallowed_substring_names):
(segment_event_type.lower() not in allowed_types) or return
any(disallowed_subs_name in segment_event_name.lower() for disallowed_subs_name in disallowed_substring_names)
): if 'data' not in segment_properties:
raise EventValidationError(WARNING_IGNORED_TYPE) raise EventValidationError(ERROR_MISSING_DATA)
# create and populate application field if it doesn't exist # create and populate application field if it doesn't exist
app_context = segment_properties.get('context', {}) app_context = segment_properties.get('context', {})
......
...@@ -96,14 +96,14 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -96,14 +96,14 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
return request return request
@data('identify', 'Group', 'Alias', 'Page', 'identify', 'screen') @data('identify', 'Group', 'Alias', 'Page', 'identify', 'screen')
@expect_failure_with_message(segmentio.WARNING_IGNORED_TYPE)
def test_segmentio_ignore_actions(self, action): def test_segmentio_ignore_actions(self, action):
self.post_segmentio_event(action=action) self.post_segmentio_event(action=action)
self.assert_no_events_emitted()
@data('edx.bi.some_name', 'EDX.BI.CAPITAL_NAME') @data('edx.bi.some_name', 'EDX.BI.CAPITAL_NAME')
@expect_failure_with_message(segmentio.WARNING_IGNORED_TYPE)
def test_segmentio_ignore_names(self, name): def test_segmentio_ignore_names(self, name):
self.post_segmentio_event(name=name) self.post_segmentio_event(name=name)
self.assert_no_events_emitted()
def post_segmentio_event(self, **kwargs): def post_segmentio_event(self, **kwargs):
"""Post a fake Segment event to the view that processes it""" """Post a fake Segment event to the view that processes it"""
...@@ -161,9 +161,9 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase): ...@@ -161,9 +161,9 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
"""Return a json string containing a fake Segment event""" """Return a json string containing a fake Segment event"""
return json.dumps(self.create_segmentio_event(**kwargs)) return json.dumps(self.create_segmentio_event(**kwargs))
@expect_failure_with_message(segmentio.WARNING_IGNORED_SOURCE)
def test_segmentio_ignore_unknown_libraries(self): def test_segmentio_ignore_unknown_libraries(self):
self.post_segmentio_event(library_name='foo') self.post_segmentio_event(library_name='foo')
self.assert_no_events_emitted()
@expect_failure_with_message(segmentio.ERROR_USER_NOT_EXIST) @expect_failure_with_message(segmentio.ERROR_USER_NOT_EXIST)
def test_no_user_for_user_id(self): def test_no_user_for_user_id(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment