Commit 35691e74 by Gabe Mulley

Merge pull request #24 from mulby/gabe/rename-event-type

rename event_type field to "name"
parents f0211d70 5790ef31
...@@ -45,7 +45,7 @@ Example:: ...@@ -45,7 +45,7 @@ Example::
Running the above example produces the following events:: Running the above example produces the following events::
{ {
"event_type": "navigation.request", "name": "navigation.request",
"timestamp": ..., "timestamp": ...,
"context": { "context": {
"user_id": 10938 "user_id": 10938
...@@ -55,7 +55,7 @@ Running the above example produces the following events:: ...@@ -55,7 +55,7 @@ Running the above example produces the following events::
} }
}, },
{ {
"event_type": "navigation.request", "name": "navigation.request",
"timestamp": ..., "timestamp": ...,
"context": { "context": {
"user_id": 11111, "user_id": 11111,
...@@ -66,7 +66,7 @@ Running the above example produces the following events:: ...@@ -66,7 +66,7 @@ Running the above example produces the following events::
} }
}, },
{ {
"event_type": "navigation.request", "name": "navigation.request",
"timestamp": ..., "timestamp": ...,
"context": { "context": {
"user_id": 10938 "user_id": 10938
......
...@@ -11,9 +11,9 @@ Interface ...@@ -11,9 +11,9 @@ Interface
Python Python
------ ------
.. function:: tracker.register(event_type, description, field_descriptions) .. function:: tracker.register(name, description, field_descriptions)
:event_type: A unique identification string for this type of event :name: A unique identification string for this type of event
:description: A description of the event and the conditions under which it is emitted :description: A description of the event and the conditions under which it is emitted
:field_descriptions: A dictionary mapping field names to a long form description :field_descriptions: A dictionary mapping field names to a long form description
...@@ -39,9 +39,9 @@ Example:: ...@@ -39,9 +39,9 @@ Example::
} }
) )
.. function:: tracker.emit(event_type, field_values) .. function:: tracker.emit(name, field_values)
:event_type: A unique identification string for an event that has already been registered. :name: A unique identification string for an event that has already been registered.
:field_values: A dictionary mapping field names to the value to include in the event. Note that all values provided must be serializable. :field_values: A dictionary mapping field names to the value to include in the event. Note that all values provided must be serializable.
Regardless of previous state or configuration, the data will always be logged, however, in the following conditions will cause a warning to be logged: Regardless of previous state or configuration, the data will always be logged, however, in the following conditions will cause a warning to be logged:
...@@ -55,7 +55,7 @@ Regardless of previous state or configuration, the data will always be logged, h ...@@ -55,7 +55,7 @@ Regardless of previous state or configuration, the data will always be logged, h
.. function:: tracker.enter_context(name, context, description, field_descriptions) .. function:: tracker.enter_context(name, context, description, field_descriptions)
:context: A dictionary of key-value pairs that will be included in every event emitted after this call. Values defined in this dictionary will override any previous calls to push_context with maps that contain the same key. :context: A dictionary of key-value pairs that will be included in every event emitted after this call. Values defined in this dictionary will override any previous calls to push_context with maps that contain the same key.
:event_type: A unique identification string for this type of context. :name: A unique identification string for this type of context.
:description: A clear description of the conditions under which this context is included. :description: A clear description of the conditions under which this context is included.
:field_descriptions: A dictionary mapping field names to a long form description. :field_descriptions: A dictionary mapping field names to a long form description.
...@@ -68,9 +68,9 @@ Removes the named context from the stack. ...@@ -68,9 +68,9 @@ Removes the named context from the stack.
Javascript Javascript
---------- ----------
.. function:: Tracker.emit(event_type, field_values) .. function:: Tracker.emit(name, field_values)
:event_type: A unique identification string for an event that has already been registered. :name: A unique identification string for an event that has already been registered.
:field_values: An object mapping field names to the value to include in the event. Note that all values provided must be serializable. :field_values: An object mapping field names to the value to include in the event. Note that all values provided must be serializable.
See the documentation for the Python API. See the documentation for the Python API.
...@@ -151,9 +151,9 @@ Sample Events ...@@ -151,9 +151,9 @@ Sample Events
Show Answer:: Show Answer::
{ {
"event_type": "edx.problem.show_answer", "name": "edx.problem.show_answer",
"timestamp": "2013-09-12T12:55:00.12345+00:00", "timestamp": "2013-09-12T12:55:00.12345+00:00",
"event_type_id": "10ac28", "name_id": "10ac28",
"context_type_id": "11bd88", "context_type_id": "11bd88",
"context": { "context": {
"course_id":"", "course_id":"",
...@@ -208,9 +208,9 @@ Event Schema:: ...@@ -208,9 +208,9 @@ Event Schema::
"description": "An event emitted from the edx platform.", "description": "An event emitted from the edx platform.",
"properties":{ "properties":{
"event_type": { "name": {
"type": "string", "type": "string",
"id": "http://edx.org/event/event_type", "id": "http://edx.org/event/name",
"description": "A unique identifier for this type of event.", "description": "A unique identifier for this type of event.",
"required": true "required": true
}, },
...@@ -220,9 +220,9 @@ Event Schema:: ...@@ -220,9 +220,9 @@ Event Schema::
"description": "The UTC time the event was emitted in RFC-3339 format.", "description": "The UTC time the event was emitted in RFC-3339 format.",
"required": true "required": true
} }
"event_type_id": { "name_id": {
"type": "string", "type": "string",
"id": "http://edx.org/event/event_type_id", "id": "http://edx.org/event/name_id",
"description": "A unique reference to the metadata for this event type.", "description": "A unique reference to the metadata for this event type.",
"required": false "required": false
}, },
......
...@@ -81,7 +81,7 @@ class MongoBackend(object): ...@@ -81,7 +81,7 @@ class MongoBackend(object):
# management command or equivalent. There is also an option to # management command or equivalent. There is also an option to
# run the indexing on the background, without locking. # run the indexing on the background, without locking.
self.collection.ensure_index([('time', pymongo.DESCENDING)]) self.collection.ensure_index([('time', pymongo.DESCENDING)])
self.collection.ensure_index('event_type') self.collection.ensure_index('name')
def send(self, event): def send(self, event):
"""Insert the event in to the Mongo collection""" """Insert the event in to the Mongo collection"""
......
...@@ -48,14 +48,14 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -48,14 +48,14 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
return self.tracker.get_backend('mock{0}'.format(index)) return self.tracker.get_backend('mock{0}'.format(index))
def test_event_simple_event_without_data(self): def test_event_simple_event_without_data(self):
self.tracker.emit(sentinel.event_type) self.tracker.emit(sentinel.name)
self.assert_backend_called_with(sentinel.event_type) self.assert_backend_called_with(sentinel.name)
def assert_backend_called_with(self, event_type, data=None, context=None, backend=None): def assert_backend_called_with(self, name, data=None, context=None, backend=None):
"""Ensures the backend is called exactly once with the expected data.""" """Ensures the backend is called exactly once with the expected data."""
self.assert_exact_backend_calls([(event_type, context, data)], backend=backend) self.assert_exact_backend_calls([(name, context, data)], backend=backend)
def assert_exact_backend_calls(self, parameter_tuple_list, backend=None): def assert_exact_backend_calls(self, parameter_tuple_list, backend=None):
""" """
...@@ -63,7 +63,7 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -63,7 +63,7 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
specified order. Note that it expects a list of tuples to be passed specified order. Note that it expects a list of tuples to be passed
in to `parameter_tuple_list`. Each tuple should be in the form: in to `parameter_tuple_list`. Each tuple should be in the form:
(event_type, context, data) (name, context, data)
These are expanded out into complete events. These are expanded out into complete events.
""" """
...@@ -74,12 +74,12 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -74,12 +74,12 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
backend.send.mock_calls, backend.send.mock_calls,
[ [
call({ call({
'event_type': event_type, 'name': name,
'timestamp': self._expected_timestamp, 'timestamp': self._expected_timestamp,
'context': context or {}, 'context': context or {},
'data': data or {} 'data': data or {}
}) })
for event_type, context, data for name, context, data
in parameter_tuple_list in parameter_tuple_list
] ]
) )
...@@ -103,14 +103,14 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -103,14 +103,14 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
def test_event_simple_event_with_data(self): def test_event_simple_event_with_data(self):
self.tracker.emit( self.tracker.emit(
sentinel.event_type, sentinel.name,
{ {
sentinel.key: sentinel.value sentinel.key: sentinel.value
} }
) )
self.assert_backend_called_with( self.assert_backend_called_with(
sentinel.event_type, sentinel.name,
{ {
sentinel.key: sentinel.value sentinel.key: sentinel.value
} }
...@@ -118,26 +118,26 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -118,26 +118,26 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
def test_multiple_backends(self): def test_multiple_backends(self):
self.configure_mock_backends(2) self.configure_mock_backends(2)
self.tracker.emit(sentinel.event_type) self.tracker.emit(sentinel.name)
for backend in self._mock_backends: for backend in self._mock_backends:
self.assert_backend_called_with( self.assert_backend_called_with(
sentinel.event_type, backend=backend) sentinel.name, backend=backend)
def test_single_backend_failure(self): def test_single_backend_failure(self):
self.configure_mock_backends(2) self.configure_mock_backends(2)
self.get_mock_backend(0).send.side_effect = Exception self.get_mock_backend(0).send.side_effect = Exception
self.tracker.emit(sentinel.event_type) self.tracker.emit(sentinel.name)
self.assert_backend_called_with( self.assert_backend_called_with(
sentinel.event_type, backend=self.get_mock_backend(1)) sentinel.name, backend=self.get_mock_backend(1))
def test_global_tracker(self): def test_global_tracker(self):
tracker.emit(sentinel.event_type) tracker.emit(sentinel.name)
self.assert_backend_called_with( self.assert_backend_called_with(
sentinel.event_type) sentinel.name)
def test_missing_tracker(self): def test_missing_tracker(self):
self.assertRaises(KeyError, tracker.get_tracker, 'foobar') self.assertRaises(KeyError, tracker.get_tracker, 'foobar')
...@@ -147,11 +147,11 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -147,11 +147,11 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
data = {sentinel.key: sentinel.value} data = {sentinel.key: sentinel.value}
self.tracker.enter_context('single', context) self.tracker.enter_context('single', context)
self.tracker.emit(sentinel.event_type, data) self.tracker.emit(sentinel.name, data)
self.tracker.exit_context('single') self.tracker.exit_context('single')
self.assert_backend_called_with( self.assert_backend_called_with(
sentinel.event_type, sentinel.name,
data=data, data=data,
context=context context=context
) )
...@@ -166,10 +166,10 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -166,10 +166,10 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
} }
with self.tracker.context('outer', context): with self.tracker.context('outer', context):
with self.tracker.context('inner', override_context): with self.tracker.context('inner', override_context):
self.tracker.emit(sentinel.event_type) self.tracker.emit(sentinel.name)
self.assert_backend_called_with( self.assert_backend_called_with(
sentinel.event_type, sentinel.name,
context={ context={
sentinel.context_key: sentinel.override_context_value, sentinel.context_key: sentinel.override_context_value,
sentinel.another_key: sentinel.another_value sentinel.another_key: sentinel.another_value
...@@ -181,6 +181,6 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring ...@@ -181,6 +181,6 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
with self.tracker.context('foo', {sentinel.context_key: sentinel.context_value}): with self.tracker.context('foo', {sentinel.context_key: sentinel.context_value}):
raise ValueError raise ValueError
self.tracker.emit(sentinel.event_type) self.tracker.emit(sentinel.name)
self.assert_backend_called_with(sentinel.event_type) self.assert_backend_called_with(sentinel.name)
...@@ -51,18 +51,18 @@ class Tracker(object): ...@@ -51,18 +51,18 @@ class Tracker(object):
"""Gets the backend that was configured with `name`""" """Gets the backend that was configured with `name`"""
return self.backends[name] return self.backends[name]
def emit(self, event_type=None, data=None): def emit(self, name=None, data=None):
""" """
Emit an event annotated with the UTC time when this function was called. Emit an event annotated with the UTC time when this function was called.
`event_type` is a unique identification string for an event that has `name` is a unique identification string for an event that has
already been registered. already been registered.
`data` is a dictionary mapping field names to the value to include in the event. `data` is a dictionary mapping field names to the value to include in the event.
Note that all values provided must be serializable. Note that all values provided must be serializable.
""" """
full_event = { full_event = {
'event_type': event_type or UNKNOWN_EVENT_TYPE, 'name': name or UNKNOWN_EVENT_TYPE,
'timestamp': datetime.now(UTC), 'timestamp': datetime.now(UTC),
'data': data or {}, 'data': data or {},
'context': self.resolve_context() 'context': self.resolve_context()
...@@ -134,6 +134,6 @@ def get_tracker(name=DEFAULT_TRACKER_NAME): ...@@ -134,6 +134,6 @@ def get_tracker(name=DEFAULT_TRACKER_NAME):
return TRACKERS[name] return TRACKERS[name]
def emit(event_type=None, data=None): def emit(name=None, data=None):
"""Calls `Tracker.emit` on the default global tracker""" """Calls `Tracker.emit` on the default global tracker"""
return get_tracker().emit(event_type=event_type, data=data) return get_tracker().emit(name=name, data=data)
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