Skip to main content

Part of edX code.

Event Tracking library build-status

The event-tracking library tracks context-aware semi-structured system events. It captures and stores events with nested data structures in order to truly take advantage of schemaless data storage systems.

Key features:

  • Multiple backends - define custom backends that can be used to persist your event data.

  • Nested contexts - allows data to be injected into events even without having to pass around all of said data to every location where the events are emitted.

  • Django integration - provides a Django app that allows context aware events to easily be captured by multi-threaded web applications.

  • MongoDB integration - support writing events out to a mongo collection.

Example:

from eventtracking import tracker

tracker = tracker.get_tracker()
tracker.enter_context('outer', {'user_id': 10938})
tracker.emit('navigation.request', {'url': 'http://www.edx.org/some/path/1'})

with tracker.context({'user_id': 11111, 'session_id': '2987lkjdyoioey'}):
    tracker.emit('navigation.request', {'url': 'http://www.edx.org/some/path/2'})

tracker.emit(
    'address.create',
    {
        'name': 'foo',
        'address': {
            'postal_code': '90210',
            'country': 'United States'
        }
    }
)

Running the above example produces the following events:

{
    "name": "navigation.request",
    "timestamp": ...,
    "context": {
        "user_id": 10938
    },
    "data": {
        "url": "http://www.edx.org/some/path/1"
    }
},
{
    "name": "navigation.request",
    "timestamp": ...,
    "context": {
        "user_id": 11111,
        "session_id": "2987lkjdyoioey"
    },
    "data": {
        "url": "http://www.edx.org/some/path/2"
    }
},
{
    "name": "address.create",
    "timestamp": ...,
    "context": {
        "user_id": 10938
    },
    "data": {
        "name": "foo",
        "address": {
            "postal_code": "90210",
            "country": "United States"
        }
    }
}

Configuration

Configuration for event-tracking takes the form of a tree of backends. When a Tracker is instantiated, it creates a root RoutingBackend object using the top-level backends and processors that are passed to it. (Or in the case of the DjangoTracker, the backends and processors are constructed according to the appropriate Django settings.)

In this RoutingBackend, each event is first passed through the chain of processors in series, and then distributed to each backend in turn. Theoretically, these backends might be the Mongo, Segment, or logger backends, but in practice these are wrapped by another layer of RoutingBackend. This allows each one to have its own set of processors that are not shared with other backends, allowing independent filtering or event emit cancellation.

Asynchronous Routing

Considering the volume of the events being generated, we would want to avoid processing events in the main thread that could cause delays in response depending upon the operations and event processors.

event-tracking provides a solution for this i.e. AsyncRoutingBackend. It extends RoutingBackend but performs its operations asynchronously.

It can:

  • Process event through the configured processors.

  • If the event is processed successfully, pass it to the configured backends.

Handling the operations asynchronously would avoid overburdening the main thread and pass the intensive processing tasks to celery workers.

Limitations: Although backends for RoutingBackend can be configured at any level of EVENT_TRACKING_BACKENDS configuration tree, AsyncRoutingBackend only supports backends defined at the root level of EVENT_TRACKING_BACKENDS setting. It is also only possible to use it successfully from the default tracker.

An example configuration for AsyncRoutingBackend is provided below:

EVENT_TRACKING_BACKENDS = {
    'caliper': {
        'ENGINE':  'eventtracking.backends.async_routing.AsyncRoutingBackend',
        'OPTIONS': {
            'backend_name': 'caliper',
            'processors': [
                {
                    'ENGINE': 'eventtracking.processors.regex_filter.RegexFilter',
                    'OPTIONS':{
                        'filter_type': 'allowlist',
                        'regular_expressions': [
                            'edx.course.enrollment.activated',
                            'edx.course.enrollment.deactivated',
                        ]
                    }
                }
            ],
            'backends': {
                'caliper': {
                    'ENGINE': 'dummy.backend.engine',
                    'OPTIONS': {
                        ...
                    }
                }
            },
        },
    },
    'tracking_logs': {
        ...
    }
    ...
}

Event Bus Routing

event-tracking provides a solution for routing events to the Event Bus using the EventBusBackend. It extends RoutingBackend but sends events to the Event Bus.

It can:

  • Process event through the configured processors.

  • If the event is allowed via EVENT_BUS_TRACKING_LOGS, send it to the Event Bus.

Make sure to enable the setting: SEND_TRACKING_EVENT_EMITTED_SIGNAL to allow the EventBusBackend to send events to the Event Bus.

An example configuration for EventBusBackend is provided below:

EVENT_TRACKING_BACKENDS = {
    'xapi': {
        'ENGINE':  'eventtracking.backends.event_bus.EventBusBackend',
        'OPTIONS': {
            'backend_name': 'xapi',
            'processors': [
                {
                    'ENGINE': 'eventtracking.processors.regex_filter.RegexFilter',
                    'OPTIONS':{
                        'filter_type': 'allowlist',
                        'regular_expressions': [
                            'edx.course.enrollment.activated',
                            'edx.course.enrollment.deactivated',
                        ]
                    }
                }
            ],
            'backends': {
                'xapi': {
                    'ENGINE': 'dummy.backend.engine',
                    'OPTIONS': {
                        ...
                    }
                }
            },
        },
    },
    'tracking_logs': {
        ...
    }
    ...
}

EVENT_BUS_TRACKING_LOGS = [
    'edx.course.enrollment.activated',
    'edx.course.enrollment.deactivated',
]

Roadmap

In the very near future the following features are planned:

  • Dynamic event documentation and event metadata - allow event emitters to document the event types, and persist this documentation along with the events so that it can be referenced during analysis to provide context about what the event is and when it is emitted.

Documentation

Latest documentation (Hosted on Read the Docs)

License

The code in this repository is licensed under version 3 of the AGPL unless otherwise noted.

Please see LICENSE.txt for details.

How to Contribute

Contributions are very welcome.

Please read How To Contribute for details.

Reporting Security Issues

Please do not report security issues in public. Please email security@openedx.org

Mailing List and IRC Channel

You can discuss this code on the edx-code Google Group or in the edx-code IRC channel on Freenode.

Release files for event-tracking 4.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for event-tracking 4.1.4
File Size Uploaded
event_tracking-4.1.4.tar.gz 140.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for event-tracking 4.1.4
File Interpreter ABI Platform
event_tracking-4.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 175.0 kB

Release files / event_tracking-4.1.4.tar.gz

Download URL event_tracking-4.1.4.tar.gz
Size 140.3 kB
Tags Source
SHA-256 checksum
How to use checksums
868cc8201e6d2e910aea0d3691e841c0efb16e50b6e5af86e244bc7fd01fbe60
BLAKE2b-256 checksum
How to use checksums
f246c6e08064d846006bc84ae695a4fbc7c4acdb57ec0c690ace786e04cc84df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / event_tracking-4.1.4-py3-none-any.whl

Download URL event_tracking-4.1.4-py3-none-any.whl
Size 34.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59d58775317eb69cc51a2908c2d5c32f99729e82f7c66a420820029331b15ea0
BLAKE2b-256 checksum
How to use checksums
ba358f47c18df417e31e08f89154495fa732a2a55b1ad4a099b53ad7bc4725bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

4.1.4 This release

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.0.2

2 release files

4.0.0

2 release files

3.3.0

2 release files

3.0.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

3 release files

0.2.9

3 release files

0.2.8

3 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

3 release files

0.2.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page