eventtracking.backends¶
Event tracking backend module.
eventtracking.backends.mongodb¶
MongoDB event tracker backend.
eventtracking.backends.logger¶
Event tracker backend that saves events to a python logger.
eventtracking.backends.routing¶
Route events to processors and backends
-
class
eventtracking.backends.routing.
RoutingBackend
(backends=None, processors=None)[source]¶ Bases:
object
Route events to the appropriate backends.
A routing backend has two types of components:
- Processors - These are run sequentially, processing the output of the previous processor. If you had three processors [a, b, c], the output of the processing step would be c(b(a(event))). Note that for performance reasons, the processor is able to actually mutate the event dictionary in-place. Event dictionaries may be large and highly nested, so creating multiple copies could be problematic. A processor can also choose to prevent the event from being emitted by raising EventEmissionExit. Doing so will prevent any subsequent processors from running and prevent the event from being sent to the backends. Any other exception raised by a processor will be logged and swallowed, subsequent processors will execute and the event will be emitted.
- Backends - Backends are intended to not mutate the event and each receive the same event data. They are not chained like processors. Once an event has been processed by the processor chain, it is passed to each backend in the order that they were registered. Backends typically persist the event in some way, either by sending it to an external system or saving it to disk. They are called synchronously and in sequence, so a long running backend will block other backends until it is done persisting the event. Note that you can register another RoutingBackend as a backend of a RoutingBackend, allowing for arbitrary processing trees.
- backends is a collection that supports iteration over its items using iteritems(). The keys are expected to be
- sortable and the values are expected to expose a send(event) method that will be called for each event. Each backend in this collection is registered in order sorted alphanumeric ascending by key.
processors is an iterable of callables.
- Raises a ValueError if any of the provided backends do not have a callable “send” attribute or any of the
- processors are not callable.
-
process_event
(event)[source]¶ Executes all event processors on the event in order.
event is a nested dictionary that represents the event.
Logs and swallows all Exception except EventEmissionExit which is re-raised if it is raised by a processor.
Returns the modified event.
-
register_backend
(name, backend)[source]¶ Register a new backend that will be called for each processed event.
Note that backends are called in the order that they are registered.
-
register_processor
(processor)[source]¶ Register a new processor.
Note that processors are called in the order that they are registered.
eventtracking.backends.segment¶
Event tracking backend that sends events to segment.com
-
class
eventtracking.backends.segment.
SegmentBackend
[source]¶ Bases:
object
Send events to segment.com
It is assumed that other code elsewhere initializes the segment.com API and makes calls to analytics.identify.
Requires all emitted events to have the following structure (at a minimum):
{ 'name': 'something', 'context': { 'user_id': 10, } }
Additionally, the following fields can optionally be defined:
{ 'context': { 'agent': "your user-agent string", 'client_id': "your google analytics client id", 'host': "your hostname", 'ip': "your IP address", 'page': "your page", 'path': "your path", 'referer': "your referrer", } }
The ‘page’, ‘path’ and ‘referer’ are sent to Segment as “page” information. If the ‘page’ is absent but the ‘host’ and ‘path’ are present, these are used to create a URL value to substitute for the ‘page’ value.
Note that although some parts of the event are lifted out to pass explicitly into the Segment.com API, the entire event is sent as the payload to segment.com, which includes all context, data and other fields in the event.