From 2982b3383578d9c4f924ad731c4589c6bec4d1d5 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 2 Jun 2023 11:20:36 -0500 Subject: [PATCH] feat: add signal for event-tracking emission --- CHANGELOG.rst | 3 +++ openedx_events/analytics/__init__.py | 6 ++++++ openedx_events/analytics/data.py | 31 ++++++++++++++++++++++++++++ openedx_events/analytics/signals.py | 23 +++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 openedx_events/analytics/__init__.py create mode 100644 openedx_events/analytics/data.py create mode 100644 openedx_events/analytics/signals.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index cec6dffa..7c19a366 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,9 @@ Change Log Unreleased ---------- +Added +~~~~~ +* Added new event TRACKING_EVENT_EMITTED. [8.0.1] - 2023-05-16 -------------------- diff --git a/openedx_events/analytics/__init__.py b/openedx_events/analytics/__init__.py new file mode 100644 index 00000000..5410a5f4 --- /dev/null +++ b/openedx_events/analytics/__init__.py @@ -0,0 +1,6 @@ +""" +Package where events related to the analytics subdomain are implemented. + +The analytics subdomain corresponds to {Architecture Subdomain} defined in +the OEP-41. +""" diff --git a/openedx_events/analytics/data.py b/openedx_events/analytics/data.py new file mode 100644 index 00000000..4f9c6474 --- /dev/null +++ b/openedx_events/analytics/data.py @@ -0,0 +1,31 @@ +""" +Data attributes for events within the architecture subdomain ``analytics``. + +These attributes follow the form of attr objects specified in OEP-49 data +pattern. + +The attributes for the events come from the CourseDetailView in the LMS, with some unused fields removed +(see deprecation proposal at https://github.com/openedx/public-engineering/issues/160) +""" + +from datetime import datetime + +import attr + + +@attr.s(frozen=True) +class TrackingLogData: + """ + Data describing tracking log data. + + Arguments: + name (str): course name + timestamp (datetime): course start date + data (dict): dictionary of extra data (optional), e.g. {"course_id": "course-v1:edX+DemoX+Demo_Course"} + context (dict): dictionary of context data, defined in https://edx.readthedocs.io/projects/devdata/en/latest/internal_data_formats/tracking_logs/common_fields.html + """ + + name = attr.ib(type=str) + timestamp = attr.ib(type=datetime) + data = attr.ib(type=dict, default={}) + context = attr.ib(type=dict, factory=dict) diff --git a/openedx_events/analytics/signals.py b/openedx_events/analytics/signals.py new file mode 100644 index 00000000..d1badd02 --- /dev/null +++ b/openedx_events/analytics/signals.py @@ -0,0 +1,23 @@ +""" +Standardized signals definitions for events within the architecture subdomain ``analytics``. + +All signals defined in this module must follow the name and versioning +conventions specified in OEP-41. + +They also must comply with the payload definition specified in +docs/decisions/0003-events-payload.rst +""" + +from openedx_events.analytics.data import TrackingLogData +from openedx_events.tooling import OpenEdxPublicSignal + +# .. event_type: org.openedx.analytics.event_tracking.emitted.v1 +# .. event_name: TRACKING_EVENT_EMITTED +# .. event_description: emitted when a tracking log is created. +# .. event_data: TrackingLogData +TRACKING_EVENT_EMITTED = OpenEdxPublicSignal( + event_type="org.openedx.analytics.event_tracking.emitted.v1", + data={ + "tracking_log": TrackingLogData, + } +)